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>
Nguyễn Thái Ngọc Duy committed
May 27, 2013 at 18:18 UTC
af0b4a3b5973ebdf8fcdedcccbc2e8ddb93c8534
3 files changed
+11
-9
builtin.h
+3
@@ -12,6 +12,9 @@
12
extern const char git_usage_string[];
13
extern const char git_more_info_string[];
14
15
+#define PRUNE_PACKED_DRY_RUN 01
16
+#define PRUNE_PACKED_VERBOSE 02
17
+
18
extern void prune_packed_objects(int);
19
20
struct fmt_merge_msg_opts {
builtin/prune-packed.c
+7
-8
@@ -8,9 +8,6 @@ static const char * const prune_packed_usage[] = {
8
NULL
9
};
10
11
-#define DRY_RUN 01
12
-#define VERBOSE 02
13
-
11
static struct progress *progress;
12
13
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)
26
if (!has_sha1_pack(sha1))
27
continue;
28
memcpy(pathname + len, de->d_name, 38);
32
- if (opts & DRY_RUN)
29
+ if (opts & PRUNE_PACKED_DRY_RUN)
30
printf("rm -f %s\n", pathname);
31
else
32
unlink_or_warn(pathname);
@@ -44,7 +41,7 @@ void prune_packed_objects(int opts)
41
const char *dir = get_object_directory();
42
int len = strlen(dir);
43
47
- if (opts == VERBOSE)
44
+ if (opts & PRUNE_PACKED_VERBOSE)
45
progress = start_progress_delay("Removing duplicate objects",
46
256, 95, 2);
47
@@ -71,10 +68,12 @@ void prune_packed_objects(int opts)
68
69
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
70
{
74
- int opts = isatty(2) ? VERBOSE : 0;
71
+ int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
72
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),
77
OPT_END()
78
};
79
builtin/prune.c
+1
-1
@@ -165,7 +165,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
165
stop_progress(&progress);
166
prune_object_dir(get_object_directory());
167
168
- prune_packed_objects(show_only);
168
+ prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
169
remove_temporary_files(get_object_directory());
170
s = mkpathdup("%s/pack", get_object_directory());
171
remove_temporary_files(s);