Skip to content

Commit 34c2903

Browse files
jonathantanmygitster
authored andcommitted
fetch-pack: split up everything_local()
The function everything_local(), despite its name, also (1) marks commits as COMPLETE and COMMON_REF and (2) invokes filter_refs() as important side effects. Extract (1) into its own function (mark_complete_and_common_ref()) and remove (2). The restoring of save_commit_buffer, which was introduced in a1c6d7c ("fetch-pack: restore save_commit_buffer after use", 2017-12-08), is a concern of the parse_object() call in mark_complete_and_common_ref(), so it has been moved from the end of everything_local() to the end of mark_complete_and_common_ref(). Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68372c8 commit 34c2903

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

fetch-pack.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,20 @@ static int add_loose_objects_to_set(const struct object_id *oid,
734734
return 0;
735735
}
736736

737-
static int everything_local(struct fetch_pack_args *args,
738-
struct ref **refs,
739-
struct ref **sought, int nr_sought)
737+
/*
738+
* Mark recent commits available locally and reachable from a local ref as
739+
* COMPLETE. If args->no_dependents is false, also mark COMPLETE remote refs as
740+
* COMMON_REF (otherwise, we are not planning to participate in negotiation, and
741+
* thus do not need COMMON_REF marks).
742+
*
743+
* The cutoff time for recency is determined by this heuristic: it is the
744+
* earliest commit time of the objects in refs that are commits and that we know
745+
* the commit time of.
746+
*/
747+
static void mark_complete_and_common_ref(struct fetch_pack_args *args,
748+
struct ref **refs)
740749
{
741750
struct ref *ref;
742-
int retval;
743751
int old_save_commit_buffer = save_commit_buffer;
744752
timestamp_t cutoff = 0;
745753
struct oidset loose_oid_set = OIDSET_INIT;
@@ -812,7 +820,18 @@ static int everything_local(struct fetch_pack_args *args,
812820
}
813821
}
814822

815-
filter_refs(args, refs, sought, nr_sought);
823+
save_commit_buffer = old_save_commit_buffer;
824+
}
825+
826+
/*
827+
* Returns 1 if every object pointed to by the given remote refs is available
828+
* locally and reachable from a local ref, and 0 otherwise.
829+
*/
830+
static int everything_local(struct fetch_pack_args *args,
831+
struct ref **refs)
832+
{
833+
struct ref *ref;
834+
int retval;
816835

817836
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
818837
const struct object_id *remote = &ref->old_oid;
@@ -829,8 +848,6 @@ static int everything_local(struct fetch_pack_args *args,
829848
ref->name);
830849
}
831850

832-
save_commit_buffer = old_save_commit_buffer;
833-
834851
return retval;
835852
}
836853

@@ -1053,7 +1070,9 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
10531070
if (!server_supports("deepen-relative") && args->deepen_relative)
10541071
die(_("Server does not support --deepen"));
10551072

1056-
if (everything_local(args, &ref, sought, nr_sought)) {
1073+
mark_complete_and_common_ref(args, &ref);
1074+
filter_refs(args, &ref, sought, nr_sought);
1075+
if (everything_local(args, &ref)) {
10571076
packet_flush(fd[1]);
10581077
goto all_done;
10591078
}
@@ -1377,7 +1396,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
13771396
for_each_cached_alternate(insert_one_alternate_object);
13781397

13791398
/* Filter 'ref' by 'sought' and those that aren't local */
1380-
if (everything_local(args, &ref, sought, nr_sought))
1399+
mark_complete_and_common_ref(args, &ref);
1400+
filter_refs(args, &ref, sought, nr_sought);
1401+
if (everything_local(args, &ref))
13811402
state = FETCH_DONE;
13821403
else
13831404
state = FETCH_SEND_REQUEST;

0 commit comments

Comments
 (0)