From patchwork Mon Dec 21 22:29:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D9654: copies-rust: make more use of the new comparison property From: phabricator X-Patchwork-Id: 47964 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Mon, 21 Dec 2020 22:29:22 +0000 marmoute created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY We deal with the "both are the same" sooner and simplify the rest of the conditional. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D9654 AFFECTED FILES rust/hg-core/src/copy_tracing.rs CHANGE DETAILS To: marmoute, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/rust/hg-core/src/copy_tracing.rs b/rust/hg-core/src/copy_tracing.rs --- a/rust/hg-core/src/copy_tracing.rs +++ b/rust/hg-core/src/copy_tracing.rs @@ -852,49 +852,31 @@ src_minor: &CopySource, src_major: &CopySource, ) -> (MergePick, bool) { - if src_major.rev == current_merge { - if src_minor.rev == current_merge { - if src_major.path.is_none() { - // We cannot get different copy information for both p1 and p2 - // from the same revision. Unless this was a - // deletion. - // - // However the deletion might come over different data on each - // branch. - let need_over = src_major.overwritten != src_minor.overwritten; - (MergePick::Any, need_over) - } else { - unreachable!(); - } - } else { - // The last value comes the current merge, this value -will- win - // eventually. - (MergePick::Major, true) - } + if src_major == src_minor { + (MergePick::Any, false) + } else if src_major.rev == current_merge { + // minor is different according to per minor == major check earlier + debug_assert!(src_minor.rev != current_merge); + + // The last value comes the current merge, this value -will- win + // eventually. + (MergePick::Major, true) } else if src_minor.rev == current_merge { // The last value comes the current merge, this value -will- win // eventually. (MergePick::Minor, true) } else if src_major.path == src_minor.path { + debug_assert!(src_major.rev != src_major.rev); // we have the same value, but from other source; - if src_major.rev == src_minor.rev { - // If the two entry are identical, they are both valid - debug_assert!(src_minor.overwritten == src_minor.overwritten); - (MergePick::Any, false) - } else if src_major.is_overwritten_by(src_minor) { + if src_major.is_overwritten_by(src_minor) { (MergePick::Minor, false) } else if src_minor.is_overwritten_by(src_major) { (MergePick::Major, false) } else { (MergePick::Any, true) } - } else if src_major.rev == src_minor.rev { - // We cannot get copy information for both p1 and p2 in the - // same rev. So this is the same value. - unreachable!( - "conflicting information from p1 and p2 in the same revision" - ); } else { + debug_assert!(src_major.rev != src_major.rev); let dest_path = path_map.untokenize(*dest); let action = changes.get_merge_case(dest_path); if src_minor.path.is_some()