annotate rust/hg-core/src/copy_tracing.rs @ 45989:10bb0856bb9f

copies-rust: pre-indent some code to clarify the next patch The next patch will need this new indentation, having it done explicitly beforehand makes that next patch clearer. Differential Revision: https://phab.mercurial-scm.org/D9305
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 30 Oct 2020 19:06:12 +0100
parents ed0e1339e4a8
children 2367937982ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
1 use crate::utils::hg_path::HgPath;
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 use crate::utils::hg_path::HgPathBuf;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 use crate::Revision;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
5 use im_rc::ordmap::DiffItem;
45978
0d99778af68a copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45959
diff changeset
6 use im_rc::ordmap::OrdMap;
0d99778af68a copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45959
diff changeset
7
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8 use std::collections::HashMap;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 use std::collections::HashSet;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11 pub type PathCopies = HashMap<HgPathBuf, HgPathBuf>;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
13 #[derive(Clone, Debug, PartialEq)]
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14 struct TimeStampedPathCopy {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
15 /// revision at which the copy information was added
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
16 rev: Revision,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
17 /// the copy source, (Set to None in case of deletion of the associated
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
18 /// key)
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
19 path: Option<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
20 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
21
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
22 /// maps CopyDestination to Copy Source (+ a "timestamp" for the operation)
45978
0d99778af68a copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45959
diff changeset
23 type TimeStampedPathCopies = OrdMap<HgPathBuf, TimeStampedPathCopy>;
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
24
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
25 /// hold parent 1, parent 2 and relevant files actions.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
26 pub type RevInfo = (Revision, Revision, ChangedFiles);
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
27
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
28 /// represent the files affected by a changesets
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
29 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
30 /// This hold a subset of mercurial.metadata.ChangingFiles as we do not need
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
31 /// all the data categories tracked by it.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
32 pub struct ChangedFiles {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
33 removed: HashSet<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 merged: HashSet<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
35 salvaged: HashSet<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
36 copied_from_p1: PathCopies,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
37 copied_from_p2: PathCopies,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
38 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
39
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
40 /// Represent active changes that affect the copy tracing.
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
41 enum Action<'a> {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
42 /// The parent ? children edge is removing a file
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
43 ///
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
44 /// (actually, this could be the edge from the other parent, but it does
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
45 /// not matters)
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
46 Removed(&'a HgPath),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
47 /// The parent ? children edge introduce copy information between (dest,
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
48 /// source)
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
49 Copied(&'a HgPath, &'a HgPath),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
50 }
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
51
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
52 impl ChangedFiles {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
53 pub fn new(
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
54 removed: HashSet<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
55 merged: HashSet<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
56 salvaged: HashSet<HgPathBuf>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
57 copied_from_p1: PathCopies,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
58 copied_from_p2: PathCopies,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
59 ) -> Self {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
60 ChangedFiles {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
61 removed,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
62 merged,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
63 salvaged,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
64 copied_from_p1,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
65 copied_from_p2,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
66 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
67 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
68
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
69 pub fn new_empty() -> Self {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
70 ChangedFiles {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
71 removed: HashSet::new(),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
72 merged: HashSet::new(),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
73 salvaged: HashSet::new(),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
74 copied_from_p1: PathCopies::new(),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
75 copied_from_p2: PathCopies::new(),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
76 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
77 }
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
78
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
79 /// Return an iterator over all the `Action` in this instance.
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
80 fn iter_actions(&self, parent: usize) -> impl Iterator<Item = Action> {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
81 let copies_iter = match parent {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
82 1 => self.copied_from_p1.iter(),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
83 2 => self.copied_from_p2.iter(),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
84 _ => unreachable!(),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
85 };
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
86 let remove_iter = self.removed.iter();
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
87 let copies_iter = copies_iter.map(|(x, y)| Action::Copied(x, y));
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
88 let remove_iter = remove_iter.map(|x| Action::Removed(x));
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
89 copies_iter.chain(remove_iter)
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
90 }
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
91 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
92
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
93 /// A struct responsible for answering "is X ancestors of Y" quickly
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
94 ///
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
95 /// The structure will delegate ancestors call to a callback, and cache the
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
96 /// result.
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
97 #[derive(Debug)]
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
98 struct AncestorOracle<'a, A: Fn(Revision, Revision) -> bool> {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
99 inner: &'a A,
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
100 pairs: HashMap<(Revision, Revision), bool>,
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
101 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
102
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
103 impl<'a, A: Fn(Revision, Revision) -> bool> AncestorOracle<'a, A> {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
104 fn new(func: &'a A) -> Self {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
105 Self {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
106 inner: func,
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
107 pairs: HashMap::default(),
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
108 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
109 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
110
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
111 /// returns `true` if `anc` is an ancestors of `desc`, `false` otherwise
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
112 fn is_ancestor(&mut self, anc: Revision, desc: Revision) -> bool {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
113 if anc > desc {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
114 false
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
115 } else if anc == desc {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
116 true
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
117 } else {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
118 if let Some(b) = self.pairs.get(&(anc, desc)) {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
119 *b
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
120 } else {
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
121 let b = (self.inner)(anc, desc);
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
122 self.pairs.insert((anc, desc), b);
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
123 b
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
124 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
125 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
126 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
127 }
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
128
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
129 /// Same as mercurial.copies._combine_changeset_copies, but in Rust.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
130 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
131 /// Arguments are:
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
132 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
133 /// revs: all revisions to be considered
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
134 /// children: a {parent ? [childrens]} mapping
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
135 /// target_rev: the final revision we are combining copies to
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
136 /// rev_info(rev): callback to get revision information:
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
137 /// * first parent
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
138 /// * second parent
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
139 /// * ChangedFiles
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
140 /// isancestors(low_rev, high_rev): callback to check if a revision is an
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
141 /// ancestor of another
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
142 pub fn combine_changeset_copies<A: Fn(Revision, Revision) -> bool>(
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
143 revs: Vec<Revision>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
144 children: HashMap<Revision, Vec<Revision>>,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
145 target_rev: Revision,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
146 rev_info: &impl Fn(Revision) -> RevInfo,
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
147 is_ancestor: &A,
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
148 ) -> PathCopies {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
149 let mut all_copies = HashMap::new();
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
150 let mut oracle = AncestorOracle::new(is_ancestor);
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
151
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
152 for rev in revs {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
153 // Retrieve data computed in a previous iteration
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
154 let copies = all_copies.remove(&rev);
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
155 let copies = match copies {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
156 Some(c) => c,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
157 None => TimeStampedPathCopies::default(), // root of the walked set
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
158 };
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
159
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
160 let current_children = match children.get(&rev) {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
161 Some(c) => c,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
162 None => panic!("inconsistent `revs` and `children`"),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
163 };
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
164
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
165 for child in current_children {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
166 // We will chain the copies information accumulated for `rev` with
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
167 // the individual copies information for each of its children.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
168 // Creating a new PathCopies for each `rev` ? `children` vertex.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
169 let (p1, p2, changes) = rev_info(*child);
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
170
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
171 let parent = if rev == p1 {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
172 1
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
173 } else {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
174 assert_eq!(rev, p2);
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
175 2
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
176 };
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
177 let mut new_copies = copies.clone();
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
178
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
179 for action in changes.iter_actions(parent) {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
180 match action {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
181 Action::Copied(dest, source) => {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
182 let entry;
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
183 if let Some(v) = copies.get(source) {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
184 entry = match &v.path {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
185 Some(path) => Some((*(path)).to_owned()),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
186 None => Some(source.to_owned()),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
187 }
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
188 } else {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
189 entry = Some(source.to_owned());
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
190 }
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
191 // Each new entry is introduced by the children, we
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
192 // record this information as we will need it to take
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
193 // the right decision when merging conflicting copy
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
194 // information. See merge_copies_dict for details.
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
195 let ttpc = TimeStampedPathCopy {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
196 rev: *child,
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
197 path: entry,
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
198 };
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
199 new_copies.insert(dest.to_owned(), ttpc);
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
200 }
45988
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
201 Action::Removed(f) => {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
202 // We must drop copy information for removed file.
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
203 //
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
204 // We need to explicitly record them as dropped to
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
205 // propagate this information when merging two
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
206 // TimeStampedPathCopies object.
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
207 if new_copies.contains_key(f.as_ref()) {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
208 let ttpc = TimeStampedPathCopy {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
209 rev: *child,
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
210 path: None,
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
211 };
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
212 new_copies.insert(f.to_owned(), ttpc);
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
213 }
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45987
diff changeset
214 }
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
215 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
216 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
217
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
218 // Merge has two parents needs to combines their copy information.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
219 //
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
220 // If the vertex from the other parent was already processed, we
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
221 // will have a value for the child ready to be used. We need to
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
222 // grab it and combine it with the one we already
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
223 // computed. If not we can simply store the newly
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
224 // computed data. The processing happening at
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
225 // the time of the second parent will take care of combining the
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
226 // two TimeStampedPathCopies instance.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
227 match all_copies.remove(child) {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
228 None => {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
229 all_copies.insert(child, new_copies);
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
230 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
231 Some(other_copies) => {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
232 let (minor, major) = match parent {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
233 1 => (other_copies, new_copies),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
234 2 => (new_copies, other_copies),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
235 _ => unreachable!(),
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
236 };
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
237 let merged_copies =
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
238 merge_copies_dict(minor, major, &changes, &mut oracle);
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
239 all_copies.insert(child, merged_copies);
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
240 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
241 };
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
242 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
243 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
244
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
245 // Drop internal information (like the timestamp) and return the final
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
246 // mapping.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
247 let tt_result = all_copies
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
248 .remove(&target_rev)
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
249 .expect("target revision was not processed");
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
250 let mut result = PathCopies::default();
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
251 for (dest, tt_source) in tt_result {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
252 if let Some(path) = tt_source.path {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
253 result.insert(dest, path);
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
254 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
255 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
256 result
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
257 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
258
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
259 /// merge two copies-mapping together, minor and major
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
260 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
261 /// In case of conflict, value from "major" will be picked, unless in some
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
262 /// cases. See inline documentation for details.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
263 #[allow(clippy::if_same_then_else)]
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
264 fn merge_copies_dict<A: Fn(Revision, Revision) -> bool>(
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
265 minor: TimeStampedPathCopies,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
266 major: TimeStampedPathCopies,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
267 changes: &ChangedFiles,
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
268 oracle: &mut AncestorOracle<A>,
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
269 ) -> TimeStampedPathCopies {
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
270 if minor.is_empty() {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
271 return major;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
272 } else if major.is_empty() {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
273 return minor;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
274 }
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
275 let mut override_minor = Vec::new();
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
276 let mut override_major = Vec::new();
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
277
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
278 let mut to_major = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
279 override_major.push((k.clone(), v.clone()))
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
280 };
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
281 let mut to_minor = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
282 override_minor.push((k.clone(), v.clone()))
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
283 };
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
284
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
285 // The diff function leverage detection of the identical subpart if minor
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
286 // and major has some common ancestors. This make it very fast is most
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
287 // case.
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
288 //
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
289 // In case where the two map are vastly different in size, the current
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
290 // approach is still slowish because the iteration will iterate over
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
291 // all the "exclusive" content of the larger on. This situation can be
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
292 // frequent when the subgraph of revision we are processing has a lot
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
293 // of roots. Each roots adding they own fully new map to the mix (and
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
294 // likely a small map, if the path from the root to the "main path" is
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
295 // small.
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
296 //
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
297 // We could do better by detecting such situation and processing them
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
298 // differently.
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
299 for d in minor.diff(&major) {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
300 match d {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
301 DiffItem::Add(k, v) => to_minor(k, v),
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
302 DiffItem::Remove(k, v) => to_major(k, v),
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
303 DiffItem::Update { old, new } => {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
304 let (dest, src_major) = new;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
305 let (_, src_minor) = old;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
306 let mut pick_minor = || (to_major(dest, src_minor));
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
307 let mut pick_major = || (to_minor(dest, src_major));
45979
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
308 if src_major.path == src_minor.path {
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
309 // we have the same value, but from other source;
45979
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
310 if src_major.rev == src_minor.rev {
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
311 // If the two entry are identical, no need to do
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
312 // anything (but diff should not have yield them)
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
313 unreachable!();
45987
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
314 } else if oracle.is_ancestor(src_major.rev, src_minor.rev)
8b99c473aae2 copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45986
diff changeset
315 {
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
316 pick_minor();
45979
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
317 } else {
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
318 pick_major();
45979
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
319 }
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
320 } else if src_major.rev == src_minor.rev {
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
321 // We cannot get copy information for both p1 and p2 in the
46a16b2c082d copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45978
diff changeset
322 // same rev. So this is the same value.
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
323 unreachable!();
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
324 } else {
45989
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
325 if src_major.path.is_none()
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
326 && changes.salvaged.contains(dest)
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
327 {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
328 // If the file is "deleted" in the major side but was
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
329 // salvaged by the merge, we keep the minor side alive
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
330 pick_minor();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
331 } else if src_minor.path.is_none()
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
332 && changes.salvaged.contains(dest)
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
333 {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
334 // If the file is "deleted" in the minor side but was
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
335 // salvaged by the merge, unconditionnaly preserve the
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
336 // major side.
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
337 pick_major();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
338 } else if changes.merged.contains(dest) {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
339 // If the file was actively merged, copy information
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
340 // from each side might conflict. The major side will
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
341 // win such conflict.
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
342 pick_major();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
343 } else if oracle.is_ancestor(src_major.rev, src_minor.rev)
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
344 {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
345 // If the minor side is strictly newer than the major
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
346 // side, it should be kept.
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
347 pick_minor();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
348 } else if src_major.path.is_some() {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
349 // without any special case, the "major" value win
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
350 // other the "minor" one.
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
351 pick_major();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
352 } else if oracle.is_ancestor(src_minor.rev, src_major.rev)
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
353 {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
354 // the "major" rev is a direct ancestors of "minor",
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
355 // any different value should
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
356 // overwrite
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
357 pick_major();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
358 } else {
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
359 // major version is None (so the file was deleted on
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
360 // that branch) and that branch is independant (neither
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
361 // minor nor major is an ancestors of the other one.)
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
362 // We preserve the new
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
363 // information about the new file.
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
364 pick_minor();
10bb0856bb9f copies-rust: pre-indent some code to clarify the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45988
diff changeset
365 }
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
366 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
367 }
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
368 };
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
369 }
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
370
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
371 let updates;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
372 let mut result;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
373 if override_major.is_empty() {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
374 result = major
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
375 } else if override_minor.is_empty() {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
376 result = minor
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
377 } else {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
378 if override_minor.len() < override_major.len() {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
379 updates = override_minor;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
380 result = minor;
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
381 } else {
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
382 updates = override_major;
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
383 result = major;
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
384 }
45986
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
385 for (k, v) in updates {
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45979
diff changeset
386 result.insert(k, v);
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
387 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
388 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
389 result
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
390 }