Mercurial > hg
annotate rust/hg-core/src/copy_tracing.rs @ 45964:46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
The next changeset will massively rewrite the next function. However having a
clear diff on the core semantic of the function will help making the next
changesets clearer. So we do most of the churn beforehand.
Differential Revision: https://phab.mercurial-scm.org/D9301
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 02 Nov 2020 19:25:26 +0100 |
parents | 0d99778af68a |
children | cc759d3db1e8 |
rev | line source |
---|---|
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 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
|
2 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
|
3 |
45963
0d99778af68a
copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45944
diff
changeset
|
4 use im_rc::ordmap::OrdMap; |
0d99778af68a
copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45944
diff
changeset
|
5 |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 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
|
7 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
|
8 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 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
|
10 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 #[derive(Clone, Debug)] |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 struct TimeStampedPathCopy { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 /// 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
|
14 rev: Revision, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 /// 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
|
16 /// key) |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 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
|
18 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 /// maps CopyDestination to Copy Source (+ a "timestamp" for the operation) |
45963
0d99778af68a
copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45944
diff
changeset
|
21 type TimeStampedPathCopies = OrdMap<HgPathBuf, TimeStampedPathCopy>; |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 /// 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
|
24 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
|
25 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 /// 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
|
27 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 /// 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
|
29 /// 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 impl ChangedFiles { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 ) -> Self { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 ChangedFiles { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 removed, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 merged, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 salvaged, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 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
|
51 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
|
52 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 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
|
56 ChangedFiles { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 /// 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
|
67 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 /// Arguments are: |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 /// 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
|
71 /// 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
|
72 /// 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
|
73 /// 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
|
74 /// * first parent |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 /// * second parent |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 /// * ChangedFiles |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 /// 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
|
78 /// ancestor of another |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 pub fn combine_changeset_copies( |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 rev_info: &impl Fn(Revision) -> RevInfo, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 is_ancestor: &impl Fn(Revision, Revision) -> bool, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 ) -> PathCopies { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 let mut all_copies = HashMap::new(); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 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
|
89 // 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 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
|
102 // 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
|
103 // 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
|
104 // 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
|
105 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
|
106 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 let (parent, child_copies) = if rev == p1 { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 (1, &changes.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
|
109 } else { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 assert_eq!(rev, p2); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 (2, &changes.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
|
112 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 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
|
114 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 for (dest, source) in child_copies { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 let entry; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 if let Some(v) = copies.get(source) { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 entry = match &v.path { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 Some(path) => Some((*(path)).to_owned()), |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 None => Some(source.to_owned()), |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 } else { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 entry = Some(source.to_owned()); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 // Each new entry is introduced by the children, we record this |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 // information as we will need it to take the right decision |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 // when merging conflicting copy information. See |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 // merge_copies_dict for details. |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
129 let ttpc = TimeStampedPathCopy { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
130 rev: *child, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
131 path: entry, |
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 new_copies.insert(dest.to_owned(), ttpc); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
134 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
135 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
136 // We must drop copy information for removed file. |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
137 // |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 // We need to explicitly record them as dropped to propagate this |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 // information when merging two TimeStampedPathCopies object. |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 for f in changes.removed.iter() { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 if new_copies.contains_key(f.as_ref()) { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 let ttpc = TimeStampedPathCopy { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 rev: *child, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 path: None, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
146 new_copies.insert(f.to_owned(), ttpc); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
150 // 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
|
151 // |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 // 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
|
153 // 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
|
154 // 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
|
155 // 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
|
156 // 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
|
157 // 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
|
158 // 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
|
159 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
|
160 None => { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 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
|
162 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 _ => unreachable!(), |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
168 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
169 let merged_copies = |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
170 merge_copies_dict(minor, major, &changes, is_ancestor); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
171 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
|
172 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
173 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
174 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
175 } |
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 // 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
|
178 // mapping. |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
179 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
|
180 .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
|
181 .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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
187 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
188 result |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
189 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
190 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
191 /// 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
|
192 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
193 /// 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
|
194 /// 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
|
195 #[allow(clippy::if_same_then_else)] |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
196 fn merge_copies_dict( |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
197 minor: TimeStampedPathCopies, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
198 major: TimeStampedPathCopies, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
199 changes: &ChangedFiles, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
200 is_ancestor: &impl Fn(Revision, Revision) -> bool, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
201 ) -> TimeStampedPathCopies { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
202 let mut result = minor.clone(); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
203 for (dest, src_major) in major { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
204 let overwrite; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
205 if let Some(src_minor) = minor.get(&dest) { |
45964
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
206 { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
207 if src_major.path == src_minor.path { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
208 // we have the same value, no need to battle; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
209 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:
45963
diff
changeset
|
210 // If the two entry are identical, no need to do |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
211 // anything |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
212 overwrite = false; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
213 } else if is_ancestor(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:
45963
diff
changeset
|
214 overwrite = false; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
215 } else { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
216 overwrite = true; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
217 } |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
218 } 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:
45963
diff
changeset
|
219 // 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:
45963
diff
changeset
|
220 // same rev. So this is the same value. |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
221 overwrite = false; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
222 } else if src_major.path.is_none() |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
223 && changes.salvaged.contains(&dest) |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
224 { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
225 // If the file is "deleted" in the major side but was |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
226 // salvaged by the merge, we keep the minor side alive |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
227 overwrite = false; |
45964
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
228 } else if src_minor.path.is_none() |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
229 && changes.salvaged.contains(&dest) |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
230 { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
231 // If the file is "deleted" in the minor side but was |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
232 // salvaged by the merge, unconditionnaly preserve the |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
233 // major side. |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
234 overwrite = true; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
235 } else if changes.merged.contains(&dest) { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
236 // If the file was actively merged, copy information from |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
237 // each side might conflict. The major side will win such |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
238 // conflict. |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
239 overwrite = true; |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
240 } else if is_ancestor(src_major.rev, src_minor.rev) { |
45964
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
241 // If the minor side is strictly newer than the major side, |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
242 // it should be kept. |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
243 overwrite = false; |
45964
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
244 } else if src_major.path.is_some() { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
245 // without any special case, the "major" value win other |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
246 // the "minor" one. |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
247 overwrite = true; |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
248 } else if is_ancestor(src_minor.rev, src_major.rev) { |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
249 // the "major" rev is a direct ancestors of "minor", any |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
250 // different value should overwrite |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
251 overwrite = true; |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
252 } else { |
45964
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
253 // major version is None (so the file was deleted on that |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
254 // branch) and that branch is independant (neither minor |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
255 // nor major is an ancestors of the other one.) We preserve |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
256 // the new information about the new file. |
46a16b2c082d
copies-rust: pre-indent some code to clarify the next changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45963
diff
changeset
|
257 overwrite = false; |
45944
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 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
260 } else { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
261 // minor had no value |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
262 overwrite = true; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
263 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
264 if overwrite { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
265 result.insert(dest, src_major); |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
266 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
267 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
268 result |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
269 } |