Skip to content

Commit b77fcd1

Browse files
peffgitster
authored andcommitted
repack: handle optional files created by pack-objects
We ask pack-objects to pack to a set of temporary files, and then rename them into place. Some files that pack-objects creates may be optional (like a .bitmap file), in which case we would not want to call rename(). We already call stat() and make the chmod optional if the file cannot be accessed. We could simply skip the rename step in this case, but that would be a minor regression in noticing problems with non-optional files (like the .pack and .idx files). Instead, we can now annotate extensions as optional, and skip them if they don't exist (and otherwise rely on rename() to barf). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42a02d8 commit b77fcd1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

builtin/repack.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
117117
{
118118
struct {
119119
const char *name;
120+
unsigned optional:1;
120121
} exts[] = {
121122
{".pack"},
122123
{".idx"},
@@ -323,16 +324,20 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
323324
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
324325
char *fname, *fname_old;
325326
struct stat statbuffer;
327+
int exists = 0;
326328
fname = mkpathdup("%s/pack-%s%s",
327329
packdir, item->string, exts[ext].name);
328330
fname_old = mkpathdup("%s-%s%s",
329331
packtmp, item->string, exts[ext].name);
330332
if (!stat(fname_old, &statbuffer)) {
331333
statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
332334
chmod(fname_old, statbuffer.st_mode);
335+
exists = 1;
336+
}
337+
if (exists || !exts[ext].optional) {
338+
if (rename(fname_old, fname))
339+
die_errno(_("renaming '%s' failed"), fname_old);
333340
}
334-
if (rename(fname_old, fname))
335-
die_errno(_("renaming '%s' failed"), fname_old);
336341
free(fname);
337342
free(fname_old);
338343
}

0 commit comments

Comments
 (0)