Skip to content

Commit 591a1da

Browse files
committed
Merge branch 'jk/fetch-pack' into maint
"git fetch" that fetches a commit using the allow-tip-sha1-in-want extension could have failed to fetch all the requested refs. * jk/fetch-pack: fetch-pack: remove dead assignment to ref->new_sha1 fetch_refs_via_pack: free extra copy of refs filter_ref: make a copy of extra "sought" entries filter_ref: avoid overwriting ref->old_sha1 with garbage
2 parents 07e3f27 + 32d0462 commit 591a1da

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

fetch-pack.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,19 @@ static void filter_refs(struct fetch_pack_args *args,
544544
/* Append unmatched requests to the list */
545545
if (allow_tip_sha1_in_want) {
546546
for (i = 0; i < nr_sought; i++) {
547+
unsigned char sha1[20];
548+
547549
ref = sought[i];
548550
if (ref->matched)
549551
continue;
550-
if (get_sha1_hex(ref->name, ref->old_sha1))
552+
if (get_sha1_hex(ref->name, sha1) ||
553+
ref->name[40] != '\0' ||
554+
hashcmp(sha1, ref->old_sha1))
551555
continue;
552556

553557
ref->matched = 1;
554-
*newtail = ref;
555-
ref->next = NULL;
556-
newtail = &ref->next;
558+
*newtail = copy_ref(ref);
559+
newtail = &(*newtail)->next;
557560
}
558561
}
559562
*refs = newlist;
@@ -625,7 +628,6 @@ static int everything_local(struct fetch_pack_args *args,
625628

626629
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
627630
const unsigned char *remote = ref->old_sha1;
628-
unsigned char local[20];
629631
struct object *o;
630632

631633
o = lookup_object(remote);
@@ -638,8 +640,6 @@ static int everything_local(struct fetch_pack_args *args,
638640
ref->name);
639641
continue;
640642
}
641-
642-
hashcpy(ref->new_sha1, local);
643643
if (!args->verbose)
644644
continue;
645645
fprintf(stderr,

t/t5516-fetch-push.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,16 @@ test_expect_success 'fetch exact SHA1' '
11071107
git config uploadpack.allowtipsha1inwant true
11081108
) &&
11091109
1110-
git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1111-
result=$(git rev-parse --verify refs/heads/copy) &&
1112-
test "$the_commit" = "$result"
1110+
git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
1111+
cat >expect <<-EOF &&
1112+
$the_commit
1113+
$the_first_commit
1114+
EOF
1115+
{
1116+
git rev-parse --verify refs/heads/copy &&
1117+
git rev-parse --verify refs/heads/extra
1118+
} >actual &&
1119+
test_cmp expect actual
11131120
)
11141121
'
11151122

transport.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static int fetch_refs_via_pack(struct transport *transport,
519519
int nr_heads, struct ref **to_fetch)
520520
{
521521
struct git_transport_data *data = transport->data;
522-
const struct ref *refs;
522+
struct ref *refs;
523523
char *dest = xstrdup(transport->url);
524524
struct fetch_pack_args args;
525525
struct ref *refs_tmp = NULL;
@@ -552,15 +552,17 @@ static int fetch_refs_via_pack(struct transport *transport,
552552
&transport->pack_lockfile);
553553
close(data->fd[0]);
554554
close(data->fd[1]);
555-
if (finish_connect(data->conn))
555+
if (finish_connect(data->conn)) {
556+
free_refs(refs);
556557
refs = NULL;
558+
}
557559
data->conn = NULL;
558560
data->got_remote_heads = 0;
559561
data->options.self_contained_and_connected =
560562
args.self_contained_and_connected;
561563

562564
free_refs(refs_tmp);
563-
565+
free_refs(refs);
564566
free(dest);
565567
return (refs ? 0 : -1);
566568
}

0 commit comments

Comments
 (0)