]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-objects: extract `record_tree_depth()` helper
authorTaylor Blau <me@ttaylorr.com>
Tue, 2 Jun 2026 22:21:50 +0000 (18:21 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Jun 2026 23:52:59 +0000 (08:52 +0900)
Prepare for a subsequent change that needs to record tree depths from a
second call site by factoring the delta-islands tree-depth bookkeeping
out of `show_object()` and into a helper, `record_tree_depth()`.

The helper looks up the object in `to_pack`, returns early when the
object was not added there, computes the depth from the slash count in
the supplied name, and preserves the existing max-depth-wins behavior
when a tree is reached by more than one path.

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

index b3822dc86c32826f4dab848c1901aa08bcf99810..db65d0e189ed31b00fd2f181729c27188217bb46 100644 (file)
@@ -2730,6 +2730,22 @@ static inline void oe_set_tree_depth(struct packing_data *pack,
        pack->tree_depth[e - pack->objects] = tree_depth;
 }
 
+static void record_tree_depth(const struct object_id *oid, const char *name)
+{
+       const char *p;
+       unsigned depth;
+       struct object_entry *ent;
+
+       /* the empty string is a root tree, which is depth 0 */
+       depth = *name ? 1 : 0;
+       for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
+               depth++;
+
+       ent = packlist_find(&to_pack, oid);
+       if (ent && depth > oe_tree_depth(&to_pack, ent))
+               oe_set_tree_depth(&to_pack, ent, depth);
+}
+
 /*
  * Return the size of the object without doing any delta
  * reconstruction (so non-deltas are true object sizes, but deltas
@@ -4385,20 +4401,8 @@ static void show_object(struct object *obj, const char *name,
        add_preferred_base_object(name);
        add_object_entry(&obj->oid, obj->type, name, 0);
 
-       if (use_delta_islands) {
-               const char *p;
-               unsigned depth;
-               struct object_entry *ent;
-
-               /* the empty string is a root tree, which is depth 0 */
-               depth = *name ? 1 : 0;
-               for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
-                       depth++;
-
-               ent = packlist_find(&to_pack, &obj->oid);
-               if (ent && depth > oe_tree_depth(&to_pack, ent))
-                       oe_set_tree_depth(&to_pack, ent, depth);
-       }
+       if (use_delta_islands)
+               record_tree_depth(&obj->oid, name);
 }
 
 static void show_object__ma_allow_any(struct object *obj, const char *name, void *data)