Skip to content

Commit bf238b7

Browse files
newrengitster
authored andcommitted
diffcore-rename: add computation of number of unknown renames
The previous commit can only be effective if we have a computation of the number of paths under a given directory which are still have pending renames, and expected this number to be recorded in the dir_rename_count map under the key UNKNOWN_DIR. Add the code necessary to compute these values. Note that this change means dir_rename_count might have a directory whose only entry (for UNKNOWN_DIR) was removed by the time merge-ort goes to check it. To account for this, merge-ort needs to check for the case where the max count is 0. With this change we are now computing the necessary value for each directory in dirs_removed, but are not using that value anywhere. The next two commits will make use of the values stored in dirs_removed in order to compute whether each relevant_source (that is needed only for directory rename detection) has become unnecessary. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0491d39 commit bf238b7

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

diffcore-rename.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,8 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
699699
/*
700700
* Although dir_rename_count was passed in
701701
* diffcore_rename_extended() and we want to keep it around and
702-
* return it to that caller, we first want to remove any data
702+
* return it to that caller, we first want to remove any counts in
703+
* the maps associated with UNKNOWN_DIR entries and any data
703704
* associated with directories that weren't renamed.
704705
*/
705706
strmap_for_each_entry(info->dir_rename_count, &iter, entry) {
@@ -711,6 +712,9 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
711712
strintmap_clear(counts);
712713
continue;
713714
}
715+
716+
if (strintmap_contains(counts, UNKNOWN_DIR))
717+
strintmap_remove(counts, UNKNOWN_DIR);
714718
}
715719
for (i = 0; i < to_remove.nr; ++i)
716720
strmap_remove(info->dir_rename_count,
@@ -1125,6 +1129,7 @@ static void handle_early_known_dir_renames(struct dir_rename_info *info,
11251129
* a majority.
11261130
*/
11271131

1132+
int i;
11281133
struct hashmap_iter iter;
11291134
struct strmap_entry *entry;
11301135

@@ -1134,10 +1139,38 @@ static void handle_early_known_dir_renames(struct dir_rename_info *info,
11341139
return; /* culling incompatbile with break detection */
11351140

11361141
/*
1137-
* FIXME: Supplement dir_rename_count with number of potential
1138-
* renames, marking all potential rename sources as mapping to
1139-
* UNKNOWN_DIR.
1142+
* Supplement dir_rename_count with number of potential renames,
1143+
* marking all potential rename sources as mapping to UNKNOWN_DIR.
11401144
*/
1145+
for (i = 0; i < rename_src_nr; i++) {
1146+
char *old_dir;
1147+
struct diff_filespec *one = rename_src[i].p->one;
1148+
1149+
/*
1150+
* sources that are part of a rename will have already been
1151+
* removed by a prior call to remove_unneeded_paths_from_src()
1152+
*/
1153+
assert(!one->rename_used);
1154+
1155+
old_dir = get_dirname(one->path);
1156+
while (*old_dir != '\0' &&
1157+
NOT_RELEVANT != strintmap_get(dirs_removed, old_dir)) {
1158+
char *freeme = old_dir;
1159+
1160+
increment_count(info, old_dir, UNKNOWN_DIR);
1161+
old_dir = get_dirname(old_dir);
1162+
1163+
/* Free resources we don't need anymore */
1164+
free(freeme);
1165+
}
1166+
/*
1167+
* old_dir and new_dir free'd in increment_count, but
1168+
* get_dirname() gives us a new pointer we need to free for
1169+
* old_dir. Also, if the loop runs 0 times we need old_dir
1170+
* to be freed.
1171+
*/
1172+
free(old_dir);
1173+
}
11411174

11421175
/*
11431176
* For any directory which we need a potential rename detected for

merge-ort.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,9 @@ static void get_provisional_directory_renames(struct merge_options *opt,
15461546
}
15471547
}
15481548

1549+
if (max == 0)
1550+
continue;
1551+
15491552
if (bad_max == max) {
15501553
path_msg(opt, source_dir, 0,
15511554
_("CONFLICT (directory rename split): "

0 commit comments

Comments
 (0)