]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-objects: fix error when same packfile is included and excluded
authorPatrick Steinhardt <ps@pks.im>
Fri, 14 Apr 2023 06:01:54 +0000 (08:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Apr 2023 17:27:51 +0000 (10:27 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
t/t5331-pack-objects-stdin.sh

index c97ae1b6d00115f8ec2a0fe04d5f831274b3002f..884b84a2fdb13e862ff6aa6e620d9426ff18c1f3 100644 (file)
@@ -3351,11 +3351,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;
        }
 
index 71c8a4a6356558bb0d9abc4d9d87e12f30f25f61..3ef736ec052575225e90cce04af2158c8ffc3630 100755 (executable)
@@ -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