From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: christian.couder@gmail•com, gitster@pobox•com,
johannes.schindelin@gmx•de, johncai86@gmail•com,
jonathantanmy@google•com, karthik.188@gmail•com,
kristofferhaugsbakk@fastmail•com, me@ttaylorr•com,
newren@gmail•com, peff@peff•net, ps@pks•im,
Derrick Stolee <stolee@gmail•com>,
Derrick Stolee <stolee@gmail•com>
Subject: [PATCH v2 2/2] path-walk: create initializer for path lists
Date: Mon, 25 Aug 2025 12:49:57 +0000 [thread overview]
Message-ID: <fc2c171f52d94022709bc86110711a3a9ae10a6a.1756126198.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1956.v2.git.1756126197.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail•com>
The previous change fixed a bug in 'git repack -adf --path-walk' that
was due to an update to how path lists are initialized and missing some
important cases when processing the pending objects.
This change takes the three critical places where path lists are
initialized and combines them into a static method. This simplifies the
callers somewhat while also helping to avoid a missed update in the
future.
The other places where a path list (struct type_and_oid_list) is
initialized is for the following "fixed" lists:
* Tag objects.
* Commit objects.
* Root trees.
* Tagged trees.
* Tagged blobs.
These lists are created and consumed in different ways, with only the
root trees being passed into the logic that cares about the
"maybe_interesting" bit. It is appropriate to keep these uses separate.
Signed-off-by: Derrick Stolee <stolee@gmail•com>
---
path-walk.c | 57 +++++++++++++++++++++++------------------------------
1 file changed, 25 insertions(+), 32 deletions(-)
diff --git a/path-walk.c b/path-walk.c
index 1215ed398f4f..f1ceed99e94c 100644
--- a/path-walk.c
+++ b/path-walk.c
@@ -105,6 +105,24 @@ static void push_to_stack(struct path_walk_context *ctx,
prio_queue_put(&ctx->path_stack, xstrdup(path));
}
+static void add_path_to_list(struct path_walk_context *ctx,
+ const char *path,
+ enum object_type type,
+ struct object_id *oid,
+ int interesting)
+{
+ struct type_and_oid_list *list = strmap_get(&ctx->paths_to_lists, path);
+
+ if (!list) {
+ CALLOC_ARRAY(list, 1);
+ list->type = type;
+ strmap_put(&ctx->paths_to_lists, path, list);
+ }
+
+ list->maybe_interesting |= interesting;
+ oid_array_append(&list->oids, oid);
+}
+
static int add_tree_entries(struct path_walk_context *ctx,
const char *base_path,
struct object_id *oid)
@@ -129,7 +147,6 @@ static int add_tree_entries(struct path_walk_context *ctx,
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
- struct type_and_oid_list *list;
struct object *o;
/* Not actually true, but we will ignore submodules later. */
enum object_type type = S_ISDIR(entry.mode) ? OBJ_TREE : OBJ_BLOB;
@@ -190,17 +207,10 @@ static int add_tree_entries(struct path_walk_context *ctx,
continue;
}
- if (!(list = strmap_get(&ctx->paths_to_lists, path.buf))) {
- CALLOC_ARRAY(list, 1);
- list->type = type;
- strmap_put(&ctx->paths_to_lists, path.buf, list);
- }
- push_to_stack(ctx, path.buf);
-
- if (!(o->flags & UNINTERESTING))
- list->maybe_interesting = 1;
+ add_path_to_list(ctx, path.buf, type, &entry.oid,
+ !(o->flags & UNINTERESTING));
- oid_array_append(&list->oids, &entry.oid);
+ push_to_stack(ctx, path.buf);
}
free_tree_buffer(tree);
@@ -377,16 +387,9 @@ static int setup_pending_objects(struct path_walk_info *info,
if (!info->trees)
continue;
if (pending->path) {
- struct type_and_oid_list *list;
char *path = *pending->path ? xstrfmt("%s/", pending->path)
: xstrdup("");
- if (!(list = strmap_get(&ctx->paths_to_lists, path))) {
- CALLOC_ARRAY(list, 1);
- list->type = OBJ_TREE;
- strmap_put(&ctx->paths_to_lists, path, list);
- }
- list->maybe_interesting = 1;
- oid_array_append(&list->oids, &obj->oid);
+ add_path_to_list(ctx, path, OBJ_TREE, &obj->oid, 1);
free(path);
} else {
/* assume a root tree, such as a lightweight tag. */
@@ -397,20 +400,10 @@ static int setup_pending_objects(struct path_walk_info *info,
case OBJ_BLOB:
if (!info->blobs)
continue;
- if (pending->path) {
- struct type_and_oid_list *list;
- char *path = pending->path;
- if (!(list = strmap_get(&ctx->paths_to_lists, path))) {
- CALLOC_ARRAY(list, 1);
- list->type = OBJ_BLOB;
- strmap_put(&ctx->paths_to_lists, path, list);
- }
- list->maybe_interesting = 1;
- oid_array_append(&list->oids, &obj->oid);
- } else {
- /* assume a root tree, such as a lightweight tag. */
+ if (pending->path)
+ add_path_to_list(ctx, pending->path, OBJ_BLOB, &obj->oid, 1);
+ else
oid_array_append(&tagged_blobs->oids, &obj->oid);
- }
break;
case OBJ_COMMIT:
--
gitgitgadget
next prev parent reply other threads:[~2025-08-25 12:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 18:39 [PATCH 0/3] [2.51.0 Bug] Missing singleton objects in 'git repack -adf --path-walk' Derrick Stolee via GitGitGadget
2025-08-20 18:39 ` [PATCH 1/3] t7700: add failing --path-walk test Derrick Stolee via GitGitGadget
2025-08-21 8:00 ` Patrick Steinhardt
2025-08-21 12:42 ` Derrick Stolee
2025-08-21 16:22 ` Junio C Hamano
2025-08-21 23:21 ` Elijah Newren
2025-08-20 18:39 ` [PATCH 2/3] path-walk: fix setup of pending objects Derrick Stolee via GitGitGadget
2025-08-20 19:02 ` Junio C Hamano
2025-08-20 19:42 ` Derrick Stolee
2025-08-21 8:01 ` Patrick Steinhardt
2025-08-21 12:55 ` Derrick Stolee
2025-08-21 8:01 ` Patrick Steinhardt
2025-08-21 20:33 ` Derrick Stolee
2025-08-21 23:21 ` Elijah Newren
2025-08-20 18:39 ` [PATCH 3/3] path-walk: create initializer for path lists Derrick Stolee via GitGitGadget
2025-08-21 23:22 ` Elijah Newren
2025-08-25 12:49 ` [PATCH v2 0/2] [2.51.0 Bug] Missing singleton objects in 'git repack -adf --path-walk' Derrick Stolee via GitGitGadget
2025-08-25 12:49 ` [PATCH v2 1/2] path-walk: fix setup of pending objects Derrick Stolee via GitGitGadget
2025-08-25 12:49 ` Derrick Stolee via GitGitGadget [this message]
2025-08-26 15:03 ` [PATCH v2 0/2] [2.51.0 Bug] Missing singleton objects in 'git repack -adf --path-walk' Elijah Newren
2025-08-26 15:58 ` Junio C Hamano
2025-09-02 11:19 ` Patrick Steinhardt
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=fc2c171f52d94022709bc86110711a3a9ae10a6a.1756126198.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail$(echo .)com \
--cc=christian.couder@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=johannes.schindelin@gmx$(echo .)de \
--cc=johncai86@gmail$(echo .)com \
--cc=jonathantanmy@google$(echo .)com \
--cc=karthik.188@gmail$(echo .)com \
--cc=kristofferhaugsbakk@fastmail$(echo .)com \
--cc=me@ttaylorr$(echo .)com \
--cc=newren@gmail$(echo .)com \
--cc=peff@peff$(echo .)net \
--cc=ps@pks$(echo .)im \
--cc=stolee@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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