Skip to content

Commit 9baa93b

Browse files
committed
merge-ort: add helper functions for using cached renames
If we have a usable rename cache, then we can remove from relevant_sources all the paths that were cached; diffcore_rename_extended() can then consider an even smaller set of relevant_sources in its rename detection. However, when diffcore_rename_extended() is done, we will need to take the renames it detected and then add back in all the ones we had cached from before. Add helper functions for doing these two operations; the next commit will make use of them. Signed-off-by: Elijah Newren <[email protected]>
1 parent 380ecb0 commit 9baa93b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

merge-ort.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,6 +2298,53 @@ static void resolve_diffpair_statuses(struct diff_queue_struct *q)
22982298
}
22992299
}
23002300

2301+
MAYBE_UNUSED
2302+
static void prune_cached_from_relevant(struct rename_info *renames,
2303+
unsigned side)
2304+
{
2305+
/* Reason for this function described in add_pair() */
2306+
struct hashmap_iter iter;
2307+
struct strmap_entry *entry;
2308+
2309+
/* Remove from relevant_sources all entries in cached_pairs[side] */
2310+
strmap_for_each_entry(&renames->cached_pairs[side], &iter, entry) {
2311+
strintmap_remove(&renames->relevant_sources[side],
2312+
entry->key);
2313+
}
2314+
/* Remove from relevant_sources all entries in cached_irrelevant[side] */
2315+
strset_for_each_entry(&renames->cached_irrelevant[side], &iter, entry) {
2316+
strintmap_remove(&renames->relevant_sources[side],
2317+
entry->key);
2318+
}
2319+
}
2320+
2321+
MAYBE_UNUSED
2322+
static void use_cached_pairs(struct merge_options *opt,
2323+
struct strmap *cached_pairs,
2324+
struct diff_queue_struct *pairs)
2325+
{
2326+
struct hashmap_iter iter;
2327+
struct strmap_entry *entry;
2328+
2329+
/*
2330+
* Add to side_pairs all entries from renames->cached_pairs[side_index].
2331+
* (Info in cached_irrelevant[side_index] is not relevant here.)
2332+
*/
2333+
strmap_for_each_entry(cached_pairs, &iter, entry) {
2334+
struct diff_filespec *one, *two;
2335+
const char *old_name = entry->key;
2336+
const char *new_name = entry->value;
2337+
if (!new_name)
2338+
new_name = old_name;
2339+
2340+
/* We don't care about oid/mode, only filenames and status */
2341+
one = alloc_filespec(old_name);
2342+
two = alloc_filespec(new_name);
2343+
diff_queue(pairs, one, two);
2344+
pairs->queue[pairs->nr-1]->status = entry->value ? 'R' : 'D';
2345+
}
2346+
}
2347+
23012348
static void possibly_cache_new_pair(struct rename_info *renames,
23022349
struct diff_filepair *p,
23032350
unsigned side,

0 commit comments

Comments
 (0)