Skip to content

Commit 42a02d8

Browse files
peffgitster
authored andcommitted
repack: turn exts array into array-of-struct
This is slightly more verbose, but will let us annotate the extensions with further options in future commits. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b328c21 commit 42a02d8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

builtin/repack.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
115115

116116
int cmd_repack(int argc, const char **argv, const char *prefix)
117117
{
118-
const char *exts[] = {".pack", ".idx"};
118+
struct {
119+
const char *name;
120+
} exts[] = {
121+
{".pack"},
122+
{".idx"},
123+
};
119124
struct child_process cmd;
120125
struct string_list_item *item;
121126
struct argv_array cmd_args = ARGV_ARRAY_INIT;
@@ -261,14 +266,14 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
261266
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
262267
char *fname, *fname_old;
263268
fname = mkpathdup("%s/%s%s", packdir,
264-
item->string, exts[ext]);
269+
item->string, exts[ext].name);
265270
if (!file_exists(fname)) {
266271
free(fname);
267272
continue;
268273
}
269274

270275
fname_old = mkpath("%s/old-%s%s", packdir,
271-
item->string, exts[ext]);
276+
item->string, exts[ext].name);
272277
if (file_exists(fname_old))
273278
if (unlink(fname_old))
274279
failed = 1;
@@ -319,9 +324,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
319324
char *fname, *fname_old;
320325
struct stat statbuffer;
321326
fname = mkpathdup("%s/pack-%s%s",
322-
packdir, item->string, exts[ext]);
327+
packdir, item->string, exts[ext].name);
323328
fname_old = mkpathdup("%s-%s%s",
324-
packtmp, item->string, exts[ext]);
329+
packtmp, item->string, exts[ext].name);
325330
if (!stat(fname_old, &statbuffer)) {
326331
statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
327332
chmod(fname_old, statbuffer.st_mode);
@@ -340,7 +345,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
340345
fname = mkpath("%s/old-pack-%s%s",
341346
packdir,
342347
item->string,
343-
exts[ext]);
348+
exts[ext].name);
344349
if (remove_path(fname))
345350
warning(_("removing '%s' failed"), fname);
346351
}

0 commit comments

Comments
 (0)