Skip to content
Snippets Groups Projects
Commit 6295cbbd0eca authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

copies-rust: encapsulate internal sets on `changes`

The goal is to eventually stop creating the underlying set. So we need to
encapsulate the call first.

Differential Revision: https://phab.mercurial-scm.org/D9306
parent 673fcc437b08
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,19 @@ ...@@ -47,6 +47,19 @@
Copied(&'a HgPath, &'a HgPath), Copied(&'a HgPath, &'a HgPath),
} }
/// This express the possible "special" case we can get in a merge
///
/// See mercurial/metadata.py for details on these values.
#[derive(PartialEq)]
enum MergeCase {
/// Merged: file had history on both side that needed to be merged
Merged,
/// Salvaged: file was candidate for deletion, but survived the merge
Salvaged,
/// Normal: Not one of the two cases above
Normal,
}
impl ChangedFiles { impl ChangedFiles {
pub fn new( pub fn new(
removed: HashSet<HgPathBuf>, removed: HashSet<HgPathBuf>,
...@@ -86,6 +99,17 @@ ...@@ -86,6 +99,17 @@
let remove_iter = remove_iter.map(|x| Action::Removed(x)); let remove_iter = remove_iter.map(|x| Action::Removed(x));
copies_iter.chain(remove_iter) copies_iter.chain(remove_iter)
} }
/// return the MergeCase value associated with a filename
fn get_merge_case(&self, path: &HgPath) -> MergeCase {
if self.salvaged.contains(path) {
return MergeCase::Salvaged;
} else if self.merged.contains(path) {
return MergeCase::Merged;
} else {
return MergeCase::Normal;
}
}
} }
/// A struct responsible for answering "is X ancestors of Y" quickly /// A struct responsible for answering "is X ancestors of Y" quickly
...@@ -318,4 +342,5 @@ ...@@ -318,4 +342,5 @@
// same rev. So this is the same value. // same rev. So this is the same value.
unreachable!(); unreachable!();
} else { } else {
let action = changes.get_merge_case(&dest);
if src_major.path.is_none() if src_major.path.is_none()
...@@ -321,7 +346,7 @@ ...@@ -321,7 +346,7 @@
if src_major.path.is_none() if src_major.path.is_none()
&& changes.salvaged.contains(dest) && action == MergeCase::Salvaged
{ {
// If the file is "deleted" in the major side but was // If the file is "deleted" in the major side but was
// salvaged by the merge, we keep the minor side alive // salvaged by the merge, we keep the minor side alive
pick_minor(); pick_minor();
} else if src_minor.path.is_none() } else if src_minor.path.is_none()
...@@ -323,11 +348,11 @@ ...@@ -323,11 +348,11 @@
{ {
// If the file is "deleted" in the major side but was // If the file is "deleted" in the major side but was
// salvaged by the merge, we keep the minor side alive // salvaged by the merge, we keep the minor side alive
pick_minor(); pick_minor();
} else if src_minor.path.is_none() } else if src_minor.path.is_none()
&& changes.salvaged.contains(dest) && action == MergeCase::Salvaged
{ {
// If the file is "deleted" in the minor side but was // If the file is "deleted" in the minor side but was
// salvaged by the merge, unconditionnaly preserve the // salvaged by the merge, unconditionnaly preserve the
// major side. // major side.
pick_major(); pick_major();
...@@ -329,9 +354,9 @@ ...@@ -329,9 +354,9 @@
{ {
// If the file is "deleted" in the minor side but was // If the file is "deleted" in the minor side but was
// salvaged by the merge, unconditionnaly preserve the // salvaged by the merge, unconditionnaly preserve the
// major side. // major side.
pick_major(); pick_major();
} else if changes.merged.contains(dest) { } else if action == MergeCase::Merged {
// If the file was actively merged, copy information // If the file was actively merged, copy information
// from each side might conflict. The major side will // from each side might conflict. The major side will
// win such conflict. // win such conflict.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment