pack-objects: extract `record_tree_depth()` helper
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>
Taylor Blau committed
Jun 21, 2026 at 19:03 UTC
264efee401e04de50055d1519dda1fbd1e02428f
1 file changed
+18
-14
builtin/pack-objects.c
+18
-14
@@ -2730,6 +2730,22 @@ static inline void oe_set_tree_depth(struct packing_data *pack,
2730
pack->tree_depth[e - pack->objects] = tree_depth;
2731
}
2732
2733
+static void record_tree_depth(const struct object_id *oid, const char *name)
2734
+{
2735
+ const char *p;
2736
+ unsigned depth;
2737
+ struct object_entry *ent;
2738
+
2739
+ /* the empty string is a root tree, which is depth 0 */
2740
+ depth = *name ? 1 : 0;
2741
+ for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
2742
+ depth++;
2743
+
2744
+ ent = packlist_find(&to_pack, oid);
2745
+ if (ent && depth > oe_tree_depth(&to_pack, ent))
2746
+ oe_set_tree_depth(&to_pack, ent, depth);
2747
+}
2748
+
2749
/*
2750
* Return the size of the object without doing any delta
2751
* reconstruction (so non-deltas are true object sizes, but deltas
@@ -4385,20 +4401,8 @@ static void show_object(struct object *obj, const char *name,
4401
add_preferred_base_object(name);
4402
add_object_entry(&obj->oid, obj->type, name, 0);
4403
4388
- if (use_delta_islands) {
4389
- const char *p;
4390
- unsigned depth;
4391
- struct object_entry *ent;
4392
-
4393
- /* the empty string is a root tree, which is depth 0 */
4394
- depth = *name ? 1 : 0;
4395
- for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
4396
- depth++;
4397
-
4398
- ent = packlist_find(&to_pack, &obj->oid);
4399
- if (ent && depth > oe_tree_depth(&to_pack, ent))
4400
- oe_set_tree_depth(&to_pack, ent, depth);
4401
- }
4404
+ if (use_delta_islands)
4405
+ record_tree_depth(&obj->oid, name);
4406
}
4407
4408
static void show_object__ma_allow_any(struct object *obj, const char *name, void *data)