fetch-pack: move fetch initialization

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>

Calvin Wan committed Jul 24, 2026 at 12:54 UTC 24f082e6f45e39dc36f55a3344696d707740f56e
1 file changed +6 -6
fetch-pack.c
+6 -6
@@ -1735,18 +1735,18 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1735 reader.me = "fetch-pack";
1736 }
1737
1738 + /* v2 supports these by default */
1739 + allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1740 + use_sideband = 2;
1741 + if (args->depth > 0 || args->deepen_since || args->deepen_not)
1742 + args->deepen = 1;
1743 +
1744 while (state != FETCH_DONE) {
1745 switch (state) {
1746 case FETCH_CHECK_LOCAL:
1747 sort_ref_list(&ref, ref_compare_name);
1748 QSORT(sought, nr_sought, cmp_ref_by_name);
1749
1744 - /* v2 supports these by default */
1745 - allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1746 - use_sideband = 2;
1747 - if (args->depth > 0 || args->deepen_since || args->deepen_not)
1748 - args->deepen = 1;
1749 -
1750 /* Filter 'ref' by 'sought' and those that aren't local */
1751 mark_complete_and_common_ref(negotiator, args, &ref);
1752 filter_refs(args, &ref, sought, nr_sought);