Merge branch 'jc/rerere'
[gitweb.git] / builtin / rerere.c
index fd229a7c7dae54be4285ba4d9528fb4d1aae2b74..8c6cb6cdc633db0a967feed1457c4aac60176088 100644 (file)
@@ -9,7 +9,7 @@
 #include "pathspec.h"
 
 static const char * const rerere_usage[] = {
-       N_("git rerere [clear | forget path... | status | remaining | diff | gc]"),
+       N_("git rerere [clear | forget <path>... | status | remaining | diff | gc]"),
        NULL,
 };
 
@@ -50,7 +50,7 @@ static int diff_two(const char *file1, const char *label1,
 int cmd_rerere(int argc, const char **argv, const char *prefix)
 {
        struct string_list merge_rr = STRING_LIST_INIT_DUP;
-       int i, fd, autoupdate = -1, flags = 0;
+       int i, autoupdate = -1, flags = 0;
 
        struct option options[] = {
                OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
@@ -79,18 +79,16 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
                return rerere_forget(&pathspec);
        }
 
-       fd = setup_rerere(&merge_rr, flags);
-       if (fd < 0)
-               return 0;
-
        if (!strcmp(argv[0], "clear")) {
                rerere_clear(&merge_rr);
        } else if (!strcmp(argv[0], "gc"))
                rerere_gc(&merge_rr);
-       else if (!strcmp(argv[0], "status"))
+       else if (!strcmp(argv[0], "status")) {
+               if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
+                       return 0;
                for (i = 0; i < merge_rr.nr; i++)
                        printf("%s\n", merge_rr.items[i].string);
-       else if (!strcmp(argv[0], "remaining")) {
+       else if (!strcmp(argv[0], "remaining")) {
                rerere_remaining(&merge_rr);
                for (i = 0; i < merge_rr.nr; i++) {
                        if (merge_rr.items[i].util != RERERE_RESOLVED)
@@ -100,13 +98,15 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
                                 * string_list_clear() */
                                merge_rr.items[i].util = NULL;
                }
-       } else if (!strcmp(argv[0], "diff"))
+       } else if (!strcmp(argv[0], "diff")) {
+               if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
+                       return 0;
                for (i = 0; i < merge_rr.nr; i++) {
                        const char *path = merge_rr.items[i].string;
                        const struct rerere_id *id = merge_rr.items[i].util;
                        diff_two(rerere_path(id, "preimage"), path, path, path);
                }
-       else
+       else
                usage_with_options(rerere_usage, options);
 
        string_list_clear(&merge_rr, 1);