Skip to content

Commit 1b6b902

Browse files
newrengitster
authored andcommitted
merge-ort: process_renames() now needs more defensiveness
Since directory rename detection adds new paths to opt->priv->paths and removes old ones, process_renames() needs to now check whether pair->one->path actually exists in opt->priv->paths instead of just assuming it does. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 089d82b commit 1b6b902

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

merge-ort.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,12 +1410,28 @@ static int process_renames(struct merge_options *opt,
14101410
const char *rename_branch = NULL, *delete_branch = NULL;
14111411

14121412
old_ent = strmap_get_entry(&opt->priv->paths, pair->one->path);
1413-
oldpath = old_ent->key;
1414-
oldinfo = old_ent->value;
1415-
14161413
new_ent = strmap_get_entry(&opt->priv->paths, pair->two->path);
1417-
newpath = new_ent->key;
1418-
newinfo = new_ent->value;
1414+
if (old_ent) {
1415+
oldpath = old_ent->key;
1416+
oldinfo = old_ent->value;
1417+
}
1418+
newpath = pair->two->path;
1419+
if (new_ent) {
1420+
newpath = new_ent->key;
1421+
newinfo = new_ent->value;
1422+
}
1423+
1424+
/*
1425+
* If pair->one->path isn't in opt->priv->paths, that means
1426+
* that either directory rename detection removed that
1427+
* path, or a parent directory of oldpath was resolved and
1428+
* we don't even need the rename; in either case, we can
1429+
* skip it. If oldinfo->merged.clean, then the other side
1430+
* of history had no changes to oldpath and we don't need
1431+
* the rename and can skip it.
1432+
*/
1433+
if (!oldinfo || oldinfo->merged.clean)
1434+
continue;
14191435

14201436
/*
14211437
* diff_filepairs have copies of pathnames, thus we have to

0 commit comments

Comments
 (0)