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

copies-rust: move the parent token to an enum

We carry around information about which parent of a revision is been dealt
with. So far this was a `usize` but as we are about to pass it around to more
function it seems like a good idea to start cleaning this up and use a proper
enum.

Differential Revision: https://phab.mercurial-scm.org/D9420
parent 0cd02885
No related branches found
No related tags found
No related merge requests found
......@@ -186,7 +186,7 @@
}
/// Return an iterator over all the `Action` in this instance.
fn iter_actions(&self, parent: usize) -> ActionsIterator {
fn iter_actions(&self, parent: Parent) -> ActionsIterator {
ActionsIterator {
changes: &self,
parent: parent,
......@@ -259,7 +259,7 @@
struct ActionsIterator<'a> {
changes: &'a ChangedFiles<'a>,
parent: usize,
parent: Parent,
current: u32,
}
......@@ -267,6 +267,10 @@
type Item = Action<'a>;
fn next(&mut self) -> Option<Action<'a>> {
let copy_flag = match self.parent {
Parent::FirstParent => P1_COPY,
Parent::SecondParent => P2_COPY,
};
while self.current < self.changes.nb_items {
let (flags, file, source) = self.changes.entry(self.current);
self.current += 1;
......@@ -274,10 +278,7 @@
return Some(Action::Removed(file));
}
let copy = flags & COPY_MASK;
if self.parent == 1 && copy == P1_COPY {
return Some(Action::Copied(file, source));
}
if self.parent == 2 && copy == P2_COPY {
if copy == copy_flag {
return Some(Action::Copied(file, source));
}
}
......@@ -301,6 +302,15 @@
pub type RevInfoMaker<'a, D> =
Box<dyn for<'r> Fn(Revision, &'r mut DataHolder<D>) -> RevInfo<'r> + 'a>;
/// enum used to carry information about the parent → child currently processed
#[derive(Copy, Clone, Debug)]
enum Parent {
/// The `p1(x) → x` edge
FirstParent,
/// The `p2(x) → x` edge
SecondParent,
}
/// Same as mercurial.copies._combine_changeset_copies, but in Rust.
///
/// Arguments are:
......@@ -345,6 +355,6 @@
let (p1, p2, changes) = rev_info(*child, &mut d);
let parent = if rev == p1 {
1
Parent::FirstParent
} else {
assert_eq!(rev, p2);
......@@ -349,6 +359,6 @@
} else {
assert_eq!(rev, p2);
2
Parent::SecondParent
};
let mut new_copies = copies.clone();
......@@ -406,9 +416,8 @@
}
Some(other_copies) => {
let (minor, major) = match parent {
1 => (other_copies, new_copies),
2 => (new_copies, other_copies),
_ => unreachable!(),
Parent::FirstParent => (other_copies, new_copies),
Parent::SecondParent => (new_copies, other_copies),
};
let merged_copies =
merge_copies_dict(minor, major, &changes, &mut oracle);
......
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