Merge branch 'sg/diff-multiple-identical-renames' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 29 Apr 2016 21:15:55 +0000 (14:15 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Apr 2016 21:15:55 +0000 (14:15 -0700)
"git diff -M" used to work better when two originally identical
files A and B got renamed to X/A and X/B by pairing A to X/A and B
to X/B, but this was broken in the 2.0 timeframe.

* sg/diff-multiple-identical-renames:
diffcore: fix iteration order of identical files during rename detection

1  2 
diffcore-rename.c
diff --combined diffcore-rename.c
index 3b3c1ed535e7c8b17947d69dbe0bd5c8f115cf2d,69fcf77be02df4160dfaa04380d0a262b9d4aa02..7f03eb5a0404d4b44f292fba76433dfec74dcd44
@@@ -340,9 -340,11 +340,11 @@@ static int find_exact_renames(struct di
        int i, renames = 0;
        struct hashmap file_table;
  
-       /* Add all sources to the hash table */
+       /* Add all sources to the hash table in reverse order, because
+        * later on they will be retrieved in LIFO order.
+        */
        hashmap_init(&file_table, NULL, rename_src_nr);
-       for (i = 0; i < rename_src_nr; i++)
+       for (i = rename_src_nr-1; i >= 0; i--)
                insert_file_table(&file_table, i, rename_src[i].p->one);
  
        /* Walk the destinations and find best source match */
@@@ -537,7 -539,7 +539,7 @@@ void diffcore_rename(struct diff_option
                                rename_dst_nr * rename_src_nr, 50, 1);
        }
  
 -      mx = xcalloc(num_create * NUM_CANDIDATE_PER_DST, sizeof(*mx));
 +      mx = xcalloc(st_mult(num_create, NUM_CANDIDATE_PER_DST), sizeof(*mx));
        for (dst_cnt = i = 0; i < rename_dst_nr; i++) {
                struct diff_filespec *two = rename_dst[i].two;
                struct diff_score *m;