Skip to content

Commit ee5fdc4

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 43fee83 + 65aac74 commit ee5fdc4

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
@@ -1127,7 +1127,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11271127
}
11281128

11291129
if (!is_local && !complete_refs_before_fetch)
1130-
transport_fetch_refs(transport, mapped_refs);
1130+
if (transport_fetch_refs(transport, mapped_refs))
1131+
die(_("could not fetch refs from %s"),
1132+
transport->url);
11311133

11321134
remote_head = find_ref_by_name(refs, "HEAD");
11331135
remote_head_points_at =

builtin/fast-export.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,20 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
851851
}
852852
}
853853

854+
static void handle_reset(const char *name, struct object *object)
855+
{
856+
int mark = get_object_mark(object);
857+
858+
if (mark)
859+
printf("reset %s\nfrom :%d\n\n", name,
860+
get_object_mark(object));
861+
else
862+
printf("reset %s\nfrom %s\n\n", name,
863+
oid_to_hex(&object->oid));
864+
}
865+
854866
static void handle_tags_and_duplicates(void)
855867
{
856-
struct commit *commit;
857868
int i;
858869

859870
for (i = extra_refs.nr - 1; i >= 0; i--) {
@@ -867,9 +878,7 @@ static void handle_tags_and_duplicates(void)
867878
if (anonymize)
868879
name = anonymize_refname(name);
869880
/* create refs pointing to already seen commits */
870-
commit = (struct commit *)object;
871-
printf("reset %s\nfrom :%d\n\n", name,
872-
get_object_mark(&commit->object));
881+
handle_reset(name, object);
873882
show_progress();
874883
break;
875884
}

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
@@ -522,4 +522,15 @@ test_expect_success 'delete refspec' '
522522
test_cmp expected actual
523523
'
524524

525+
cat > expected << EOF
526+
reset refs/heads/master
527+
from $(git rev-parse master)
528+
529+
EOF
530+
531+
test_expect_failure 'refs are updated even if no commits need to be exported' '
532+
git fast-export master..master > actual &&
533+
test_cmp expected actual
534+
'
535+
525536
test_done

transport-helper.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "refs.h"
1414

1515
static int debug;
16+
/* TODO: put somewhere sensible, e.g. git_transport_options? */
17+
static int auto_gc = 1;
1618

1719
struct helper_data {
1820
const char *name;
@@ -469,10 +471,25 @@ static int get_exporter(struct transport *transport,
469471
for (i = 0; i < revlist_args->nr; i++)
470472
argv_array_push(&fastexport->args, revlist_args->items[i].string);
471473

474+
argv_array_push(&fastexport->args, "--");
475+
472476
fastexport->git_cmd = 1;
473477
return start_command(fastexport);
474478
}
475479

480+
static void check_helper_status(struct helper_data *data)
481+
{
482+
int pid, status;
483+
484+
pid = waitpid(data->helper->pid, &status, WNOHANG);
485+
if (pid < 0)
486+
die("Could not retrieve status of remote helper '%s'",
487+
data->name);
488+
if (pid > 0 && WIFEXITED(status))
489+
die("Remote helper '%s' died with %d",
490+
data->name, WEXITSTATUS(status));
491+
}
492+
476493
static int fetch_with_import(struct transport *transport,
477494
int nr_heads, struct ref **to_fetch)
478495
{
@@ -509,6 +526,7 @@ static int fetch_with_import(struct transport *transport,
509526

510527
if (finish_command(&fastimport))
511528
die("Error while running fast-import");
529+
check_helper_status(data);
512530

513531
/*
514532
* The fast-import stream of a remote helper that advertises
@@ -542,6 +560,12 @@ static int fetch_with_import(struct transport *transport,
542560
}
543561
}
544562
strbuf_release(&buf);
563+
if (auto_gc) {
564+
const char *argv_gc_auto[] = {
565+
"gc", "--auto", "--quiet", NULL,
566+
};
567+
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
568+
}
545569
return 0;
546570
}
547571

@@ -968,6 +992,7 @@ static int push_refs_with_export(struct transport *transport,
968992

969993
if (finish_command(&exporter))
970994
die("Error while running fast-export");
995+
check_helper_status(data);
971996
if (push_update_refs_status(data, remote_refs, flags))
972997
return 1;
973998

0 commit comments

Comments
 (0)