]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-objects: declare 'rev_info' for '--stdin-packs' earlier
authorTaylor Blau <me@ttaylorr.com>
Mon, 23 Jun 2025 22:32:18 +0000 (18:32 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Jun 2025 22:41:36 +0000 (15:41 -0700)
Once 'read_packs_list_from_stdin()' has called for_each_object_in_pack()
on each of the input packs, we do a reachability traversal to discover
names for any objects we picked up so we can generate name hash values
and hopefully get higher quality deltas as a result.

A future commit will change the purpose of this reachability traversal
to find and pack objects which are reachable from commits in the input
packs, but are packed in an unknown (not included nor excluded) pack.

Extract the code which initializes and performs the reachability
traversal to take place in the caller, not the callee, which prepares us
to share this code for the '--unpacked' case (see the function
add_unreachable_loose_objects() for more details).

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c

index 7ce04b71ddf72b6ef62031a835804ca78479b041..4258ac1792ab30843bebc5ac48ca97a0c490423f 100644 (file)
@@ -3793,7 +3793,7 @@ static int pack_mtime_cmp(const void *_a, const void *_b)
                return 0;
 }
 
-static void read_packs_list_from_stdin(void)
+static void read_packs_list_from_stdin(struct rev_info *revs)
 {
        struct strbuf buf = STRBUF_INIT;
        struct string_list include_packs = STRING_LIST_INIT_DUP;
@@ -3801,24 +3801,6 @@ static void read_packs_list_from_stdin(void)
        struct string_list_item *item = NULL;
 
        struct packed_git *p;
-       struct rev_info revs;
-
-       repo_init_revisions(the_repository, &revs, NULL);
-       /*
-        * Use a revision walk to fill in the namehash of objects in the include
-        * packs. To save time, we'll avoid traversing through objects that are
-        * in excluded packs.
-        *
-        * That may cause us to avoid populating all of the namehash fields of
-        * all included objects, but our goal is best-effort, since this is only
-        * an optimization during delta selection.
-        */
-       revs.no_kept_objects = 1;
-       revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
-       revs.blob_objects = 1;
-       revs.tree_objects = 1;
-       revs.tag_objects = 1;
-       revs.ignore_missing_links = 1;
 
        while (strbuf_getline(&buf, stdin) != EOF) {
                if (!buf.len)
@@ -3888,22 +3870,10 @@ static void read_packs_list_from_stdin(void)
                struct packed_git *p = item->util;
                for_each_object_in_pack(p,
                                        add_object_entry_from_pack,
-                                       &revs,
+                                       revs,
                                        FOR_EACH_OBJECT_PACK_ORDER);
        }
 
-       if (prepare_revision_walk(&revs))
-               die(_("revision walk setup failed"));
-       traverse_commit_list(&revs,
-                            show_commit_pack_hint,
-                            show_object_pack_hint,
-                            NULL);
-
-       trace2_data_intmax("pack-objects", the_repository, "stdin_packs_found",
-                          stdin_packs_found_nr);
-       trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
-                          stdin_packs_hints_nr);
-
        strbuf_release(&buf);
        string_list_clear(&include_packs, 0);
        string_list_clear(&exclude_packs, 0);
@@ -3913,11 +3883,42 @@ static void add_unreachable_loose_objects(void);
 
 static void read_stdin_packs(int rev_list_unpacked)
 {
+       struct rev_info revs;
+
+       repo_init_revisions(the_repository, &revs, NULL);
+       /*
+        * Use a revision walk to fill in the namehash of objects in the include
+        * packs. To save time, we'll avoid traversing through objects that are
+        * in excluded packs.
+        *
+        * That may cause us to avoid populating all of the namehash fields of
+        * all included objects, but our goal is best-effort, since this is only
+        * an optimization during delta selection.
+        */
+       revs.no_kept_objects = 1;
+       revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
+       revs.blob_objects = 1;
+       revs.tree_objects = 1;
+       revs.tag_objects = 1;
+       revs.ignore_missing_links = 1;
+
        /* avoids adding objects in excluded packs */
        ignore_packed_keep_in_core = 1;
-       read_packs_list_from_stdin();
+       read_packs_list_from_stdin(&revs);
        if (rev_list_unpacked)
                add_unreachable_loose_objects();
+
+       if (prepare_revision_walk(&revs))
+               die(_("revision walk setup failed"));
+       traverse_commit_list(&revs,
+                            show_commit_pack_hint,
+                            show_object_pack_hint,
+                            NULL);
+
+       trace2_data_intmax("pack-objects", the_repository, "stdin_packs_found",
+                          stdin_packs_found_nr);
+       trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
+                          stdin_packs_hints_nr);
 }
 
 static void add_cruft_object_entry(const struct object_id *oid, enum object_type type,