{"thread":{"id":"8704","subject":"[PATCH] diffcore-rename: don't change similarity index based on basename equality","startedAt":"2007-06-24T22:23:28Z","lastAt":"2007-06-24T22:23:28Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"45706","messageId":"467EEEE0.5010203@lsrfire.ath.cx","threadId":"8704","inReplyTo":null,"subject":"[PATCH] diffcore-rename: don't change similarity index based on basename equality","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2007-06-24T22:23:28Z","receivedAt":"2007-06-24T22:23:28Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"This implements a suggestion from Johannes.  It uses a separate field in\nstruct diff_score to keep the result of the file name comparison in the\nrename detection logic.  This reverts the value of the similarity index\nto be a function of file contents, only, and basename comparison is only\nused to decide between files with equal amounts of content changes.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n\n diffcore-rename.c |   11 +++++++----\n 1 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 79c984c..e0a89f3 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -138,6 +138,7 @@ struct diff_score {\n \tint src; /* index in rename_src */\n \tint dst; /* index in rename_dst */\n \tint score;\n+\tint name_score;\n };\n \n static int estimate_similarity(struct diff_filespec *src,\n@@ -201,11 +202,8 @@ static int estimate_similarity(struct diff_filespec *src,\n \t */\n \tif (!dst->size)\n \t\tscore = 0; /* should not happen */\n-\telse {\n+\telse\n \t\tscore = (int)(src_copied * MAX_SCORE / max_size);\n-\t\tif (basename_same(src, dst))\n-\t\t\tscore++;\n-\t}\n \treturn score;\n }\n \n@@ -242,6 +240,10 @@ static void record_rename_pair(int dst_index, int src_index, int score)\n static int score_compare(const void *a_, const void *b_)\n {\n \tconst struct diff_score *a = a_, *b = b_;\n+\n+\tif (a->score == b->score)\n+\t\treturn b->name_score - a->name_score;\n+\n \treturn b->score - a->score;\n }\n \n@@ -360,6 +362,7 @@ void diffcore_rename(struct diff_options *options)\n \t\t\tm->dst = i;\n \t\t\tm->score = estimate_similarity(one, two,\n \t\t\t\t\t\t       minimum_score);\n+\t\t\tm->name_score = basename_same(one, two);\n \t\t\tdiff_free_filespec_data(one);\n \t\t}\n \t\t/* We do not need the text anymore */\n"}]}