Skip to content

Commit 752b465

Browse files
pks-tgitster
authored andcommitted
pack-objects: fix error when same packfile is included and excluded
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 732194b commit 752b465

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,11 +3351,9 @@ static void read_packs_list_from_stdin(void)
33513351
for (p = get_all_packs(the_repository); p; p = p->next) {
33523352
const char *pack_name = pack_basename(p);
33533353

3354-
item = string_list_lookup(&include_packs, pack_name);
3355-
if (!item)
3356-
item = string_list_lookup(&exclude_packs, pack_name);
3357-
3358-
if (item)
3354+
if ((item = string_list_lookup(&include_packs, pack_name)))
3355+
item->util = p;
3356+
if ((item = string_list_lookup(&exclude_packs, pack_name)))
33593357
item->util = p;
33603358
}
33613359

t/t5331-pack-objects-stdin.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,24 @@ test_expect_success 'pack-objects --stdin with duplicate packfile' '
169169
)
170170
'
171171

172+
test_expect_success 'pack-objects --stdin with same packfile excluded and included' '
173+
test_when_finished "rm -fr repo" &&
174+
175+
git init repo &&
176+
(
177+
cd repo &&
178+
test_commit "commit" &&
179+
git repack -ad &&
180+
181+
{
182+
basename .git/objects/pack/pack-*.pack &&
183+
printf "^%s\n" "$(basename .git/objects/pack/pack-*.pack)"
184+
} >packfiles &&
185+
186+
git pack-objects --stdin-packs generated-pack <packfiles &&
187+
packed_objects generated-pack-*.idx >packed-objects &&
188+
test_must_be_empty packed-objects
189+
)
190+
'
191+
172192
test_done

0 commit comments

Comments
 (0)