Skip to content

Commit 94168ce

Browse files
author
Git for Windows Build Agent
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 2457b57 + 594a899 commit 94168ce

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
@@ -1138,7 +1138,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11381138
}
11391139

11401140
if (!is_local && !complete_refs_before_fetch)
1141-
transport_fetch_refs(transport, mapped_refs);
1141+
if (transport_fetch_refs(transport, mapped_refs))
1142+
die(_("could not fetch refs from %s"),
1143+
transport->url);
11421144

11431145
remote_head = find_ref_by_name(refs, "HEAD");
11441146
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
@@ -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;
@@ -468,10 +470,25 @@ static int get_exporter(struct transport *transport,
468470
for (i = 0; i < revlist_args->nr; i++)
469471
argv_array_push(&fastexport->args, revlist_args->items[i].string);
470472

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

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

509526
if (finish_command(&fastimport))
510527
die("Error while running fast-import");
528+
check_helper_status(data);
511529

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

@@ -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)