mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
Merge branch 'jk/fetch-pack'
"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
This commit is contained in:
commit
2f6ef71387
14
fetch-pack.c
14
fetch-pack.c
|
@ -544,16 +544,19 @@ static void filter_refs(struct fetch_pack_args *args,
|
||||||
/* Append unmatched requests to the list */
|
/* Append unmatched requests to the list */
|
||||||
if (allow_tip_sha1_in_want) {
|
if (allow_tip_sha1_in_want) {
|
||||||
for (i = 0; i < nr_sought; i++) {
|
for (i = 0; i < nr_sought; i++) {
|
||||||
|
unsigned char sha1[20];
|
||||||
|
|
||||||
ref = sought[i];
|
ref = sought[i];
|
||||||
if (ref->matched)
|
if (ref->matched)
|
||||||
continue;
|
continue;
|
||||||
if (get_sha1_hex(ref->name, ref->old_sha1))
|
if (get_sha1_hex(ref->name, sha1) ||
|
||||||
|
ref->name[40] != '\0' ||
|
||||||
|
hashcmp(sha1, ref->old_sha1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ref->matched = 1;
|
ref->matched = 1;
|
||||||
*newtail = ref;
|
*newtail = copy_ref(ref);
|
||||||
ref->next = NULL;
|
newtail = &(*newtail)->next;
|
||||||
newtail = &ref->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*refs = newlist;
|
*refs = newlist;
|
||||||
|
@ -625,7 +628,6 @@ static int everything_local(struct fetch_pack_args *args,
|
||||||
|
|
||||||
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
|
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
|
||||||
const unsigned char *remote = ref->old_sha1;
|
const unsigned char *remote = ref->old_sha1;
|
||||||
unsigned char local[20];
|
|
||||||
struct object *o;
|
struct object *o;
|
||||||
|
|
||||||
o = lookup_object(remote);
|
o = lookup_object(remote);
|
||||||
|
@ -638,8 +640,6 @@ static int everything_local(struct fetch_pack_args *args,
|
||||||
ref->name);
|
ref->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashcpy(ref->new_sha1, local);
|
|
||||||
if (!args->verbose)
|
if (!args->verbose)
|
||||||
continue;
|
continue;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
|
@ -1107,9 +1107,16 @@ test_expect_success 'fetch exact SHA1' '
|
||||||
git config uploadpack.allowtipsha1inwant true
|
git config uploadpack.allowtipsha1inwant true
|
||||||
) &&
|
) &&
|
||||||
|
|
||||||
git fetch -v ../testrepo $the_commit:refs/heads/copy &&
|
git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
|
||||||
result=$(git rev-parse --verify refs/heads/copy) &&
|
cat >expect <<-EOF &&
|
||||||
test "$the_commit" = "$result"
|
$the_commit
|
||||||
|
$the_first_commit
|
||||||
|
EOF
|
||||||
|
{
|
||||||
|
git rev-parse --verify refs/heads/copy &&
|
||||||
|
git rev-parse --verify refs/heads/extra
|
||||||
|
} >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
|
@ -519,7 +519,7 @@ static int fetch_refs_via_pack(struct transport *transport,
|
||||||
int nr_heads, struct ref **to_fetch)
|
int nr_heads, struct ref **to_fetch)
|
||||||
{
|
{
|
||||||
struct git_transport_data *data = transport->data;
|
struct git_transport_data *data = transport->data;
|
||||||
const struct ref *refs;
|
struct ref *refs;
|
||||||
char *dest = xstrdup(transport->url);
|
char *dest = xstrdup(transport->url);
|
||||||
struct fetch_pack_args args;
|
struct fetch_pack_args args;
|
||||||
struct ref *refs_tmp = NULL;
|
struct ref *refs_tmp = NULL;
|
||||||
|
@ -552,15 +552,17 @@ static int fetch_refs_via_pack(struct transport *transport,
|
||||||
&transport->pack_lockfile);
|
&transport->pack_lockfile);
|
||||||
close(data->fd[0]);
|
close(data->fd[0]);
|
||||||
close(data->fd[1]);
|
close(data->fd[1]);
|
||||||
if (finish_connect(data->conn))
|
if (finish_connect(data->conn)) {
|
||||||
|
free_refs(refs);
|
||||||
refs = NULL;
|
refs = NULL;
|
||||||
|
}
|
||||||
data->conn = NULL;
|
data->conn = NULL;
|
||||||
data->got_remote_heads = 0;
|
data->got_remote_heads = 0;
|
||||||
data->options.self_contained_and_connected =
|
data->options.self_contained_and_connected =
|
||||||
args.self_contained_and_connected;
|
args.self_contained_and_connected;
|
||||||
|
|
||||||
free_refs(refs_tmp);
|
free_refs(refs_tmp);
|
||||||
|
free_refs(refs);
|
||||||
free(dest);
|
free(dest);
|
||||||
return (refs ? 0 : -1);
|
return (refs ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue