Skip to content

Commit baa8d7e

Browse files
committed
diffcore-rename: relevant_sources needed for location might be skippable
As noted a few commits ago, when a source file rename is used as part of directory rename detection, we need to increment counts for each ancestor directory in dirs_removed with value RELEVANT_FOR_SELF. However, due to the last commit, we may have downgraded all relevant ancestor directories from RELEVANT_FOR_SELF to RELEVANT_FOR_ANCESTOR. If no ancestor directory is found in dirs_removed with a value of RELEVANT_FOR_SELF, then we can downgrade relevant_source[PATH] from RELEVANT_LOCATION to RELEVANT_NO_MORE. This change does not yet affect things, as handle_early_known_dir_renames() has not yet been hooked into the code and called from anywhere. The next commit will change that. Signed-off-by: Elijah Newren <[email protected]>
1 parent a4f53cf commit baa8d7e

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

diffcore-rename.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ static void handle_early_known_dir_renames(struct dir_rename_info *info,
11211121
struct strintmap *relevant_sources,
11221122
struct strintmap *dirs_removed)
11231123
{
1124-
int i;
1124+
int i, new_num_src;
11251125
struct hashmap_iter iter;
11261126
struct strmap_entry *entry;
11271127

@@ -1171,6 +1171,55 @@ static void handle_early_known_dir_renames(struct dir_rename_info *info,
11711171
RELEVANT_FOR_ANCESTOR);
11721172
}
11731173
}
1174+
1175+
for (i = 0, new_num_src = 0; i < rename_src_nr; i++) {
1176+
struct diff_filespec *one = rename_src[i].p->one;
1177+
int val;
1178+
1179+
val = strintmap_get(relevant_sources, one->path);
1180+
1181+
/*
1182+
* sources that were not found in relevant_sources should
1183+
* have already been removed by a prior call to
1184+
* remove_unneeded_paths_from_src()
1185+
*/
1186+
assert(val != -1);
1187+
1188+
if (val == RELEVANT_LOCATION) {
1189+
int removable = 1;
1190+
char *dir = get_dirname(one->path);
1191+
while (1) {
1192+
char *freeme = dir;
1193+
int res = strintmap_get(dirs_removed, dir);
1194+
1195+
/* Quit if not found or irrelevant */
1196+
if (res == NOT_RELEVANT)
1197+
break;
1198+
/* If RELEVANT_FOR_SELF, can't remove */
1199+
if (res == RELEVANT_FOR_SELF) {
1200+
removable = 0;
1201+
break;
1202+
}
1203+
/* Else continue searching upwards */
1204+
assert(res == RELEVANT_FOR_ANCESTOR);
1205+
dir = get_dirname(dir);
1206+
free(freeme);
1207+
}
1208+
free(dir);
1209+
if (removable) {
1210+
strintmap_set(relevant_sources, one->path,
1211+
RELEVANT_NO_MORE);
1212+
continue;
1213+
}
1214+
}
1215+
1216+
if (new_num_src < i)
1217+
memcpy(&rename_src[new_num_src], &rename_src[i],
1218+
sizeof(struct diff_rename_src));
1219+
new_num_src++;
1220+
}
1221+
1222+
rename_src_nr = new_num_src;
11741223
}
11751224

11761225
void diffcore_rename_extended(struct diff_options *options,

0 commit comments

Comments
 (0)