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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 14, 2023 at 08:01 UTC
752b465c3c0fd7f503b50c326017b8b13af83c3b
2 files changed
+23
-5
builtin/pack-objects.c
+3
-5
@@ -3351,11 +3351,9 @@ static void read_packs_list_from_stdin(void)
3351
for (p = get_all_packs(the_repository); p; p = p->next) {
3352
const char *pack_name = pack_basename(p);
3353
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)))
3357
item->util = p;
3358
}
3359
t/t5331-pack-objects-stdin.sh
+20
@@ -169,4 +169,24 @@ test_expect_success 'pack-objects --stdin with duplicate packfile' '
169
)
170
'
171
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
+
192
test_done