Skip to content

Commit 86b41b3

Browse files
newrengitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d509802 commit 86b41b3

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
@@ -2371,6 +2371,53 @@ static void resolve_diffpair_statuses(struct diff_queue_struct *q)
23712371
}
23722372
}
23732373

2374+
MAYBE_UNUSED
2375+
static void prune_cached_from_relevant(struct rename_info *renames,
2376+
unsigned side)
2377+
{
2378+
/* Reason for this function described in add_pair() */
2379+
struct hashmap_iter iter;
2380+
struct strmap_entry *entry;
2381+
2382+
/* Remove from relevant_sources all entries in cached_pairs[side] */
2383+
strmap_for_each_entry(&renames->cached_pairs[side], &iter, entry) {
2384+
strintmap_remove(&renames->relevant_sources[side],
2385+
entry->key);
2386+
}
2387+
/* Remove from relevant_sources all entries in cached_irrelevant[side] */
2388+
strset_for_each_entry(&renames->cached_irrelevant[side], &iter, entry) {
2389+
strintmap_remove(&renames->relevant_sources[side],
2390+
entry->key);
2391+
}
2392+
}
2393+
2394+
MAYBE_UNUSED
2395+
static void use_cached_pairs(struct merge_options *opt,
2396+
struct strmap *cached_pairs,
2397+
struct diff_queue_struct *pairs)
2398+
{
2399+
struct hashmap_iter iter;
2400+
struct strmap_entry *entry;
2401+
2402+
/*
2403+
* Add to side_pairs all entries from renames->cached_pairs[side_index].
2404+
* (Info in cached_irrelevant[side_index] is not relevant here.)
2405+
*/
2406+
strmap_for_each_entry(cached_pairs, &iter, entry) {
2407+
struct diff_filespec *one, *two;
2408+
const char *old_name = entry->key;
2409+
const char *new_name = entry->value;
2410+
if (!new_name)
2411+
new_name = old_name;
2412+
2413+
/* We don't care about oid/mode, only filenames and status */
2414+
one = alloc_filespec(old_name);
2415+
two = alloc_filespec(new_name);
2416+
diff_queue(pairs, one, two);
2417+
pairs->queue[pairs->nr-1]->status = entry->value ? 'R' : 'D';
2418+
}
2419+
}
2420+
23742421
static void cache_new_pair(struct rename_info *renames,
23752422
int side,
23762423
char *old_path,

0 commit comments

Comments
 (0)