Skip to content

Commit b160b6e

Browse files
committed
Merge branch 'jt/connectivity-check-after-unshallow'
"git fetch" sometimes failed to update the remote-tracking refs, which has been corrected. * jt/connectivity-check-after-unshallow: fetch-pack: unify ref in and out param
2 parents 6be44b5 + e2842b3 commit b160b6e

File tree

9 files changed

+50
-84
lines changed

9 files changed

+50
-84
lines changed

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11661166
}
11671167

11681168
if (!is_local && !complete_refs_before_fetch)
1169-
transport_fetch_refs(transport, mapped_refs, NULL);
1169+
transport_fetch_refs(transport, mapped_refs);
11701170

11711171
remote_head = find_ref_by_name(refs, "HEAD");
11721172
remote_head_points_at =
@@ -1208,7 +1208,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12081208
if (is_local)
12091209
clone_local(path, git_dir);
12101210
else if (refs && complete_refs_before_fetch)
1211-
transport_fetch_refs(transport, mapped_refs, NULL);
1211+
transport_fetch_refs(transport, mapped_refs);
12121212

12131213
update_remote_refs(refs, mapped_refs, remote_head_points_at,
12141214
branch_top.buf, reflog_msg.buf, transport,

builtin/fetch.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -942,13 +942,11 @@ static int quickfetch(struct ref *ref_map)
942942
return check_connected(iterate_ref_map, &rm, &opt);
943943
}
944944

945-
static int fetch_refs(struct transport *transport, struct ref *ref_map,
946-
struct ref **updated_remote_refs)
945+
static int fetch_refs(struct transport *transport, struct ref *ref_map)
947946
{
948947
int ret = quickfetch(ref_map);
949948
if (ret)
950-
ret = transport_fetch_refs(transport, ref_map,
951-
updated_remote_refs);
949+
ret = transport_fetch_refs(transport, ref_map);
952950
if (!ret)
953951
/*
954952
* Keep the new pack's ".keep" file around to allow the caller
@@ -1153,7 +1151,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
11531151
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
11541152
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
11551153
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
1156-
if (!fetch_refs(transport, ref_map, NULL))
1154+
if (!fetch_refs(transport, ref_map))
11571155
consume_refs(transport, ref_map);
11581156

11591157
if (gsecondary) {
@@ -1169,7 +1167,6 @@ static int do_fetch(struct transport *transport,
11691167
int autotags = (transport->remote->fetch_tags == 1);
11701168
int retcode = 0;
11711169
const struct ref *remote_refs;
1172-
struct ref *updated_remote_refs = NULL;
11731170
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
11741171

11751172
if (tags == TAGS_DEFAULT) {
@@ -1220,24 +1217,7 @@ static int do_fetch(struct transport *transport,
12201217
transport->url);
12211218
}
12221219
}
1223-
1224-
if (fetch_refs(transport, ref_map, &updated_remote_refs)) {
1225-
free_refs(ref_map);
1226-
retcode = 1;
1227-
goto cleanup;
1228-
}
1229-
if (updated_remote_refs) {
1230-
/*
1231-
* Regenerate ref_map using the updated remote refs. This is
1232-
* to account for additional information which may be provided
1233-
* by the transport (e.g. shallow info).
1234-
*/
1235-
free_refs(ref_map);
1236-
ref_map = get_ref_map(transport->remote, updated_remote_refs, rs,
1237-
tags, &autotags);
1238-
free_refs(updated_remote_refs);
1239-
}
1240-
if (consume_refs(transport, ref_map)) {
1220+
if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
12411221
free_refs(ref_map);
12421222
retcode = 1;
12431223
goto cleanup;

fetch-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void fetch_refs(const char *remote_name, struct ref *ref)
1919

2020
transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
2121
transport_set_option(transport, TRANS_OPT_NO_DEPENDENTS, "1");
22-
transport_fetch_refs(transport, ref, NULL);
22+
transport_fetch_refs(transport, ref);
2323
fetch_if_missing = original_fetch_if_missing;
2424
}
2525

fetch-pack.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,25 +1278,26 @@ static void receive_shallow_info(struct fetch_pack_args *args,
12781278
args->deepen = 1;
12791279
}
12801280

