Skip to content

Commit b328c21

Browse files
peffgitster
authored andcommitted
repack: stop using magic number for ARRAY_SIZE(exts)
We have a static array of extensions, but hardcode the size of the array in our loops. Let's pull out this magic number, which will make it easier to change. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7cc8f97 commit b328c21

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/repack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ 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[2] = {".pack", ".idx"};
118+
const char *exts[] = {".pack", ".idx"};
119119
struct child_process cmd;
120120
struct string_list_item *item;
121121
struct argv_array cmd_args = ARGV_ARRAY_INIT;
@@ -258,7 +258,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
258258
*/
259259
failed = 0;
260260
for_each_string_list_item(item, &names) {
261-
for (ext = 0; ext < 2; ext++) {
261+
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
262262
char *fname, *fname_old;
263263
fname = mkpathdup("%s/%s%s", packdir,
264264
item->string, exts[ext]);
@@ -315,7 +315,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
315315

316316
/* Now the ones with the same name are out of the way... */
317317
for_each_string_list_item(item, &names) {
318-
for (ext = 0; ext < 2; ext++) {
318+
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
319319
char *fname, *fname_old;
320320
struct stat statbuffer;
321321
fname = mkpathdup("%s/pack-%s%s",
@@ -335,7 +335,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
335335

336336
/* Remove the "old-" files */
337337
for_each_string_list_item(item, &names) {
338-
for (ext = 0; ext < 2; ext++) {
338+
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
339339
char *fname;
340340
fname = mkpath("%s/old-pack-%s%s",
341341
packdir,

0 commit comments

Comments
 (0)