diff mbox series

[v4,06/10] pack-objects: fix error when same packfile is included and excluded

Message ID 33aea4c71edf60094e01ef245429befe1142c0ea.1681452028.git.ps@pks.im (mailing list archive)
State Accepted
Commit 752b465c3c0fd7f503b50c326017b8b13af83c3b
Headers show
Series [v4,01/10] midx: fix segfault with no packs and invalid preferred pack | expand

Commit Message

Patrick Steinhardt April 14, 2023, 6:01 a.m. UTC
When passing the same packfile both as included and excluded via the
`--stdin-packs` option, then we will return an error because the
excluded packfile cannot be found. This is because we will only set the
`util` pointer for the included packfile list if it was found, so that
we later die when we notice that it's in fact not set for the excluded
packfile list.

Fix this bug by always setting the `util` pointer for both the included
and excluded list entries.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/pack-objects.c        |  8 +++-----
 t/t5331-pack-objects-stdin.sh | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 7d0e864c35..c5147d392f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3355,11 +3355,9 @@  static void read_packs_list_from_stdin(void)
 	for (p = get_all_packs(the_repository); p; p = p->next) {
 		const char *pack_name = pack_basename(p);
 
-		item = string_list_lookup(&include_packs, pack_name);
-		if (!item)
-			item = string_list_lookup(&exclude_packs, pack_name);
-
-		if (item)
+		if ((item = string_list_lookup(&include_packs, pack_name)))
+			item->util = p;
+		if ((item = string_list_lookup(&exclude_packs, pack_name)))
 			item->util = p;
 	}
 
diff --git a/t/t5331-pack-objects-stdin.sh b/t/t5331-pack-objects-stdin.sh
index 71c8a4a635..3ef736ec05 100755
--- a/t/t5331-pack-objects-stdin.sh
+++ b/t/t5331-pack-objects-stdin.sh
@@ -169,4 +169,24 @@  test_expect_success 'pack-objects --stdin with duplicate packfile' '
 	)
 '
 
+test_expect_success 'pack-objects --stdin with same packfile excluded and included' '
+	test_when_finished "rm -fr repo" &&
+
+	git init repo &&
+	(
+		cd repo &&
+		test_commit "commit" &&
+		git repack -ad &&
+
+		{
+			basename .git/objects/pack/pack-*.pack &&
+			printf "^%s\n" "$(basename .git/objects/pack/pack-*.pack)"
+		} >packfiles &&
+
+		git pack-objects --stdin-packs generated-pack <packfiles &&
+		packed_objects generated-pack-*.idx >packed-objects &&
+		test_must_be_empty packed-objects
+	)
+'
+
 test_done