Skip to content

Commit 4dfd092

Browse files
rcoupgitster
authored andcommitted
fetch-pack: add refetch
Allow a "refetch" where the contents of the local object store are ignored and a full fetch is performed, not attempting to find or negotiate common commits with the remote. A key use case is to apply a new partial clone blob/tree filter and refetch all the associated matching content, which would otherwise not be transferred when the commit objects are already present locally. Signed-off-by: Robert Coup <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1836836 commit 4dfd092

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

fetch-pack.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,21 @@ static int find_common(struct fetch_negotiator *negotiator,
312312
const char *remote_hex;
313313
struct object *o;
314314

315-
/*
316-
* If that object is complete (i.e. it is an ancestor of a
317-
* local ref), we tell them we have it but do not have to
318-
* tell them about its ancestors, which they already know
319-
* about.
320-
*
321-
* We use lookup_object here because we are only
322-
* interested in the case we *know* the object is
323-
* reachable and we have already scanned it.
324-
*/
325-
if (((o = lookup_object(the_repository, remote)) != NULL) &&
326-
(o->flags & COMPLETE)) {
327-
continue;
315+
if (!args->refetch) {
316+
/*
317+
* If that object is complete (i.e. it is an ancestor of a
318+
* local ref), we tell them we have it but do not have to
319+
* tell them about its ancestors, which they already know
320+
* about.
321+
*
322+
* We use lookup_object here because we are only
323+
* interested in the case we *know* the object is
324+
* reachable and we have already scanned it.
325+
*/
326+
if (((o = lookup_object(the_repository, remote)) != NULL) &&
327+
(o->flags & COMPLETE)) {
328+
continue;
329+
}
328330
}
329331

330332
remote_hex = oid_to_hex(remote);
@@ -692,6 +694,9 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
692694
int old_save_commit_buffer = save_commit_buffer;
693695
timestamp_t cutoff = 0;
694696

697+
if (args->refetch)
698+
return;
699+
695700
save_commit_buffer = 0;
696701

697702
trace2_region_enter("fetch-pack", "parse_remote_refs_and_find_cutoff", NULL);
@@ -1028,7 +1033,11 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
10281033
struct fetch_negotiator *negotiator;
10291034

10301035
negotiator = &negotiator_alloc;
1031-
fetch_negotiator_init(r, negotiator);
1036+
if (args->refetch) {
1037+
fetch_negotiator_init_noop(negotiator);
1038+
} else {
1039+
fetch_negotiator_init(r, negotiator);
1040+
}
10321041

10331042
sort_ref_list(&ref, ref_compare_name);
10341043
QSORT(sought, nr_sought, cmp_ref_by_name);
@@ -1121,7 +1130,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
11211130

11221131
mark_complete_and_common_ref(negotiator, args, &ref);
11231132
filter_refs(args, &ref, sought, nr_sought);
1124-
if (everything_local(args, &ref)) {
1133+
if (!args->refetch && everything_local(args, &ref)) {
11251134
packet_flush(fd[1]);
11261135
goto all_done;
11271136
}
@@ -1587,7 +1596,10 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
15871596
struct strvec index_pack_args = STRVEC_INIT;
15881597

15891598
negotiator = &negotiator_alloc;
1590-
fetch_negotiator_init(r, negotiator);
1599+
if (args->refetch)
1600+
fetch_negotiator_init_noop(negotiator);
1601+
else
1602+
fetch_negotiator_init(r, negotiator);
15911603

15921604
packet_reader_init(&reader, fd[0], NULL, 0,
15931605
PACKET_READ_CHOMP_NEWLINE |
@@ -1613,7 +1625,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
16131625
/* Filter 'ref' by 'sought' and those that aren't local */
16141626
mark_complete_and_common_ref(negotiator, args, &ref);
16151627
filter_refs(args, &ref, sought, nr_sought);
1616-
if (everything_local(args, &ref))
1628+
if (!args->refetch && everything_local(args, &ref))
16171629
state = FETCH_DONE;
16181630
else
16191631
state = FETCH_SEND_REQUEST;

fetch-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct fetch_pack_args {
4242
unsigned update_shallow:1;
4343
unsigned reject_shallow_remote:1;
4444
unsigned deepen:1;
45+
unsigned refetch:1;
4546

4647
/*
4748
* Indicate that the remote of this request is a promisor remote. The

0 commit comments

Comments
 (0)