Skip to content

Commit 31cbd78

Browse files
committed
Merge 'remote-hg-prerequisites' into HEAD
These fixes were necessary for Sverre Rabbelier's remote-hg to work, but for some magic reason they are not necessary for the current remote-hg. Makes you wonder how that one gets away with it. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 0f19817 + 7c65c43 commit 31cbd78

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

builtin/clone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11661166
}
11671167

11681168
if (!is_local && !complete_refs_before_fetch)
1169-
transport_fetch_refs(transport, mapped_refs);
1169+
if (transport_fetch_refs(transport, mapped_refs))
1170+
die(_("could not fetch refs from %s"),
1171+
transport->url);
11701172

11711173
remote_head = find_ref_by_name(refs, "HEAD");
11721174
remote_head_points_at =

builtin/fast-export.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,9 +874,20 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
874874
}
875875
}
876876

877+
static void handle_reset(const char *name, struct object *object)
878+
{
879+
int mark = get_object_mark(object);
880+
881+
if (mark)
882+
printf("reset %s\nfrom :%d\n\n", name,
883+
get_object_mark(object));
884+
else
885+
printf("reset %s\nfrom %s\n\n", name,
886+
oid_to_hex(&object->oid));
887+
}
888+
877889
static void handle_tags_and_duplicates(void)
878890
{
879-
struct commit *commit;
880891
int i;
881892

882893
for (i = extra_refs.nr - 1; i >= 0; i--) {
@@ -890,9 +901,7 @@ static void handle_tags_and_duplicates(void)
890901
if (anonymize)
891902
name = anonymize_refname(name);
892903
/* create refs pointing to already seen commits */
893-
commit = (struct commit *)object;
894-
printf("reset %s\nfrom :%d\n\n", name,
895-
get_object_mark(&commit->object));
904+
handle_reset(name, object);
896905
show_progress();
897906
break;
898907
}

t/t5801-remote-helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ test_expect_success 'push update refs failure' '
228228
echo "update fail" >>file &&
229229
git commit -a -m "update fail" &&
230230
git rev-parse --verify testgit/origin/heads/update >expect &&
231-
test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
231+
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
232232
git push origin update &&
233233
git rev-parse --verify testgit/origin/heads/update >actual &&
234234
test_cmp expect actual

t/t9350-fast-export.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,15 @@ test_expect_success 'merge commit gets exported with --import-marks' '
556556
)
557557
'
558558

559+
cat > expected << EOF
560+
reset refs/heads/master
561+
from $(git rev-parse master)
562+
563+
EOF
564+
565+
test_expect_failure 'refs are updated even if no commits need to be exported' '
566+
git fast-export master..master > actual &&
567+
test_cmp expected actual
568+
'
569+
559570
test_done

transport-helper.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "protocol.h"
1717

1818
static int debug;
19+
/* TODO: put somewhere sensible, e.g. git_transport_options? */
20+
static int auto_gc = 1;
1921

2022
struct helper_data {
2123
const char *name;
@@ -460,10 +462,25 @@ static int get_exporter(struct transport *transport,
460462
for (i = 0; i < revlist_args->nr; i++)
461463
argv_array_push(&fastexport->args, revlist_args->items[i].string);
462464

465+
argv_array_push(&fastexport->args, "--");
466+
463467
fastexport->git_cmd = 1;
464468
return start_command(fastexport);
465469
}
466470

471+
static void check_helper_status(struct helper_data *data)
472+
{
473+
int pid, status;
474+
475+
pid = waitpid(data->helper->pid, &status, WNOHANG);
476+
if (pid < 0)
477+
die("Could not retrieve status of remote helper '%s'",
478+
data->name);
479+
if (pid > 0 && WIFEXITED(status))
480+
die("Remote helper '%s' died with %d",
481+
data->name, WEXITSTATUS(status));
482+
}
483+
467484
static int fetch_with_import(struct transport *transport,
468485
int nr_heads, struct ref **to_fetch)
469486
{
@@ -500,6 +517,7 @@ static int fetch_with_import(struct transport *transport,
500517

501518
if (finish_command(&fastimport))
502519
die(_("error while running fast-import"));
520+
check_helper_status(data);
503521

504522
/*
505523
* The fast-import stream of a remote helper that advertises
@@ -533,6 +551,12 @@ static int fetch_with_import(struct transport *transport,
533551
}
534552
}
535553
strbuf_release(&buf);
554+
if (auto_gc) {
555+
const char *argv_gc_auto[] = {
556+
"gc", "--auto", "--quiet", NULL,
557+
};
558+
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
559+
}
536560
return 0;
537561
}
538562

@@ -987,6 +1011,7 @@ static int push_refs_with_export(struct transport *transport,
9871011

9881012
if (finish_command(&exporter))
9891013
die(_("error while running fast-export"));
1014+
check_helper_status(data);
9901015
if (push_update_refs_status(data, remote_refs, flags))
9911016
return 1;
9921017

0 commit comments

Comments
 (0)