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

copies-rust: move the mapping merging into a else clause

We are going to add more cases, to it is time to stop using early returns and to
move everything in a single if/elif/else block for clarity.

Differential Revision: https://phab.mercurial-scm.org/D9425
parent 61afe6215aef
No related branches found
No related tags found
No related merge requests found
......@@ -464,5 +464,5 @@
oracle: &mut AncestorOracle<A>,
) -> TimeStampedPathCopies {
if minor.is_empty() {
return major;
major
} else if major.is_empty() {
......@@ -468,6 +468,6 @@
} else if major.is_empty() {
return minor;
}
let mut override_minor = Vec::new();
let mut override_major = Vec::new();
minor
} else {
let mut override_minor = Vec::new();
let mut override_major = Vec::new();
......@@ -473,8 +473,8 @@
let mut to_major = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
override_major.push((k.clone(), v.clone()))
};
let mut to_minor = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
override_minor.push((k.clone(), v.clone()))
};
let mut to_major = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
override_major.push((k.clone(), v.clone()))
};
let mut to_minor = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
override_minor.push((k.clone(), v.clone()))
};
......@@ -480,31 +480,32 @@
// The diff function leverage detection of the identical subpart if minor
// and major has some common ancestors. This make it very fast is most
// case.
//
// In case where the two map are vastly different in size, the current
// approach is still slowish because the iteration will iterate over
// all the "exclusive" content of the larger on. This situation can be
// frequent when the subgraph of revision we are processing has a lot
// of roots. Each roots adding they own fully new map to the mix (and
// likely a small map, if the path from the root to the "main path" is
// small.
//
// We could do better by detecting such situation and processing them
// differently.
for d in minor.diff(&major) {
match d {
DiffItem::Add(k, v) => to_minor(k, v),
DiffItem::Remove(k, v) => to_major(k, v),
DiffItem::Update { old, new } => {
let (dest, src_major) = new;
let (_, src_minor) = old;
match compare_value(
changes, oracle, dest, src_minor, src_major,
) {
MergePick::Major => to_minor(dest, src_major),
MergePick::Minor => to_major(dest, src_minor),
// If the two entry are identical, no need to do
// anything (but diff should not have yield them)
MergePick::Any => unreachable!(),
// The diff function leverage detection of the identical subpart if
// minor and major has some common ancestors. This make it very
// fast is most case.
//
// In case where the two map are vastly different in size, the current
// approach is still slowish because the iteration will iterate over
// all the "exclusive" content of the larger on. This situation can be
// frequent when the subgraph of revision we are processing has a lot
// of roots. Each roots adding they own fully new map to the mix (and
// likely a small map, if the path from the root to the "main path" is
// small.
//
// We could do better by detecting such situation and processing them
// differently.
for d in minor.diff(&major) {
match d {
DiffItem::Add(k, v) => to_minor(k, v),
DiffItem::Remove(k, v) => to_major(k, v),
DiffItem::Update { old, new } => {
let (dest, src_major) = new;
let (_, src_minor) = old;
match compare_value(
changes, oracle, dest, src_minor, src_major,
) {
MergePick::Major => to_minor(dest, src_major),
MergePick::Minor => to_major(dest, src_minor),
// If the two entry are identical, no need to do
// anything (but diff should not have yield them)
MergePick::Any => unreachable!(),
}
}
......@@ -510,5 +511,4 @@
}
}
};
}
};
}
......@@ -514,12 +514,8 @@
let updates;
let mut result;
if override_major.is_empty() {
result = major
} else if override_minor.is_empty() {
result = minor
} else {
if override_minor.len() < override_major.len() {
updates = override_minor;
result = minor;
let updates;
let mut result;
if override_major.is_empty() {
result = major
} else if override_minor.is_empty() {
result = minor
} else {
......@@ -525,4 +521,12 @@
} else {
updates = override_major;
result = major;
if override_minor.len() < override_major.len() {
updates = override_minor;
result = minor;
} else {
updates = override_major;
result = major;
}
for (k, v) in updates {
result.insert(k, v);
}
}
......@@ -528,5 +532,3 @@
}
for (k, v) in updates {
result.insert(k, v);
}
result
}
......@@ -532,5 +534,4 @@
}
result
}
/// represent the side that should prevail when merging two
......
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