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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jan 19, 2021 at 19:53 UTC
1b6b902d95a5b2c5677b6351c670202dae7cd230
1 file changed
+21
-5
merge-ort.c
+21
-5
@@ -1410,12 +1410,28 @@ static int process_renames(struct merge_options *opt,
1410
const char *rename_branch = NULL, *delete_branch = NULL;
1411
1412
old_ent = strmap_get_entry(&opt->priv->paths, pair->one->path);
1413
- oldpath = old_ent->key;
1414
- oldinfo = old_ent->value;
1415
-
1413
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;
1435
1436
/*
1437
* diff_filepairs have copies of pathnames, thus we have to