зеркало из https://github.com/microsoft/git.git
diffcore-rename.c: move code around to prepare for the next patch
No actual code changes, just move hash_filespec up and outdent part of find_identical_files. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
29d8a834b5
Коммит
48f6407ffe
|
@ -248,6 +248,18 @@ struct file_similarity {
|
|||
struct file_similarity *next;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int find_identical_files(struct file_similarity *src,
|
||||
struct file_similarity *dst,
|
||||
struct diff_options *options)
|
||||
|
@ -258,46 +270,46 @@ static int find_identical_files(struct file_similarity *src,
|
|||
* Walk over all the destinations ...
|
||||
*/
|
||||
do {
|
||||
struct diff_filespec *target = dst->filespec;
|
||||
struct file_similarity *p, *best;
|
||||
int i = 100, best_score = -1;
|
||||
struct diff_filespec *target = dst->filespec;
|
||||
struct file_similarity *p, *best;
|
||||
int i = 100, best_score = -1;
|
||||
|
||||
/*
|
||||
* .. to find the best source match
|
||||
*/
|
||||
best = NULL;
|
||||
for (p = src; p; p = p->next) {
|
||||
int score;
|
||||
struct diff_filespec *source = p->filespec;
|
||||
/*
|
||||
* .. to find the best source match
|
||||
*/
|
||||
best = NULL;
|
||||
for (p = src; p; p = p->next) {
|
||||
int score;
|
||||
struct diff_filespec *source = p->filespec;
|
||||
|
||||
/* False hash collision? */
|
||||
if (hashcmp(source->sha1, target->sha1))
|
||||
/* False hash collision? */
|
||||
if (hashcmp(source->sha1, target->sha1))
|
||||
continue;
|
||||
/* Non-regular files? If so, the modes must match! */
|
||||
if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
|
||||
if (source->mode != target->mode)
|
||||
continue;
|
||||
/* Non-regular files? If so, the modes must match! */
|
||||
if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
|
||||
if (source->mode != target->mode)
|
||||
continue;
|
||||
}
|
||||
/* Give higher scores to sources that haven't been used already */
|
||||
score = !source->rename_used;
|
||||
if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
|
||||
continue;
|
||||
score += basename_same(source, target);
|
||||
if (score > best_score) {
|
||||
best = p;
|
||||
best_score = score;
|
||||
if (score == 2)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Too many identical alternatives? Pick one */
|
||||
if (!--i)
|
||||
}
|
||||
/* Give higher scores to sources that haven't been used already */
|
||||
score = !source->rename_used;
|
||||
if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
|
||||
continue;
|
||||
score += basename_same(source, target);
|
||||
if (score > best_score) {
|
||||
best = p;
|
||||
best_score = score;
|
||||
if (score == 2)
|
||||
break;
|
||||
}
|
||||
if (best) {
|
||||
record_rename_pair(dst->index, best->index, MAX_SCORE);
|
||||
renames++;
|
||||
}
|
||||
|
||||
/* Too many identical alternatives? Pick one */
|
||||
if (!--i)
|
||||
break;
|
||||
}
|
||||
if (best) {
|
||||
record_rename_pair(dst->index, best->index, MAX_SCORE);
|
||||
renames++;
|
||||
}
|
||||
} while ((dst = dst->next) != NULL);
|
||||
return renames;
|
||||
}
|
||||
|
@ -343,18 +355,6 @@ static int find_same_files(void *ptr, void *data)
|
|||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void insert_file_table(struct hash_table *table, int src_dst, int index, struct diff_filespec *filespec)
|
||||
{
|
||||
void **pos;
|
||||
|
|
Загрузка…
Ссылка в новой задаче