Skip to content

Commit 314a5d2

Browse files
committed
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; record the reason so that future patches to diffcore-rename can take it into account. Signed-off-by: Elijah Newren <[email protected]>
1 parent 854225e commit 314a5d2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

diffcore.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *,
161161
struct diff_filespec *);
162162
void diff_q(struct diff_queue_struct *, struct diff_filepair *);
163163

164+
/* file_rename_relevance: the reason(s) we want rename information for a file */
165+
enum file_rename_relevance {
166+
RELEVANT_NO_MORE = 0, /* i.e. NOT relevant */
167+
RELEVANT_CONTENT = 1,
168+
RELEVANT_LOCATION = 2
169+
};
164170
void partial_clear_dir_rename_count(struct strmap *dir_rename_count);
165171

166172
void diffcore_break(struct repository *, int);

merge-ort.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,18 @@ struct rename_info {
9595
struct strmap dir_renames[3];
9696

9797
/*
98-
* relevant_sources: deleted paths for which we need rename detection
98+
* relevant_sources: deleted paths wanted in rename detection, and why
9999
*
100100
* relevant_sources is a set of deleted paths on each side of
101101
* history for which we need rename detection. If a path is deleted
102102
* on one side of history, we need to detect if it is part of a
103103
* rename if either
104-
* * we need to detect renames for an ancestor directory
105104
* * the file is modified/deleted on the other side of history
105+
* * we need to detect renames for an ancestor directory
106106
* If neither of those are true, we can skip rename detection for
107-
* that path.
107+
* that path. The reason is stored as a value from enum
108+
* file_rename_relevance, as the reason can inform the algorithm in
109+
* diffcore_rename_extended().
108110
*/
109111
struct strintmap relevant_sources[3];
110112

@@ -674,8 +676,11 @@ static void add_pair(struct merge_options *opt,
674676
unsigned content_relevant = (match_mask == 0);
675677
unsigned location_relevant = (dir_rename_mask == 0x07);
676678

677-
if (content_relevant || location_relevant)
678-
strintmap_set(&renames->relevant_sources[side], pathname, 1);
679+
if (content_relevant || location_relevant) {
680+
/* content_relevant trumps location_relevant */
681+
strintmap_set(&renames->relevant_sources[side], pathname,
682+
content_relevant ? RELEVANT_CONTENT : RELEVANT_LOCATION);
683+
}
679684
}
680685

681686
one = alloc_filespec(pathname);

0 commit comments

Comments
 (0)