Skip to content

Commit af0b4a3

Browse files
pcloudsgitster
authored andcommitted
prune-packed: avoid implying "1" is DRY_RUN in prune_packed_objects()
Commit b60daf0 (Make git-prune-packed a bit more chatty. - 2007-01-12) changes the meaning of prune_packed_objects()'s argument, from "dry run or not dry run" to a bitmap. It however forgot to update prune_packed_objects() caller in builtin/prune.c to use new DRY_RUN macro. It's fine (for a long time!) but there is a risk that someday someone may change the value of DRY_RUN to something else and builtin/prune.c suddenly breaks. Avoid that possibility. While at there, change "opts == VERBOSE" to "opts & VERBOSE" as there is no obvious reason why we only be chatty when DRY_RUN is not set. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent edca415 commit af0b4a3

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

builtin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
extern const char git_usage_string[];
1313
extern const char git_more_info_string[];
1414

15+
#define PRUNE_PACKED_DRY_RUN 01
16+
#define PRUNE_PACKED_VERBOSE 02
17+
1518
extern void prune_packed_objects(int);
1619

1720
struct fmt_merge_msg_opts {

builtin/prune-packed.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ static const char * const prune_packed_usage[] = {
88
NULL
99
};
1010

11-
#define DRY_RUN 01
12-
#define VERBOSE 02
13-
1411
static struct progress *progress;
1512

1613
static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
@@ -29,7 +26,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
2926
if (!has_sha1_pack(sha1))
3027
continue;
3128
memcpy(pathname + len, de->d_name, 38);
32-
if (opts & DRY_RUN)
29+
if (opts & PRUNE_PACKED_DRY_RUN)
3330
printf("rm -f %s\n", pathname);
3431
else
3532
unlink_or_warn(pathname);
@@ -44,7 +41,7 @@ void prune_packed_objects(int opts)
4441
const char *dir = get_object_directory();
4542
int len = strlen(dir);
4643

47-
if (opts == VERBOSE)
44+
if (opts & PRUNE_PACKED_VERBOSE)
4845
progress = start_progress_delay("Removing duplicate objects",
4946
256, 95, 2);
5047

@@ -71,10 +68,12 @@ void prune_packed_objects(int opts)
7168

7269
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
7370
{
74-
int opts = isatty(2) ? VERBOSE : 0;
71+
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
7572
const struct option prune_packed_options[] = {
76-
OPT_BIT('n', "dry-run", &opts, N_("dry run"), DRY_RUN),
77-
OPT_NEGBIT('q', "quiet", &opts, N_("be quiet"), VERBOSE),
73+
OPT_BIT('n', "dry-run", &opts, N_("dry run"),
74+
PRUNE_PACKED_DRY_RUN),
75+
OPT_NEGBIT('q', "quiet", &opts, N_("be quiet"),
76+
PRUNE_PACKED_VERBOSE),
7877
OPT_END()
7978
};
8079

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
165165
stop_progress(&progress);
166166
prune_object_dir(get_object_directory());
167167

168-
prune_packed_objects(show_only);
168+
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
169169
remove_temporary_files(get_object_directory());
170170
s = mkpathdup("%s/pack", get_object_directory());
171171
remove_temporary_files(s);

0 commit comments

Comments
 (0)