Skip to content

Commit 8c5d742

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 27f0ca5 + f3b96dc commit 8c5d742

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
@@ -1142,7 +1142,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11421142
}
11431143

11441144
if (!is_local && !complete_refs_before_fetch)
1145-
transport_fetch_refs(transport, mapped_refs);
1145+
if (transport_fetch_refs(transport, mapped_refs))
1146+
die(_("could not fetch refs from %s"),
1147+
transport->url);
11461148

11471149
remote_head = find_ref_by_name(refs, "HEAD");
11481150
remote_head_points_at =

builtin/fast-export.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,20 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
866866
}
867867
}
868868

869+
static void handle_reset(const char *name, struct object *object)
870+
{
871+
int mark = get_object_mark(object);
872+
873+
if (mark)
874+
printf("reset %s\nfrom :%d\n\n", name,
875+
get_object_mark(object));
876+
else
877+
printf("reset %s\nfrom %s\n\n", name,
878+
oid_to_hex(&object->oid));
879+
}
880+
869881
static void handle_tags_and_duplicates(void)
870882
{
871-
struct commit *commit;
872883
int i;
873884

874885
for (i = extra_refs.nr - 1; i >= 0; i--) {
@@ -882,9 +893,7 @@ static void handle_tags_and_duplicates(void)
882893
if (anonymize)
883894
name = anonymize_refname(name);
884895
/* create refs pointing to already seen commits */
885-
commit = (struct commit *)object;
886-
printf("reset %s\nfrom :%d\n\n", name,
887-
get_object_mark(&commit->object));
896+
handle_reset(name, object);
888897
show_progress();
889898
break;
890899
}

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
@@ -540,4 +540,15 @@ test_expect_success 'when using -C, do not declare copy when source of copy is a
540540
test_cmp expected actual
541541
'
542542

543+
cat > expected << EOF
544+
reset refs/heads/master
545+
from $(git rev-parse master)
546+
547+
EOF
548+
549+
test_expect_failure 'refs are updated even if no commits need to be exported' '
550+
git fast-export master..master > actual &&
551+
test_cmp expected actual
552+
'
553+
543554
test_done

transport-helper.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "transport-internal.h"
1515

1616
static int debug;
17+
/* TODO: put somewhere sensible, e.g. git_transport_options? */
18+
static int auto_gc = 1;
1719

1820
struct helper_data {
1921
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

@@ -972,6 +996,7 @@ static int push_refs_with_export(struct transport *transport,
972996

973997
if (finish_command(&exporter))
974998
die("Error while running fast-export");
999+
check_helper_status(data);
9751000
if (push_update_refs_status(data, remote_refs, flags))
9761001
return 1;
9771002

0 commit comments

Comments
 (0)