Merge branch 'dk/gc-idx-wo-pack' into maint
[gitweb.git] / merge-recursive.c
index 771f5e21b09aac6976297b8a6e9028f90787a764..b446df9c1da0db2e21918f188b85536960d306f2 100644 (file)
@@ -611,7 +611,6 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
 {
        struct strbuf newpath = STRBUF_INIT;
        int suffix = 0;
-       struct stat st;
        size_t base_len;
 
        strbuf_addf(&newpath, "%s~", path);
@@ -620,7 +619,7 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
        base_len = newpath.len;
        while (string_list_has_string(&o->current_file_set, newpath.buf) ||
               string_list_has_string(&o->current_directory_set, newpath.buf) ||
-              lstat(newpath.buf, &st) == 0) {
+              file_exists(newpath.buf)) {
                strbuf_setlen(&newpath, base_len);
                strbuf_addf(&newpath, "_%d", suffix++);
        }
@@ -1532,13 +1531,17 @@ static int read_sha1_strbuf(const unsigned char *sha1, struct strbuf *dst)
 }
 
 static int blob_unchanged(const unsigned char *o_sha,
+                         unsigned o_mode,
                          const unsigned char *a_sha,
+                         unsigned a_mode,
                          int renormalize, const char *path)
 {
        struct strbuf o = STRBUF_INIT;
        struct strbuf a = STRBUF_INIT;
        int ret = 0; /* assume changed for safety */
 
+       if (a_mode != o_mode)
+               return 0;
        if (sha_eq(o_sha, a_sha))
                return 1;
        if (!renormalize)
@@ -1724,8 +1727,8 @@ static int process_entry(struct merge_options *o,
        } else if (o_sha && (!a_sha || !b_sha)) {
                /* Case A: Deleted in one */
                if ((!a_sha && !b_sha) ||
-                   (!b_sha && blob_unchanged(o_sha, a_sha, normalize, path)) ||
-                   (!a_sha && blob_unchanged(o_sha, b_sha, normalize, path))) {
+                   (!b_sha && blob_unchanged(o_sha, o_mode, a_sha, a_mode, normalize, path)) ||
+                   (!a_sha && blob_unchanged(o_sha, o_mode, b_sha, b_mode, normalize, path))) {
                        /* Deleted in both or deleted in one and
                         * unchanged in the other */
                        if (a_sha)
@@ -1858,6 +1861,9 @@ int merge_trees(struct merge_options *o,
                string_list_clear(re_head, 0);
                string_list_clear(entries, 1);
 
+               free(re_merge);
+               free(re_head);
+               free(entries);
        }
        else
                clean = 1;