Merge branch 'lt/rename-no-extra-copy-detection'
* lt/rename-no-extra-copy-detection: diffcore-rename: improve estimate_similarity() heuristics diffcore-rename: properly honor the difference between -M and -C for_each_hash: allow passing a 'void *data' pointer to callback
This commit is contained in:
commit
24161eb036
@ -63,7 +63,7 @@ static inline struct commit_name *find_commit_name(const unsigned char *peeled)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_util(void *chain)
|
static int set_util(void *chain, void *data)
|
||||||
{
|
{
|
||||||
struct commit_name *n;
|
struct commit_name *n;
|
||||||
for (n = chain; n; n = n->next) {
|
for (n = chain; n; n = n->next) {
|
||||||
@ -289,7 +289,7 @@ static void describe(const char *arg, int last_one)
|
|||||||
fprintf(stderr, "searching to describe %s\n", arg);
|
fprintf(stderr, "searching to describe %s\n", arg);
|
||||||
|
|
||||||
if (!have_util) {
|
if (!have_util) {
|
||||||
for_each_hash(&names, set_util);
|
for_each_hash(&names, set_util, NULL);
|
||||||
have_util = 1;
|
have_util = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ static int estimate_similarity(struct diff_filespec *src,
|
|||||||
* and the final score computation below would not have a
|
* and the final score computation below would not have a
|
||||||
* divide-by-zero issue.
|
* divide-by-zero issue.
|
||||||
*/
|
*/
|
||||||
if (base_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE)
|
if (max_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!src->cnt_data && diff_populate_filespec(src, 0))
|
if (!src->cnt_data && diff_populate_filespec(src, 0))
|
||||||
@ -247,7 +247,8 @@ struct file_similarity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int find_identical_files(struct file_similarity *src,
|
static int find_identical_files(struct file_similarity *src,
|
||||||
struct file_similarity *dst)
|
struct file_similarity *dst,
|
||||||
|
struct diff_options *options)
|
||||||
{
|
{
|
||||||
int renames = 0;
|
int renames = 0;
|
||||||
|
|
||||||
@ -277,6 +278,8 @@ static int find_identical_files(struct file_similarity *src,
|
|||||||
}
|
}
|
||||||
/* Give higher scores to sources that haven't been used already */
|
/* Give higher scores to sources that haven't been used already */
|
||||||
score = !source->rename_used;
|
score = !source->rename_used;
|
||||||
|
if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
|
||||||
|
continue;
|
||||||
score += basename_same(source, target);
|
score += basename_same(source, target);
|
||||||
if (score > best_score) {
|
if (score > best_score) {
|
||||||
best = p;
|
best = p;
|
||||||
@ -306,11 +309,12 @@ static void free_similarity_list(struct file_similarity *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_same_files(void *ptr)
|
static int find_same_files(void *ptr, void *data)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct file_similarity *p = ptr;
|
struct file_similarity *p = ptr;
|
||||||
struct file_similarity *src = NULL, *dst = NULL;
|
struct file_similarity *src = NULL, *dst = NULL;
|
||||||
|
struct diff_options *options = data;
|
||||||
|
|
||||||
/* Split the hash list up into sources and destinations */
|
/* Split the hash list up into sources and destinations */
|
||||||
do {
|
do {
|
||||||
@ -329,7 +333,7 @@ static int find_same_files(void *ptr)
|
|||||||
* If we have both sources *and* destinations, see if
|
* If we have both sources *and* destinations, see if
|
||||||
* we can match them up
|
* we can match them up
|
||||||
*/
|
*/
|
||||||
ret = (src && dst) ? find_identical_files(src, dst) : 0;
|
ret = (src && dst) ? find_identical_files(src, dst, options) : 0;
|
||||||
|
|
||||||
/* Free the hashes and return the number of renames found */
|
/* Free the hashes and return the number of renames found */
|
||||||
free_similarity_list(src);
|
free_similarity_list(src);
|
||||||
@ -377,7 +381,7 @@ static void insert_file_table(struct hash_table *table, int src_dst, int index,
|
|||||||
* and then during the second round we try to match
|
* and then during the second round we try to match
|
||||||
* cache-dirty entries as well.
|
* cache-dirty entries as well.
|
||||||
*/
|
*/
|
||||||
static int find_exact_renames(void)
|
static int find_exact_renames(struct diff_options *options)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct hash_table file_table;
|
struct hash_table file_table;
|
||||||
@ -390,7 +394,7 @@ static int find_exact_renames(void)
|
|||||||
insert_file_table(&file_table, 1, i, rename_dst[i].two);
|
insert_file_table(&file_table, 1, i, rename_dst[i].two);
|
||||||
|
|
||||||
/* Find the renames */
|
/* Find the renames */
|
||||||
i = for_each_hash(&file_table, find_same_files);
|
i = for_each_hash(&file_table, find_same_files, options);
|
||||||
|
|
||||||
/* .. and free the hash data structure */
|
/* .. and free the hash data structure */
|
||||||
free_hash(&file_table);
|
free_hash(&file_table);
|
||||||
@ -414,6 +418,27 @@ static void record_if_better(struct diff_score m[], struct diff_score *o)
|
|||||||
m[worst] = *o;
|
m[worst] = *o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int find_renames(struct diff_score *mx, int dst_cnt, int minimum_score, int copies)
|
||||||
|
{
|
||||||
|
int count = 0, i;
|
||||||
|
|
||||||
|
for (i = 0; i < dst_cnt * NUM_CANDIDATE_PER_DST; i++) {
|
||||||
|
struct diff_rename_dst *dst;
|
||||||
|
|
||||||
|
if ((mx[i].dst < 0) ||
|
||||||
|
(mx[i].score < minimum_score))
|
||||||
|
break; /* there is no more usable pair. */
|
||||||
|
dst = &rename_dst[mx[i].dst];
|
||||||
|
if (dst->pair)
|
||||||
|
continue; /* already done, either exact or fuzzy. */
|
||||||
|
if (!copies && rename_src[mx[i].src].one->rename_used)
|
||||||
|
continue;
|
||||||
|
record_rename_pair(mx[i].dst, mx[i].src, mx[i].score);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
void diffcore_rename(struct diff_options *options)
|
void diffcore_rename(struct diff_options *options)
|
||||||
{
|
{
|
||||||
int detect_rename = options->detect_rename;
|
int detect_rename = options->detect_rename;
|
||||||
@ -467,7 +492,7 @@ void diffcore_rename(struct diff_options *options)
|
|||||||
* We really want to cull the candidates list early
|
* We really want to cull the candidates list early
|
||||||
* with cheap tests in order to avoid doing deltas.
|
* with cheap tests in order to avoid doing deltas.
|
||||||
*/
|
*/
|
||||||
rename_count = find_exact_renames();
|
rename_count = find_exact_renames(options);
|
||||||
|
|
||||||
/* Did we only want exact renames? */
|
/* Did we only want exact renames? */
|
||||||
if (minimum_score == MAX_SCORE)
|
if (minimum_score == MAX_SCORE)
|
||||||
@ -536,33 +561,9 @@ void diffcore_rename(struct diff_options *options)
|
|||||||
/* cost matrix sorted by most to least similar pair */
|
/* cost matrix sorted by most to least similar pair */
|
||||||
qsort(mx, dst_cnt * NUM_CANDIDATE_PER_DST, sizeof(*mx), score_compare);
|
qsort(mx, dst_cnt * NUM_CANDIDATE_PER_DST, sizeof(*mx), score_compare);
|
||||||
|
|
||||||
for (i = 0; i < dst_cnt * NUM_CANDIDATE_PER_DST; i++) {
|
rename_count += find_renames(mx, dst_cnt, minimum_score, 0);
|
||||||
struct diff_rename_dst *dst;
|
if (detect_rename == DIFF_DETECT_COPY)
|
||||||
|
rename_count += find_renames(mx, dst_cnt, minimum_score, 1);
|
||||||
if ((mx[i].dst < 0) ||
|
|
||||||
(mx[i].score < minimum_score))
|
|
||||||
break; /* there is no more usable pair. */
|
|
||||||
dst = &rename_dst[mx[i].dst];
|
|
||||||
if (dst->pair)
|
|
||||||
continue; /* already done, either exact or fuzzy. */
|
|
||||||
if (rename_src[mx[i].src].one->rename_used)
|
|
||||||
continue;
|
|
||||||
record_rename_pair(mx[i].dst, mx[i].src, mx[i].score);
|
|
||||||
rename_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < dst_cnt * NUM_CANDIDATE_PER_DST; i++) {
|
|
||||||
struct diff_rename_dst *dst;
|
|
||||||
|
|
||||||
if ((mx[i].dst < 0) ||
|
|
||||||
(mx[i].score < minimum_score))
|
|
||||||
break; /* there is no more usable pair. */
|
|
||||||
dst = &rename_dst[mx[i].dst];
|
|
||||||
if (dst->pair)
|
|
||||||
continue; /* already done, either exact or fuzzy. */
|
|
||||||
record_rename_pair(mx[i].dst, mx[i].src, mx[i].score);
|
|
||||||
rename_count++;
|
|
||||||
}
|
|
||||||
free(mx);
|
free(mx);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
4
hash.c
4
hash.c
@ -81,7 +81,7 @@ void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table)
|
|||||||
return insert_hash_entry(hash, ptr, table);
|
return insert_hash_entry(hash, ptr, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
int for_each_hash(const struct hash_table *table, int (*fn)(void *))
|
int for_each_hash(const struct hash_table *table, int (*fn)(void *, void *), void *data)
|
||||||
{
|
{
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -92,7 +92,7 @@ int for_each_hash(const struct hash_table *table, int (*fn)(void *))
|
|||||||
void *ptr = array->ptr;
|
void *ptr = array->ptr;
|
||||||
array++;
|
array++;
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
int val = fn(ptr);
|
int val = fn(ptr, data);
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
return val;
|
return val;
|
||||||
sum += val;
|
sum += val;
|
||||||
|
2
hash.h
2
hash.h
@ -30,7 +30,7 @@ struct hash_table {
|
|||||||
|
|
||||||
extern void *lookup_hash(unsigned int hash, const struct hash_table *table);
|
extern void *lookup_hash(unsigned int hash, const struct hash_table *table);
|
||||||
extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table);
|
extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table);
|
||||||
extern int for_each_hash(const struct hash_table *table, int (*fn)(void *));
|
extern int for_each_hash(const struct hash_table *table, int (*fn)(void *, void *), void *data);
|
||||||
extern void free_hash(struct hash_table *table);
|
extern void free_hash(struct hash_table *table);
|
||||||
|
|
||||||
static inline void init_hash(struct hash_table *table)
|
static inline void init_hash(struct hash_table *table)
|
||||||
|
@ -29,7 +29,7 @@ test_expect_success \
|
|||||||
# copy-and-edit one, and rename-and-edit the other. We do not say
|
# copy-and-edit one, and rename-and-edit the other. We do not say
|
||||||
# anything about rezrov.
|
# anything about rezrov.
|
||||||
|
|
||||||
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current
|
GIT_DIFF_OPTS=--unified=0 git diff-index -C -p $tree >current
|
||||||
cat >expected <<\EOF
|
cat >expected <<\EOF
|
||||||
diff --git a/COPYING b/COPYING.1
|
diff --git a/COPYING b/COPYING.1
|
||||||
copy from COPYING
|
copy from COPYING
|
||||||
|
@ -35,7 +35,7 @@ test_expect_success SYMLINKS \
|
|||||||
# a new creation.
|
# a new creation.
|
||||||
|
|
||||||
test_expect_success SYMLINKS 'setup diff output' "
|
test_expect_success SYMLINKS 'setup diff output' "
|
||||||
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
|
GIT_DIFF_OPTS=--unified=0 git diff-index -C -p $tree >current &&
|
||||||
cat >expected <<\EOF
|
cat >expected <<\EOF
|
||||||
diff --git a/bozbar b/bozbar
|
diff --git a/bozbar b/bozbar
|
||||||
new file mode 120000
|
new file mode 120000
|
||||||
|
@ -29,7 +29,7 @@ test_expect_success \
|
|||||||
# and COPYING.2 are based on COPYING, and do not say anything about
|
# and COPYING.2 are based on COPYING, and do not say anything about
|
||||||
# rezrov.
|
# rezrov.
|
||||||
|
|
||||||
git diff-index -M $tree >current
|
git diff-index -C $tree >current
|
||||||
|
|
||||||
cat >expected <<\EOF
|
cat >expected <<\EOF
|
||||||
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
|
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
|
||||||
|
@ -173,8 +173,8 @@ test_expect_success \
|
|||||||
'compare_diff_raw expected current'
|
'compare_diff_raw expected current'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'run diff with -B -M' \
|
'run diff with -B -C' \
|
||||||
'git diff-index -B -M "$tree" >current'
|
'git diff-index -B -C "$tree" >current'
|
||||||
|
|
||||||
cat >expected <<\EOF
|
cat >expected <<\EOF
|
||||||
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1
|
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1
|
||||||
|
@ -29,7 +29,7 @@ test_expect_success \
|
|||||||
# and COPYING.2 are based on COPYING, and do not say anything about
|
# and COPYING.2 are based on COPYING, and do not say anything about
|
||||||
# rezrov.
|
# rezrov.
|
||||||
|
|
||||||
git diff-index -z -M $tree >current
|
git diff-index -z -C $tree >current
|
||||||
|
|
||||||
cat >expected <<\EOF
|
cat >expected <<\EOF
|
||||||
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234
|
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234
|
||||||
|
Loading…
Reference in New Issue
Block a user