Skip to content

Commit ae1db7b

Browse files
newrengitster
authored andcommitted
diffcore-rename: take advantage of "majority rules" to skip more renames
In directory rename detection (when a directory is removed on one side of history and the other side adds new files to that directory), we work to find where the greatest number of files within that directory were renamed to so that the new files can be moved with the majority of the files. Naively, we can just do this by detecting renames for *all* files within the removed/renamed directory, looking at all the destination directories where files within that directory were moved, and if there is more than one such directory then taking the one with the greatest number of files as the directory where the old directory was renamed to. However, sometimes there are enough renames from exact rename detection or basename-guided rename detection that we have enough information to determine the majority winner already. Add a function meant to compute whether particular renames are still needed based on this majority rules check. The next several commits will then add the necessary infrastructure to get the information we need to compute which additional rename sources we can skip. An important side note for future further optimization: There is a possible improvement to this optimization that I have not yet attempted and will not be included in this series of patches: we could first check whether exact renames provide enough information for us to determine directory renames, and avoid doing basename-guided rename detection on some or all of the RELEVANT_LOCATION files within those directories. In effect, this variant would mean doing the handle_early_known_dir_renames() both after exact rename detection and again after basename-guided rename detection, though it would also mean decrementing the number of "unknown" renames for each rename we found from basename-guided rename detection. Adding this additional check for skippable renames right after exact rename detection might turn out to be valuable, especially for partial clones where it might allow us to download certain source files entirely. However, this particular optimization was actually the last one I did in original implementation order, and by the time I implemented this idea, every testcase I had was sufficiently fast that further optimization was unwarranted. If future testcases arise that tax rename detection more heavily (or perhaps partial clones can benefit from avoiding loading more objects), it may be worth implementing this more involved variant. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4fd06e commit ae1db7b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

diffcore-rename.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,24 @@ static void remove_unneeded_paths_from_src(int detecting_copies,
10731073
rename_src_nr = new_num_src;
10741074
}
10751075

1076+
static void handle_early_known_dir_renames(struct dir_rename_info *info,
1077+
struct strset *relevant_sources,
1078+
struct strset *dirs_removed)
1079+
{
1080+
/*
1081+
* Not yet implemented; directory renames are determined via an
1082+
* aggregate of all renames under them and using a "majority wins"
1083+
* rule. The fact that "majority wins", though, means we don't need
1084+
* all the renames under the given directory, we only need enough to
1085+
* ensure we have a majority.
1086+
*
1087+
* For now, we don't have enough information to know if we have a
1088+
* majority after exact renames and basename-guided rename detection,
1089+
* so just return early without doing any extra filtering.
1090+
*/
1091+
return;
1092+
}
1093+
10761094
void diffcore_rename_extended(struct diff_options *options,
10771095
struct strset *relevant_sources,
10781096
struct strset *dirs_removed,
@@ -1208,9 +1226,16 @@ void diffcore_rename_extended(struct diff_options *options,
12081226
* Cull sources, again:
12091227
* - remove ones involved in renames (found via basenames)
12101228
* - remove ones not found in relevant_sources
1229+
* and
1230+
* - remove ones in relevant_sources which are needed only
1231+
* for directory renames IF no ancestory directory
1232+
* actually needs to know any more individual path
1233+
* renames under them
12111234
*/
12121235
trace2_region_enter("diff", "cull basename", options->repo);
12131236
remove_unneeded_paths_from_src(want_copies, relevant_sources);
1237+
handle_early_known_dir_renames(&info, relevant_sources,
1238+
dirs_removed);
12141239
trace2_region_leave("diff", "cull basename", options->repo);
12151240
}
12161241

0 commit comments

Comments
 (0)