Skip to content

Commit 8e30669

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 f9c201d commit 8e30669

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

diffcore-rename.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ static int handle_early_known_dir_renames(int num_src,
10841084
struct strintmap *relevant_sources,
10851085
struct strintmap *dirs_removed)
10861086
{
1087-
int i;
1087+
int i, new_num_src;
10881088
struct hashmap_iter iter;
10891089
struct strmap_entry *entry;
10901090

@@ -1135,7 +1135,54 @@ static int handle_early_known_dir_renames(int num_src,
11351135
}
11361136
}
11371137

1138-
return num_src;
1138+
for (i = 0, new_num_src = 0; i < num_src; i++) {
1139+
struct diff_filespec *one = rename_src[i].p->one;
1140+
int val;
1141+
1142+
val = strintmap_get(relevant_sources, one->path);
1143+
1144+
/*
1145+
* sources that were not found in relevant_sources should
1146+
* have already been removed by a prior call to
1147+
* remove_unneeded_paths_from_src()
1148+
*/
1149+
assert(val != -1);
1150+
1151+
if (val == RELEVANT_LOCATION) {
1152+
int removable = 1;
1153+
char *dir = get_dirname(one->path);
1154+
while (1) {
1155+
char *freeme = dir;
1156+
int res = strintmap_get(dirs_removed, dir);
1157+
1158+
/* Quit if not found or irrelevant */
1159+
if (res == NOT_RELEVANT)
1160+
break;
1161+
/* If RELEVANT_FOR_SELF, can't remove */
1162+
if (res == RELEVANT_FOR_SELF) {
1163+
removable = 0;
1164+
break;
1165+
}
1166+
/* Else continue searching upwards */
1167+
assert(res == RELEVANT_FOR_ANCESTOR);
1168+
dir = get_dirname(dir);
1169+
free(freeme);
1170+
}
1171+
free(dir);
1172+
if (removable) {
1173+
strintmap_set(relevant_sources, one->path,
1174+
RELEVANT_NO_MORE);
1175+
continue;
1176+
}
1177+
}
1178+
1179+
if (new_num_src < i)
1180+
memcpy(&rename_src[new_num_src], &rename_src[i],
1181+
sizeof(struct diff_rename_src));
1182+
new_num_src++;
1183+
}
1184+
1185+
return new_num_src;
11391186
}
11401187

11411188
void diffcore_rename_extended(struct diff_options *options,

0 commit comments

Comments
 (0)