1281-
static void receive_wanted_refs(struct packet_reader *reader, struct ref *refs)
1281+
static void receive_wanted_refs(struct packet_reader *reader,
1282+
struct ref **sought, int nr_sought)
12821283
{
12831284
process_section_header(reader, "wanted-refs", 0);
12841285
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
12851286
struct object_id oid;
12861287
const char *end;
1287-
struct ref *r = NULL;
1288+
int i;
12881289

12891290
if (parse_oid_hex(reader->line, &oid, &end) || *end++ != ' ')
12901291
die(_("expected wanted-ref, got '%s'"), reader->line);
12911292

1292-
for (r = refs; r; r = r->next) {
1293-
if (!strcmp(end, r->name)) {
1294-
oidcpy(&r->old_oid, &oid);
1293+
for (i = 0; i < nr_sought; i++) {
1294+
if (!strcmp(end, sought[i]->name)) {
1295+
oidcpy(&sought[i]->old_oid, &oid);
12951296
break;
12961297
}
12971298
}
12981299

1299-
if (!r)
1300+
if (i == nr_sought)
13001301
die(_("unexpected wanted-ref: '%s'"), reader->line);
13011302
}
13021303

@@ -1381,7 +1382,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
13811382
receive_shallow_info(args, &reader);
13821383

13831384
if (process_section_header(&reader, "wanted-refs", 1))
1384-
receive_wanted_refs(&reader, ref);
1385+
receive_wanted_refs(&reader, sought, nr_sought);
13851386

13861387
/* get the pack */
13871388
process_section_header(&reader, "packfile", 0);
@@ -1448,13 +1449,12 @@ static int remove_duplicates_in_refs(struct ref **ref, int nr)
14481449
}
14491450

14501451
static void update_shallow(struct fetch_pack_args *args,
1451-
struct ref *refs,
1452+
struct ref **sought, int nr_sought,
14521453
struct shallow_info *si)
14531454
{
14541455
struct oid_array ref = OID_ARRAY_INIT;
14551456
int *status;
14561457
int i;
1457-
struct ref *r;
14581458

14591459
if (args->deepen && alternate_shallow_file) {
14601460
if (*alternate_shallow_file == '\0') { /* --unshallow */
@@ -1496,8 +1496,8 @@ static void update_shallow(struct fetch_pack_args *args,
14961496
remove_nonexistent_theirs_shallow(si);
14971497
if (!si->nr_ours && !si->nr_theirs)
14981498
return;
1499-
for (r = refs; r; r = r->next)
1500-
oid_array_append(&ref, &r->old_oid);
1499+
for (i = 0; i < nr_sought; i++)
1500+
oid_array_append(&ref, &sought[i]->old_oid);
15011501
si->ref = &ref;
15021502

15031503
if (args->update_shallow) {
@@ -1531,12 +1531,12 @@ static void update_shallow(struct fetch_pack_args *args,
15311531
* remote is also shallow, check what ref is safe to update
15321532
* without updating .git/shallow
15331533
*/
1534-
status = xcalloc(ref.nr, sizeof(*status));
1534+
status = xcalloc(nr_sought, sizeof(*status));
15351535
assign_shallow_commits_to_refs(si, NULL, status);
15361536
if (si->nr_ours || si->nr_theirs) {
1537-
for (r = refs, i = 0; r; r = r->next, i++)
1537+
for (i = 0; i < nr_sought; i++)
15381538
if (status[i])
1539-
r->status = REF_STATUS_REJECT_SHALLOW;
1539+
sought[i]->status = REF_STATUS_REJECT_SHALLOW;
15401540
}
15411541
free(status);
15421542
oid_array_clear(&ref);
@@ -1599,7 +1599,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
15991599
args->connectivity_checked = 1;
16001600
}
16011601

1602-
update_shallow(args, ref_cpy, &si);
1602+
update_shallow(args, sought, nr_sought, &si);
16031603
cleanup:
16041604
clear_shallow_info(&si);
16051605
return ref_cpy;

t/t5551-http-fetch-smart.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ test_expect_success 'custom http headers' '
363363
submodule update sub
364364
'
365365

366+
test_expect_success 'using fetch command in remote-curl updates refs' '
367+
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
368+
rm -rf "$SERVER" client &&
369+
370+
git init "$SERVER" &&
371+
test_commit -C "$SERVER" foo &&
372+
git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
373+
374+
git clone $HTTPD_URL/smart/twobranch client &&
375+
376+
test_commit -C "$SERVER" bar &&
377+
git -C client -c protocol.version=0 fetch &&
378+
379+
git -C "$SERVER" rev-parse master >expect &&
380+
git -C client rev-parse origin/master >actual &&
381+
test_cmp expect actual
382+
'
383+
366384
test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
367385
rm -rf clone &&
368386
echo "Set-Cookie: Foo=1" >cookies &&

transport-helper.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,16 +651,14 @@ static int connect_helper(struct transport *transport, const char *name,
651651
}
652652

653653
static int fetch(struct transport *transport,
654-
int nr_heads, struct ref **to_fetch,
655-
struct ref **fetched_refs)
654+
int nr_heads, struct ref **to_fetch)
656655
{
657656
struct helper_data *data = transport->data;
658657
int i, count;
659658

660659
if (process_connect(transport, 0)) {
661660
do_take_over(transport);
662-
return transport->vtable->fetch(transport, nr_heads, to_fetch,
663-
fetched_refs);
661+
return transport->vtable->fetch(transport, nr_heads, to_fetch);
664662
}
665663

666664
count = 0;

transport-internal.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,11 @@ struct transport_vtable {
3636
* Fetch the objects for the given refs. Note that this gets
3737
* an array, and should ignore the list structure.
3838
*
39-
* The transport *may* provide, in fetched_refs, the list of refs that
40-
* it fetched. If the transport knows anything about the fetched refs
41-
* that the caller does not know (for example, shallow status), it
42-
* should provide that list of refs and include that information in the
43-
* list.
44-
*
4539
* If the transport did not get hashes for refs in
4640
* get_refs_list(), it should set the old_sha1 fields in the
4741
* provided refs now.
4842
**/
49-
int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs,
50-
struct ref **fetched_refs);
43+
int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
5144

5245
/**
5346
* Push the objects and refs. Send the necessary objects, and

transport.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
151151
}
152152

153153
static int fetch_refs_from_bundle(struct transport *transport,
154-
int nr_heads, struct ref **to_fetch,
155-
struct ref **fetched_refs)
154+
int nr_heads, struct ref **to_fetch)
156155
{
157156
struct bundle_transport_data *data = transport->data;
158157
return unbundle(&data->header, data->fd,
@@ -288,8 +287,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
288287
}
289288

290289
static int fetch_refs_via_pack(struct transport *transport,
291-
int nr_heads, struct ref **to_fetch,
292-
struct ref **fetched_refs)
290+
int nr_heads, struct ref **to_fetch)
293291
{
294292
int ret = 0;
295293
struct git_transport_data *data = transport->data;
@@ -358,12 +356,8 @@ static int fetch_refs_via_pack(struct transport *transport,
358356
if (report_unmatched_refs(to_fetch, nr_heads))
359357
ret = -1;
360358

361-
if (fetched_refs)
362-
*fetched_refs = refs;
363-
else
364-
free_refs(refs);
365-
366359
free_refs(refs_tmp);
360+
free_refs(refs);
367361
free(dest);
368362
return ret;
369363
}
@@ -1223,31 +1217,19 @@ const struct ref *transport_get_remote_refs(struct transport *transport,
12231217
return transport->remote_refs;
12241218
}
12251219

1226-
int transport_fetch_refs(struct transport *transport, struct ref *refs,
1227-
struct ref **fetched_refs)
1220+
int transport_fetch_refs(struct transport *transport, struct ref *refs)
12281221
{
12291222
int rc;
12301223
int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
12311224
struct ref **heads = NULL;
1232-
struct ref *nop_head = NULL, **nop_tail = &nop_head;
12331225
struct ref *rm;
12341226

12351227
for (rm = refs; rm; rm = rm->next) {
12361228
nr_refs++;
12371229
if (rm->peer_ref &&
12381230
!is_null_oid(&rm->old_oid) &&
1239-
!oidcmp(&rm->peer_ref->old_oid, &rm->old_oid)) {
1240-
/*
1241-
* These need to be reported as fetched, but we don't
1242-
* actually need to fetch them.
1243-
*/
1244-
if (fetched_refs) {
1245-
struct ref *nop_ref = copy_ref(rm);
1246-
*nop_tail = nop_ref;
1247-
nop_tail = &nop_ref->next;
1248-
}
1231+
!oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))
12491232
continue;
1250-
}
12511233
ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
12521234
heads[nr_heads++] = rm;
12531235
}
@@ -1265,11 +1247,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs,
12651247
heads[nr_heads++] = rm;
12661248
}
12671249

1268-
rc = transport->vtable->fetch(transport, nr_heads, heads, fetched_refs);
1269-
if (fetched_refs && nop_head) {
1270-
*nop_tail = *fetched_refs;
1271-
*fetched_refs = nop_head;
1272-
}
1250+
rc = transport->vtable->fetch(transport, nr_heads, heads);
12731251

12741252
free(heads);
12751253
return rc;

transport.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ int transport_push(struct transport *connection,
239239
const struct ref *transport_get_remote_refs(struct transport *transport,
240240
const struct argv_array *ref_prefixes);
241241

242-
int transport_fetch_refs(struct transport *transport, struct ref *refs,
243-
struct ref **fetched_refs);
242+
int transport_fetch_refs(struct transport *transport, struct ref *refs);
244243
void transport_unlock_pack(struct transport *transport);
245244
int transport_disconnect(struct transport *transport);
246245
char *transport_anonymize_url(const char *url);

0 commit comments

Comments
 (0)