]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch-pack: move fetch initialization
authorCalvin Wan <calvinwan@google.com>
Fri, 24 Jul 2026 10:54:19 +0000 (12:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Jul 2026 15:46:59 +0000 (08:46 -0700)
There are some variables initialized at the start of the
do_fetch_pack_v2() state machine. Currently, they are initialized in
FETCH_CHECK_LOCAL, which is the initial state set at the beginning
of the function.

However, a subsequent patch will allow for another initial state,
while still requiring these initialized variables.
Move the initialization to be before the state machine,
so that they are set regardless of the initial state.

Note that there is no change in behavior, because we're moving code
from the beginning of the first state to just before the execution of
the state machine.

Helped-by: Jonathan Tan <jonathantanmy@google.com>
Helped-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Eric Ju <eric.peijian@gmail.com>
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fetch-pack.c

index 3695059cd55b03e238ed7917ec4afe3e6bd520f2..922a9b25812c68aa787feb950b24bcab1c026af3 100644 (file)
@@ -1735,18 +1735,18 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                reader.me = "fetch-pack";
        }
 
+       /* v2 supports these by default */
+       allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
+       use_sideband = 2;
+       if (args->depth > 0 || args->deepen_since || args->deepen_not)
+               args->deepen = 1;
+
        while (state != FETCH_DONE) {
                switch (state) {
                case FETCH_CHECK_LOCAL:
                        sort_ref_list(&ref, ref_compare_name);
                        QSORT(sought, nr_sought, cmp_ref_by_name);
 
-                       /* v2 supports these by default */
-                       allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
-                       use_sideband = 2;
-                       if (args->depth > 0 || args->deepen_since || args->deepen_not)
-                               args->deepen = 1;
-
                        /* Filter 'ref' by 'sought' and those that aren't local */
                        mark_complete_and_common_ref(negotiator, args, &ref);
                        filter_refs(args, &ref, sought, nr_sought);