worktree: add 'list' command
[gitweb.git] / builtin / rerere.c
index 7afadd2eadd59d8d3f4b77ad902bc24c94af9ec6..12535c9b4f48cd196943c1914fefee7c47cecec2 100644 (file)
@@ -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 char *name = (const char *)merge_rr.items[i].util;
                        diff_two(rerere_path(name, "preimage"), path, path, path);
                }
-       else
+       else
                usage_with_options(rerere_usage, options);
 
        string_list_clear(&merge_rr, 1);