Skip to content

Commit

Permalink
repack.c: rename and unlink pack file if it exists
Browse files Browse the repository at this point in the history
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 <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Torsten Bögershausen authored and Junio C Hamano committed Feb 5, 2014
1 parent b861e23 commit 9d7fbfd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
for_each_string_list_item(item, &names) {
for (ext = 0; ext < 2; ext++) {
char *fname, *fname_old;
fname = mkpathdup("%s/%s%s", packdir,
fname = mkpathdup("%s/pack-%s%s", packdir,
item->string, exts[ext]);
if (!file_exists(fname)) {
free(fname);
Expand Down Expand Up @@ -337,7 +337,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
for_each_string_list_item(item, &names) {
for (ext = 0; ext < 2; ext++) {
char *fname;
fname = mkpath("%s/old-pack-%s%s",
fname = mkpath("%s/old-%s%s",
packdir,
item->string,
exts[ext]);
Expand Down

0 comments on commit 9d7fbfd

Please sign in to comment.