Skip to content

Commit 9d7fbfd

Browse files
tboegigitster
authored andcommitted
repack.c: rename and unlink pack file if it exists
When a repo was fully repacked, and is repacked again, we may run into the situation that "new" packfiles have the same name as already existing ones (traditionally packfiles have been named after the list of names of objects in them, so repacking all the objects in a single pack would have produced a packfile with the same name). The logic is to rename the existing ones into filename like "old-XXX", create the new ones and then remove the "old-" ones. When something went wrong in the middle, this sequence is rolled back by renaming the "old-" files back. The renaming into "old-" did not work as intended, because file_exists() was done on "XXX", not "pack-XXX". Also when rolling back the change, the code tried to rename "old-pack-XXX" but the saved ones are named "old-XXX", so this couldn't have worked. Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b861e23 commit 9d7fbfd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

builtin/repack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
260260
for_each_string_list_item(item, &names) {
261261
for (ext = 0; ext < 2; ext++) {
262262
char *fname, *fname_old;
263-
fname = mkpathdup("%s/%s%s", packdir,
263+
fname = mkpathdup("%s/pack-%s%s", packdir,
264264
item->string, exts[ext]);
265265
if (!file_exists(fname)) {
266266
free(fname);
@@ -337,7 +337,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
337337
for_each_string_list_item(item, &names) {
338338
for (ext = 0; ext < 2; ext++) {
339339
char *fname;
340-
fname = mkpath("%s/old-pack-%s%s",
340+
fname = mkpath("%s/old-%s%s",
341341
packdir,
342342
item->string,
343343
exts[ext]);

0 commit comments

Comments
 (0)