Code

Merge branch 'kb/checkout-optim'
[git.git] / builtin-rerere.c
index 580580502cc0d84400edca8e2bda5ce607b43b58..020af7377bb9aa1bced7489d40169e3cb2ff7682 100644 (file)
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
-#include "path-list.h"
+#include "dir.h"
+#include "string-list.h"
 #include "rerere.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
@@ -12,28 +13,17 @@ static const char git_rerere_usage[] =
 static int cutoff_noresolve = 15;
 static int cutoff_resolve = 60;
 
-static const char *rr_path(const char *name, const char *file)
-{
-       return git_path("rr-cache/%s/%s", name, file);
-}
-
 static time_t rerere_created_at(const char *name)
 {
        struct stat st;
-       return stat(rr_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
-}
-
-static int has_resolution(const char *name)
-{
-       struct stat st;
-       return !stat(rr_path(name, "postimage"), &st);
+       return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
 }
 
 static void unlink_rr_item(const char *name)
 {
-       unlink(rr_path(name, "thisimage"));
-       unlink(rr_path(name, "preimage"));
-       unlink(rr_path(name, "postimage"));
+       unlink(rerere_path(name, "thisimage"));
+       unlink(rerere_path(name, "preimage"));
+       unlink(rerere_path(name, "postimage"));
        rmdir(git_path("rr-cache/%s", name));
 }
 
@@ -48,9 +38,9 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb)
        return 0;
 }
 
-static void garbage_collect(struct path_list *rr)
+static void garbage_collect(struct string_list *rr)
 {
-       struct path_list to_remove = { NULL, 0, 0, 1 };
+       struct string_list to_remove = { NULL, 0, 0, 1 };
        DIR *dir;
        struct dirent *e;
        int i, cutoff;
@@ -59,21 +49,19 @@ static void garbage_collect(struct path_list *rr)
        git_config(git_rerere_gc_config, NULL);
        dir = opendir(git_path("rr-cache"));
        while ((e = readdir(dir))) {
-               const char *name = e->d_name;
-               if (name[0] == '.' &&
-                   (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))
+               if (is_dot_or_dotdot(e->d_name))
                        continue;
-               then = rerere_created_at(name);
+               then = rerere_created_at(e->d_name);
                if (!then)
                        continue;
-               cutoff = (has_resolution(name)
+               cutoff = (has_rerere_resolution(e->d_name)
                          ? cutoff_resolve : cutoff_noresolve);
                if (then < now - cutoff * 86400)
-                       path_list_append(name, &to_remove);
+                       string_list_append(e->d_name, &to_remove);
        }
        for (i = 0; i < to_remove.nr; i++)
-               unlink_rr_item(to_remove.items[i].path);
-       path_list_clear(&to_remove, 0);
+               unlink_rr_item(to_remove.items[i].string);
+       string_list_clear(&to_remove, 0);
 }
 
 static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
@@ -98,6 +86,7 @@ static int diff_two(const char *file1, const char *label1,
 
        printf("--- a/%s\n+++ b/%s\n", label1, label2);
        fflush(stdout);
+       memset(&xpp, 0, sizeof(xpp));
        xpp.flags = XDF_NEED_MINIMAL;
        memset(&xecfg, 0, sizeof(xecfg));
        xecfg.ctxlen = 3;
@@ -111,7 +100,7 @@ static int diff_two(const char *file1, const char *label1,
 
 int cmd_rerere(int argc, const char **argv, const char *prefix)
 {
-       struct path_list merge_rr = { NULL, 0, 0, 1 };
+       struct string_list merge_rr = { NULL, 0, 0, 1 };
        int i, fd;
 
        if (argc < 2)
@@ -124,7 +113,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
        if (!strcmp(argv[1], "clear")) {
                for (i = 0; i < merge_rr.nr; i++) {
                        const char *name = (const char *)merge_rr.items[i].util;
-                       if (!has_resolution(name))
+                       if (!has_rerere_resolution(name))
                                unlink_rr_item(name);
                }
                unlink(git_path("rr-cache/MERGE_RR"));
@@ -132,16 +121,16 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
                garbage_collect(&merge_rr);
        else if (!strcmp(argv[1], "status"))
                for (i = 0; i < merge_rr.nr; i++)
-                       printf("%s\n", merge_rr.items[i].path);
+                       printf("%s\n", merge_rr.items[i].string);
        else if (!strcmp(argv[1], "diff"))
                for (i = 0; i < merge_rr.nr; i++) {
-                       const char *path = merge_rr.items[i].path;
+                       const char *path = merge_rr.items[i].string;
                        const char *name = (const char *)merge_rr.items[i].util;
-                       diff_two(rr_path(name, "preimage"), path, path, path);
+                       diff_two(rerere_path(name, "preimage"), path, path, path);
                }
        else
                usage(git_rerere_usage);
 
-       path_list_clear(&merge_rr, 1);
+       string_list_clear(&merge_rr, 1);
        return 0;
 }