merge-ort: record the reason that we want a rename for a file
There are two different reasons we might want a rename for a file -- for three-way content merging or as part of directory rename detection. Record the reason. diffcore-rename will potentially be able to filter some of the ones marked as needed only for directory rename detection, if it can determine those directory renames based solely on renames found via exact rename detection and basename-guided rename detection. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Mar 13, 2021 at 22:22 UTC
ec59da6015c457e84953a802fc6484ae2da2d774
2 files changed
+16
-5
diffcore.h
+6
@@ -167,6 +167,12 @@ enum dir_rename_relevance {
167
RELEVANT_FOR_ANCESTOR = 1,
168
RELEVANT_FOR_SELF = 2
169
};
170
+/* file_rename_relevance: the reason(s) we want rename information for a file */
171
+enum file_rename_relevance {
172
+ RELEVANT_NO_MORE = 0, /* i.e. NOT relevant */
173
+ RELEVANT_CONTENT = 1,
174
+ RELEVANT_LOCATION = 2
175
+};
176
177
void partial_clear_dir_rename_count(struct strmap *dir_rename_count);
178
merge-ort.c
+10
-5
@@ -99,16 +99,18 @@ struct rename_info {
99
struct strmap dir_renames[3];
100
101
/*
102
- * relevant_sources: deleted paths for which we need rename detection
102
+ * relevant_sources: deleted paths wanted in rename detection, and why
103
*
104
* relevant_sources is a set of deleted paths on each side of
105
* history for which we need rename detection. If a path is deleted
106
* on one side of history, we need to detect if it is part of a
107
* rename if either
108
- * * we need to detect renames for an ancestor directory
108
* * the file is modified/deleted on the other side of history
109
+ * * we need to detect renames for an ancestor directory
110
* If neither of those are true, we can skip rename detection for
111
- * that path.
111
+ * that path. The reason is stored as a value from enum
112
+ * file_rename_relevance, as the reason can inform the algorithm in
113
+ * diffcore_rename_extended().
114
*/
115
struct strintmap relevant_sources[3];
116
@@ -677,8 +679,11 @@ static void add_pair(struct merge_options *opt,
679
unsigned content_relevant = (match_mask == 0);
680
unsigned location_relevant = (dir_rename_mask == 0x07);
681
680
- if (content_relevant || location_relevant)
681
- strintmap_set(&renames->relevant_sources[side], pathname, 1);
682
+ if (content_relevant || location_relevant) {
683
+ /* content_relevant trumps location_relevant */
684
+ strintmap_set(&renames->relevant_sources[side], pathname,
685
+ content_relevant ? RELEVANT_CONTENT : RELEVANT_LOCATION);
686
+ }
687
}
688
689
one = alloc_filespec(pathname);