Git development
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee <stolee@gmail.com>, Jeff King <peff@peff.net>,
	Elijah Newren <newren@gmail.com>
Subject: [RFC PATCH 6/7] pack-objects: extract `record_tree_depth()` helper
Date: Sun, 3 May 2026 20:11:32 -0400	[thread overview]
Message-ID: <35b4485fa5258f63d0e0996be7760ec83e9adac6.1777853408.git.me@ttaylorr.com> (raw)
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


  parent reply	other threads:[~2026-05-04  0:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04  0:11 [RFC PATCH 0/7] pack-bitmap: resolve various `--path-walk` incompatibilities Taylor Blau
2026-05-04  0:11 ` [RFC PATCH 1/7] pack-objects: update `--path-walk`'s existing incompatibilities Taylor Blau
2026-05-04 12:22   ` Derrick Stolee
2026-05-04  0:11 ` [RFC PATCH 2/7] path-walk: support `tree:0` filter Taylor Blau
2026-05-04 12:30   ` Derrick Stolee
2026-05-04 21:55   ` Kristoffer Haugsbakk
2026-05-04  0:11 ` [RFC PATCH 3/7] path-walk: support `object:type` filter Taylor Blau
2026-05-04 12:32   ` Derrick Stolee
2026-05-04  0:11 ` [RFC PATCH 4/7] path-walk: support `combine` filter Taylor Blau
2026-05-04  0:11 ` [RFC PATCH 5/7] pack-objects: support reachability bitmaps with `--path-walk` Taylor Blau
2026-05-04  0:11 ` Taylor Blau [this message]
2026-05-04  0:11 ` [RFC PATCH 7/7] pack-objects: support `--delta-islands` " Taylor Blau
2026-05-04 12:13 ` [RFC PATCH 0/7] pack-bitmap: resolve various `--path-walk` incompatibilities Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=35b4485fa5258f63d0e0996be7760ec83e9adac6.1777853408.git.me@ttaylorr.com \
    --to=me@ttaylorr.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox