git-p4: add failing test for P4EDITOR handling
[gitweb.git] / diffcore-rename.c
index 0afe903de9d300f36f12242ef89ea0d7c46aecbf..af1fe08861e6862985ac8fb9311b17568cb9e547 100644 (file)
@@ -163,9 +163,11 @@ static int estimate_similarity(struct diff_filespec *src,
         * is a possible size - we really should have a flag to
         * say whether the size is valid or not!)
         */
-       if (!src->cnt_data && diff_populate_filespec(src, 1))
+       if (!src->cnt_data &&
+           diff_populate_filespec(src, CHECK_SIZE_ONLY))
                return 0;
-       if (!dst->cnt_data && diff_populate_filespec(dst, 1))
+       if (!dst->cnt_data &&
+           diff_populate_filespec(dst, CHECK_SIZE_ONLY))
                return 0;
 
        max_size = ((src->size > dst->size) ? src->size : dst->size);
@@ -258,14 +260,12 @@ struct file_similarity {
 
 static unsigned int hash_filespec(struct diff_filespec *filespec)
 {
-       unsigned int hash;
        if (!filespec->sha1_valid) {
                if (diff_populate_filespec(filespec, 0))
                        return 0;
                hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
        }
-       memcpy(&hash, filespec->sha1, sizeof(hash));
-       return hash;
+       return sha1hash(filespec->sha1);
 }
 
 static int find_identical_files(struct hashmap *srcs,
@@ -275,15 +275,14 @@ static int find_identical_files(struct hashmap *srcs,
        int renames = 0;
 
        struct diff_filespec *target = rename_dst[dst_index].two;
-       struct file_similarity *p, *best, dst;
+       struct file_similarity *p, *best = NULL;
        int i = 100, best_score = -1;
 
        /*
         * Find the best source match for specified destination.
         */
-       best = NULL;
-       hashmap_entry_init(&dst, hash_filespec(target));
-       for (p = hashmap_get(srcs, &dst, NULL); p; p = hashmap_get_next(srcs, p)) {
+       p = hashmap_get_from_hash(srcs, hash_filespec(target), NULL);
+       for (; p; p = hashmap_get_next(srcs, p)) {
                int score;
                struct diff_filespec *source = p->filespec;
 
@@ -467,8 +466,12 @@ void diffcore_rename(struct diff_options *options)
                        else if (!DIFF_OPT_TST(options, RENAME_EMPTY) &&
                                 is_empty_blob_sha1(p->two->sha1))
                                continue;
-                       else
-                               add_rename_dst(p->two);
+                       else if (add_rename_dst(p->two) < 0) {
+                               warning("skipping rename detection, detected"
+                                       " duplicate destination '%s'",
+                                       p->two->path);
+                               goto cleanup;
+                       }
                }
                else if (!DIFF_OPT_TST(options, RENAME_EMPTY) &&
                         is_empty_blob_sha1(p->one->sha1))