Skip to content
Snippets Groups Projects
Commit 66003328 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 we are currently
dealing with. So far this was a `usize` but as we are about to pass it around
more function it seems like a good idea to start cleaning this up and use a
proper enum.
parent 9e649556
No related branches found
No related tags found
No related merge requests found
......@@ -184,7 +184,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,
......@@ -257,7 +257,7 @@
struct ActionsIterator<'a> {
changes: &'a ChangedFiles<'a>,
parent: usize,
parent: Parent,
current: u32,
}
......@@ -265,6 +265,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;
......@@ -272,10 +276,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));
}
}
......@@ -299,6 +300,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:
......@@ -343,6 +353,6 @@
let (p1, p2, changes) = rev_info(*child, &mut d);
let parent = if rev == p1 {
1
Parent::FirstParent
} else {
assert_eq!(rev, p2);
......@@ -347,6 +357,6 @@
} else {
assert_eq!(rev, p2);
2
Parent::SecondParent
};
let mut new_copies = copies.clone();
......@@ -404,9 +414,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