git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 6/7] pack-objects: extract `record_tree_depth()` helper

From
Taylor Blau <me@ttaylorr.com>
Date
May 4, 2026, 00:11 UTC
Message-ID
<35b4485fa5258f63d0e0996be7760ec83e9adac6.1777853408.git.me@ttaylorr.com>
In-Reply-To
<cover.1777853408.git.me@ttaylorr.com>

Prepare for a future change that needs to record tree depths from a second call site by factoring out the delta islands-specific portion of `show_object()` out into a helper, `record_tree_depth()`.

`record_tree_depth()` takes a tree OID along with the path that `show_object()` received, and computes the directory depth from the slash count in the path.

While we're in the area, make a few minor clean-ups:
 - Gate the call on `obj->type == OBJ_TREE`, as we only care to compute
   the depth for tree objects. The sole caller of `oe_tree_depth()`
   resides in `delta-islands.c::resolve_tree_islands()`, and only calls
   `oe_tree_depth()` behind `oe_type(...) == OBJ_TREE`.
 - Defer computing the depth for an object until we know it is in the
   `to_pack` list.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 builtin/pack-objects.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1a5f1afd32e..842d1fcac29 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2722,6 +2722,24 @@ 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 = packlist_find(&to_pack, oid);
+
+	if (!ent)
+		return;
+
+	/* 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++;
+
+	if (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
@@ -4375,20 +4393,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 && obj->type == OBJ_TREE)
+		record_tree_depth(&obj->oid, name);
 }
 
 static void show_object__ma_allow_any(struct object *obj, const char *name, void *data)
-- 
2.54.0.4.g6aa0d38a4ec
Previous: Taylor BlauNext: Taylor Blau
Message 11 of 13 in “pack-bitmap: resolve various `--path-walk` incompatibilities”
  1. 0/7 pack-bitmap: resolve various `--path-walk` incompatibilitiesTaylor Blau, May 4, 2026
  2. 1/7 pack-objects: update `--path-walk`'s existing incompatibilitiesTaylor Blau, May 4, 2026
  3. Derrick StoleeMay 4, 2026
  4. 2/7 path-walk: support `tree:0` filterTaylor Blau, May 4, 2026
  5. Derrick StoleeMay 4, 2026
  6. Kristoffer HaugsbakkMay 4, 2026
  7. 3/7 path-walk: support `object:type` filterTaylor Blau, May 4, 2026
  8. Derrick StoleeMay 4, 2026
  9. 4/7 path-walk: support `combine` filterTaylor Blau, May 4, 2026
  10. 5/7 pack-objects: support reachability bitmaps with `--path-walk`Taylor Blau, May 4, 2026
  11. 6/7 pack-objects: extract `record_tree_depth()` helperTaylor Blau, May 4, 2026
  12. 7/7 pack-objects: support `--delta-islands` with `--path-walk`Taylor Blau, May 4, 2026
  13. Derrick StoleeMay 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.