{"thread":{"id":"33947","subject":"[PATCH] prune-packed: avoid implying \"1\" is DRY_RUN in prune_packed_objects()","startedAt":"2013-05-27T11:18:47Z","lastAt":"2013-05-27T11:18:47Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"218599","messageId":"1369653527-2233-1-git-send-email-pclouds@gmail.com","threadId":"33947","inReplyTo":null,"subject":"[PATCH] prune-packed: avoid implying \"1\" is DRY_RUN in prune_packed_objects()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-05-27T11:18:47Z","receivedAt":"2013-05-27T11:18:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Commit b60daf0 (Make git-prune-packed a bit more chatty. - 2007-01-12)\nchanges the meaning of prune_packed_objects()'s argument, from \"dry\nrun or not dry run\" to a bitmap.\n\nIt however forgot to update prune_packed_objects() caller in\nbuiltin/prune.c to use new DRY_RUN macro. It's fine (for a long time!)\nbut there is a risk that someday someone may change the value of\nDRY_RUN to something else and builtin/prune.c suddenly breaks. Avoid\nthat possibility.\n\nWhile at there, change \"opts == VERBOSE\" to \"opts & VERBOSE\" as there\nis no obvious reason why we only be chatty when DRY_RUN is not set.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin.h              |  3 +++\n builtin/prune-packed.c | 15 +++++++--------\n builtin/prune.c        |  2 +-\n 3 files changed, 11 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin.h b/builtin.h\nindex faef559..64bab6b 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -12,6 +12,9 @@\n extern const char git_usage_string[];\n extern const char git_more_info_string[];\n \n+#define PRUNE_PACKED_DRY_RUN 01\n+#define PRUNE_PACKED_VERBOSE 02\n+\n extern void prune_packed_objects(int);\n \n struct fmt_merge_msg_opts {\ndiff --git a/builtin/prune-packed.c b/builtin/prune-packed.c\nindex 83382c1..fa6ce42 100644\n--- a/builtin/prune-packed.c\n+++ b/builtin/prune-packed.c\n@@ -8,9 +8,6 @@ static const char * const prune_packed_usage[] = {\n \tNULL\n };\n \n-#define DRY_RUN 01\n-#define VERBOSE 02\n-\n static struct progress *progress;\n \n static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)\n@@ -29,7 +26,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)\n \t\tif (!has_sha1_pack(sha1))\n \t\t\tcontinue;\n \t\tmemcpy(pathname + len, de->d_name, 38);\n-\t\tif (opts & DRY_RUN)\n+\t\tif (opts & PRUNE_PACKED_DRY_RUN)\n \t\t\tprintf(\"rm -f %s\\n\", pathname);\n \t\telse\n \t\t\tunlink_or_warn(pathname);\n@@ -44,7 +41,7 @@ void prune_packed_objects(int opts)\n \tconst char *dir = get_object_directory();\n \tint len = strlen(dir);\n \n-\tif (opts == VERBOSE)\n+\tif (opts & PRUNE_PACKED_VERBOSE)\n \t\tprogress = start_progress_delay(\"Removing duplicate objects\",\n \t\t\t256, 95, 2);\n \n@@ -71,10 +68,12 @@ void prune_packed_objects(int opts)\n \n int cmd_prune_packed(int argc, const char **argv, const char *prefix)\n {\n-\tint opts = isatty(2) ? VERBOSE : 0;\n+\tint opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;\n \tconst struct option prune_packed_options[] = {\n-\t\tOPT_BIT('n', \"dry-run\", &opts, N_(\"dry run\"), DRY_RUN),\n-\t\tOPT_NEGBIT('q', \"quiet\", &opts, N_(\"be quiet\"), VERBOSE),\n+\t\tOPT_BIT('n', \"dry-run\", &opts, N_(\"dry run\"),\n+\t\t\tPRUNE_PACKED_DRY_RUN),\n+\t\tOPT_NEGBIT('q', \"quiet\", &opts, N_(\"be quiet\"),\n+\t\t\t   PRUNE_PACKED_VERBOSE),\n \t\tOPT_END()\n \t};\n \ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex 85843d4..59d1fdc 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -165,7 +165,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)\n \tstop_progress(&progress);\n \tprune_object_dir(get_object_directory());\n \n-\tprune_packed_objects(show_only);\n+\tprune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);\n \tremove_temporary_files(get_object_directory());\n \ts = mkpathdup(\"%s/pack\", get_object_directory());\n \tremove_temporary_files(s);\n-- \n1.8.2.83.gc99314b\n"}]}