]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-rerere.c
GIT-VERSION-FILE: check ./version first.
[thirdparty/git.git] / builtin-rerere.c
index d064bd8bf0218feb7d4ad01b39be6a143757499e..318d959d89669f09e12b1b97ca62f100e1a58ecd 100644 (file)
@@ -51,9 +51,11 @@ static int write_rr(struct path_list *rr, int out_fd)
        int i;
        for (i = 0; i < rr->nr; i++) {
                const char *path = rr->items[i].path;
-               write(out_fd, rr->items[i].util, 40);
-               write(out_fd, "\t", 1);
-               write(out_fd, path, strlen(path) + 1);
+               int length = strlen(path) + 1;
+               if (write_in_full(out_fd, rr->items[i].util, 40) != 40 ||
+                   write_in_full(out_fd, "\t", 1) != 1 ||
+                   write_in_full(out_fd, path, length) != length)
+                       die("unable to write rerere record");
        }
        close(out_fd);
        return commit_lock_file(&write_lock);
@@ -244,7 +246,8 @@ static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
 {
        int i;
        for (i = 0; i < nbuf; i++)
-               write(1, ptr[i].ptr, ptr[i].size);
+               if (write_in_full(1, ptr[i].ptr, ptr[i].size) != ptr[i].size)
+                       return -1;
        return 0;
 }
 
@@ -350,11 +353,10 @@ static int do_plain_rerere(struct path_list *rr, int fd)
                fprintf(stderr, "Recorded resolution for '%s'.\n", path);
                copy_file(path, rr_path(name, "postimage"));
 tail_optimization:
-               if (i < rr->nr - 1) {
+               if (i < rr->nr - 1)
                        memmove(rr->items + i,
-                                       rr->items + i + 1,
-                                       rr->nr - i - 1);
-               }
+                               rr->items + i + 1,
+                               sizeof(rr->items[0]) * (rr->nr - i - 1));
                rr->nr--;
                i--;
        }
@@ -362,6 +364,17 @@ tail_optimization:
        return write_rr(rr, fd);
 }
 
+static int git_rerere_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "gc.rerereresolved"))
+               cutoff_resolve = git_config_int(var, value);
+       else if (!strcmp(var, "gc.rerereunresolved"))
+               cutoff_noresolve = git_config_int(var, value);
+       else
+               return git_default_config(var, value);
+       return 0;
+}
+
 int cmd_rerere(int argc, const char **argv, const char *prefix)
 {
        struct path_list merge_rr = { NULL, 0, 0, 1 };
@@ -371,6 +384,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
        if (stat(git_path("rr-cache"), &st) || !S_ISDIR(st.st_mode))
                return 0;
 
+       git_config(git_rerere_config);
+
        merge_rr_path = xstrdup(git_path("rr-cache/MERGE_RR"));
        fd = hold_lock_file_for_update(&write_lock, merge_rr_path, 1);
        read_rr(&merge_rr);