Mercurial > hg-stable
annotate rust/hg-core/src/copy_tracing.rs @ 46127:94300498491e
copies-rust: move the mapping merging into a else clause
We are going to add more cases, to it is time to stop using early returns and to
move everything in a single if/elif/else block for clarity.
Differential Revision: https://phab.mercurial-scm.org/D9425
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 21 Nov 2020 09:31:34 +0100 |
parents | 61afe6215aef |
children | c58c8f1d63b1 |
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 |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
8 use std::cmp::Ordering; |
45959
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::HashMap; |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
10 use std::convert::TryInto; |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 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
|
13 |
45986
cc759d3db1e8
copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45979
diff
changeset
|
14 #[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
|
15 struct TimeStampedPathCopy { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 /// 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
|
17 rev: Revision, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 /// 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
|
19 /// key) |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 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
|
21 } |
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 /// 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
|
24 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
|
25 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 /// hold parent 1, parent 2 and relevant files actions. |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
27 pub type RevInfo<'a> = (Revision, Revision, ChangedFiles<'a>); |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 /// 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
|
30 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 /// 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
|
32 /// all the data categories tracked by it. |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
33 /// This hold a subset of mercurial.metadata.ChangingFiles as we do not need |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
34 /// all the data categories tracked by it. |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
35 pub struct ChangedFiles<'a> { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
36 nb_items: u32, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
37 index: &'a [u8], |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
38 data: &'a [u8], |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 |
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
|
41 /// 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
|
42 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
|
43 /// 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
|
44 /// |
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 /// (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
|
46 /// 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
|
47 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
|
48 /// 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
|
49 /// 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
|
50 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
|
51 } |
ed0e1339e4a8
copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45987
diff
changeset
|
52 |
45990
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
53 /// This express the possible "special" case we can get in a merge |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
54 /// |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
55 /// See mercurial/metadata.py for details on these values. |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
56 #[derive(PartialEq)] |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
57 enum MergeCase { |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
58 /// Merged: file had history on both side that needed to be merged |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
59 Merged, |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
60 /// Salvaged: file was candidate for deletion, but survived the merge |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
61 Salvaged, |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
62 /// Normal: Not one of the two cases above |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
63 Normal, |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
64 } |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
65 |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
66 type FileChange<'a> = (u8, &'a HgPath, &'a HgPath); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
67 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
68 const EMPTY: &[u8] = b""; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
69 const COPY_MASK: u8 = 3; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
70 const P1_COPY: u8 = 2; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
71 const P2_COPY: u8 = 3; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
72 const ACTION_MASK: u8 = 28; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
73 const REMOVED: u8 = 12; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
74 const MERGED: u8 = 8; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
75 const SALVAGED: u8 = 16; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
76 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
77 impl<'a> ChangedFiles<'a> { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
78 const INDEX_START: usize = 4; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
79 const ENTRY_SIZE: u32 = 9; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
80 const FILENAME_START: u32 = 1; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
81 const COPY_SOURCE_START: u32 = 5; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
82 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
83 pub fn new(data: &'a [u8]) -> Self { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
84 assert!( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
85 data.len() >= 4, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
86 "data size ({}) is too small to contain the header (4)", |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
87 data.len() |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
88 ); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
89 let nb_items_raw: [u8; 4] = (&data[0..=3]) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
90 .try_into() |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
91 .expect("failed to turn 4 bytes into 4 bytes"); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
92 let nb_items = u32::from_be_bytes(nb_items_raw); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
93 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
94 let index_size = (nb_items * Self::ENTRY_SIZE) as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
95 let index_end = Self::INDEX_START + index_size; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
96 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
97 assert!( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
98 data.len() >= index_end, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
99 "data size ({}) is too small to fit the index_data ({})", |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
100 data.len(), |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
101 index_end |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
102 ); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
103 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
104 let ret = ChangedFiles { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
105 nb_items, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
106 index: &data[Self::INDEX_START..index_end], |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
107 data: &data[index_end..], |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
108 }; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
109 let max_data = ret.filename_end(nb_items - 1) as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
110 assert!( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
111 ret.data.len() >= max_data, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
112 "data size ({}) is too small to fit all data ({})", |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
113 data.len(), |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
114 index_end + max_data |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
115 ); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
116 ret |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 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
|
120 ChangedFiles { |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
121 nb_items: 0, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
122 index: EMPTY, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
123 data: EMPTY, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
124 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
125 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
126 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
127 /// internal function to return an individual entry at a given index |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
128 fn entry(&'a self, idx: u32) -> FileChange<'a> { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
129 if idx >= self.nb_items { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
130 panic!( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
131 "index for entry is higher that the number of file {} >= {}", |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
132 idx, self.nb_items |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
133 ) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
134 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
135 let flags = self.flags(idx); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
136 let filename = self.filename(idx); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
137 let copy_idx = self.copy_idx(idx); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
138 let copy_source = self.filename(copy_idx); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
139 (flags, filename, copy_source) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
140 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
141 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
142 /// internal function to return the filename of the entry at a given index |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
143 fn filename(&self, idx: u32) -> &HgPath { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
144 let filename_start; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
145 if idx == 0 { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
146 filename_start = 0; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
147 } else { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
148 filename_start = self.filename_end(idx - 1) |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 } |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
150 let filename_end = self.filename_end(idx); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
151 let filename_start = filename_start as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
152 let filename_end = filename_end as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
153 HgPath::new(&self.data[filename_start..filename_end]) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
154 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
155 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
156 /// internal function to return the flag field of the entry at a given |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
157 /// index |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
158 fn flags(&self, idx: u32) -> u8 { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
159 let idx = idx as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
160 self.index[idx * (Self::ENTRY_SIZE as usize)] |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
161 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
162 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
163 /// internal function to return the end of a filename part at a given index |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
164 fn filename_end(&self, idx: u32) -> u32 { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
165 let start = (idx * Self::ENTRY_SIZE) + Self::FILENAME_START; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
166 let end = (idx * Self::ENTRY_SIZE) + Self::COPY_SOURCE_START; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
167 let start = start as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
168 let end = end as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
169 let raw = (&self.index[start..end]) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
170 .try_into() |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
171 .expect("failed to turn 4 bytes into 4 bytes"); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
172 u32::from_be_bytes(raw) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
173 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
174 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
175 /// internal function to return index of the copy source of the entry at a |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
176 /// given index |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
177 fn copy_idx(&self, idx: u32) -> u32 { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
178 let start = (idx * Self::ENTRY_SIZE) + Self::COPY_SOURCE_START; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
179 let end = (idx + 1) * Self::ENTRY_SIZE; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
180 let start = start as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
181 let end = end as usize; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
182 let raw = (&self.index[start..end]) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
183 .try_into() |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
184 .expect("failed to turn 4 bytes into 4 bytes"); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
185 u32::from_be_bytes(raw) |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
186 } |
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
|
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 /// Return an iterator over all the `Action` in this instance. |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
189 fn iter_actions(&self, parent: Parent) -> ActionsIterator { |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
190 ActionsIterator { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
191 changes: &self, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
192 parent: parent, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
193 current: 0, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
194 } |
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
|
195 } |
45990
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
196 |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
197 /// return the MergeCase value associated with a filename |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
198 fn get_merge_case(&self, path: &HgPath) -> MergeCase { |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
199 if self.nb_items == 0 { |
45990
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
200 return MergeCase::Normal; |
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
201 } |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
202 let mut low_part = 0; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
203 let mut high_part = self.nb_items; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
204 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
205 while low_part < high_part { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
206 let cursor = (low_part + high_part - 1) / 2; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
207 let (flags, filename, _source) = self.entry(cursor); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
208 match path.cmp(filename) { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
209 Ordering::Less => low_part = cursor + 1, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
210 Ordering::Greater => high_part = cursor, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
211 Ordering::Equal => { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
212 return match flags & ACTION_MASK { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
213 MERGED => MergeCase::Merged, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
214 SALVAGED => MergeCase::Salvaged, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
215 _ => MergeCase::Normal, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
216 }; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
217 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
218 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
219 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
220 MergeCase::Normal |
45990
2367937982ba
copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45989
diff
changeset
|
221 } |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
222 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
223 |
45987
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
224 /// 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
|
225 /// |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
226 /// 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
|
227 /// result. |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
228 #[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
|
229 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
|
230 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
|
231 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
|
232 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
233 |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
234 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
|
235 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
|
236 Self { |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
237 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
|
238 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
|
239 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
240 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
241 |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
242 /// 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
|
243 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
|
244 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
|
245 false |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
246 } 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
|
247 true |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
248 } else { |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
249 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
|
250 *b |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
251 } else { |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
252 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
|
253 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
|
254 b |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
255 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
256 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
257 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
258 } |
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
259 |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
260 struct ActionsIterator<'a> { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
261 changes: &'a ChangedFiles<'a>, |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
262 parent: Parent, |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
263 current: u32, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
264 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
265 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
266 impl<'a> Iterator for ActionsIterator<'a> { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
267 type Item = Action<'a>; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
268 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
269 fn next(&mut self) -> Option<Action<'a>> { |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
270 let copy_flag = match self.parent { |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
271 Parent::FirstParent => P1_COPY, |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
272 Parent::SecondParent => P2_COPY, |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
273 }; |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
274 while self.current < self.changes.nb_items { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
275 let (flags, file, source) = self.changes.entry(self.current); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
276 self.current += 1; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
277 if (flags & ACTION_MASK) == REMOVED { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
278 return Some(Action::Removed(file)); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
279 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
280 let copy = flags & COPY_MASK; |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
281 if copy == copy_flag { |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
282 return Some(Action::Copied(file, source)); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
283 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
284 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
285 return None; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
286 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
287 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
288 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
289 /// A small struct whose purpose is to ensure lifetime of bytes referenced in |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
290 /// ChangedFiles |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
291 /// |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
292 /// It is passed to the RevInfoMaker callback who can assign any necessary |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
293 /// content to the `data` attribute. The copy tracing code is responsible for |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
294 /// keeping the DataHolder alive at least as long as the ChangedFiles object. |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
295 pub struct DataHolder<D> { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
296 /// RevInfoMaker callback should assign data referenced by the |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
297 /// ChangedFiles struct it return to this attribute. The DataHolder |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
298 /// lifetime will be at least as long as the ChangedFiles one. |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
299 pub data: Option<D>, |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
300 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
301 |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
302 pub type RevInfoMaker<'a, D> = |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
303 Box<dyn for<'r> Fn(Revision, &'r mut DataHolder<D>) -> RevInfo<'r> + 'a>; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
304 |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
305 /// enum used to carry information about the parent → child currently processed |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
306 #[derive(Copy, Clone, Debug)] |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
307 enum Parent { |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
308 /// The `p1(x) → x` edge |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
309 FirstParent, |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
310 /// The `p2(x) → x` edge |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
311 SecondParent, |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
312 } |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
313 |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
314 /// 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
|
315 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
316 /// Arguments are: |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
317 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
318 /// 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
|
319 /// 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
|
320 /// 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
|
321 /// 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
|
322 /// * first parent |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
323 /// * second parent |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
324 /// * ChangedFiles |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
325 /// 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
|
326 /// ancestor of another |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
327 pub fn combine_changeset_copies<A: Fn(Revision, Revision) -> bool, D>( |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
328 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
|
329 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
|
330 target_rev: Revision, |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
331 rev_info: RevInfoMaker<D>, |
45987
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
332 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
|
333 ) -> PathCopies { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
334 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
|
335 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
|
336 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
337 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
|
338 // 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
344 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
345 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
|
346 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
|
347 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
|
348 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
349 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
350 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
|
351 // 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
|
352 // the individual copies information for each of its children. |
46061
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
353 // Creating a new PathCopies for each `rev` → `children` vertex. |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
354 let mut d: DataHolder<D> = DataHolder { data: None }; |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45990
diff
changeset
|
355 let (p1, p2, changes) = rev_info(*child, &mut d); |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
356 |
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
|
357 let parent = if rev == p1 { |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
358 Parent::FirstParent |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
359 } else { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
360 assert_eq!(rev, p2); |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
361 Parent::SecondParent |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
362 }; |
46063
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
363 let new_copies = |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
364 add_from_changes(&copies, &changes, parent, *child); |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
365 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
366 // 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
|
367 // |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
368 // 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
|
369 // 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
|
370 // 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
|
371 // 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
|
372 // 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
|
373 // 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
|
374 // 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
|
375 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
|
376 None => { |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
377 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
|
378 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
379 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
|
380 let (minor, major) = match parent { |
46062
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
381 Parent::FirstParent => (other_copies, new_copies), |
12192fdbf3ac
copies-rust: move the parent token to an enum
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46061
diff
changeset
|
382 Parent::SecondParent => (new_copies, other_copies), |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
383 }; |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
384 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
|
385 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
|
386 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
|
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 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
390 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
391 |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
392 // 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
|
393 // mapping. |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
394 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
|
395 .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
|
396 .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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
402 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
403 result |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
404 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
405 |
46063
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
406 /// Combine ChangedFiles with some existing PathCopies information and return |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
407 /// the result |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
408 fn add_from_changes( |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
409 base_copies: &TimeStampedPathCopies, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
410 changes: &ChangedFiles, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
411 parent: Parent, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
412 current_rev: Revision, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
413 ) -> TimeStampedPathCopies { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
414 let mut copies = base_copies.clone(); |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
415 for action in changes.iter_actions(parent) { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
416 match action { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
417 Action::Copied(dest, source) => { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
418 let entry; |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
419 if let Some(v) = base_copies.get(source) { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
420 entry = match &v.path { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
421 Some(path) => Some((*(path)).to_owned()), |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
422 None => Some(source.to_owned()), |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
423 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
424 } else { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
425 entry = Some(source.to_owned()); |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
426 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
427 // Each new entry is introduced by the children, we |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
428 // record this information as we will need it to take |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
429 // the right decision when merging conflicting copy |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
430 // information. See merge_copies_dict for details. |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
431 let ttpc = TimeStampedPathCopy { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
432 rev: current_rev, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
433 path: entry, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
434 }; |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
435 copies.insert(dest.to_owned(), ttpc); |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
436 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
437 Action::Removed(f) => { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
438 // We must drop copy information for removed file. |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
439 // |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
440 // We need to explicitly record them as dropped to |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
441 // propagate this information when merging two |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
442 // TimeStampedPathCopies object. |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
443 if copies.contains_key(f.as_ref()) { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
444 let ttpc = TimeStampedPathCopy { |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
445 rev: current_rev, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
446 path: None, |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
447 }; |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
448 copies.insert(f.to_owned(), ttpc); |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
449 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
450 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
451 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
452 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
453 copies |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
454 } |
dacb771f6dd2
copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46062
diff
changeset
|
455 |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
456 /// 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
|
457 /// |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
458 /// 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
|
459 /// cases. See inline documentation for details. |
45987
8b99c473aae2
copies-rust: move is_ancestor caching within the rust code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45986
diff
changeset
|
460 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
|
461 minor: TimeStampedPathCopies, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
462 major: TimeStampedPathCopies, |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
463 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
|
464 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
|
465 ) -> TimeStampedPathCopies { |
45986
cc759d3db1e8
copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45979
diff
changeset
|
466 if minor.is_empty() { |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
467 major |
45986
cc759d3db1e8
copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45979
diff
changeset
|
468 } else if major.is_empty() { |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
469 minor |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
470 } else { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
471 let mut override_minor = Vec::new(); |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
472 let mut override_major = Vec::new(); |
45986
cc759d3db1e8
copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45979
diff
changeset
|
473 |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
474 let mut to_major = |k: &HgPathBuf, v: &TimeStampedPathCopy| { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
475 override_major.push((k.clone(), v.clone())) |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
476 }; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
477 let mut to_minor = |k: &HgPathBuf, v: &TimeStampedPathCopy| { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
478 override_minor.push((k.clone(), v.clone())) |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
479 }; |
45986
cc759d3db1e8
copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45979
diff
changeset
|
480 |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
481 // The diff function leverage detection of the identical subpart if |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
482 // minor and major has some common ancestors. This make it very |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
483 // fast is most case. |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
484 // |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
485 // In case where the two map are vastly different in size, the current |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
486 // approach is still slowish because the iteration will iterate over |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
487 // all the "exclusive" content of the larger on. This situation can be |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
488 // frequent when the subgraph of revision we are processing has a lot |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
489 // of roots. Each roots adding they own fully new map to the mix (and |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
490 // likely a small map, if the path from the root to the "main path" is |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
491 // small. |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
492 // |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
493 // We could do better by detecting such situation and processing them |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
494 // differently. |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
495 for d in minor.diff(&major) { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
496 match d { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
497 DiffItem::Add(k, v) => to_minor(k, v), |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
498 DiffItem::Remove(k, v) => to_major(k, v), |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
499 DiffItem::Update { old, new } => { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
500 let (dest, src_major) = new; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
501 let (_, src_minor) = old; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
502 match compare_value( |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
503 changes, oracle, dest, src_minor, src_major, |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
504 ) { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
505 MergePick::Major => to_minor(dest, src_major), |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
506 MergePick::Minor => to_major(dest, src_minor), |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
507 // If the two entry are identical, no need to do |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
508 // anything (but diff should not have yield them) |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
509 MergePick::Any => unreachable!(), |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
510 } |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
511 } |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
512 }; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
513 } |
45986
cc759d3db1e8
copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45979
diff
changeset
|
514 |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
515 let updates; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
516 let mut result; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
517 if override_major.is_empty() { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
518 result = major |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
519 } else if override_minor.is_empty() { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
520 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
|
521 } else { |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
522 if override_minor.len() < override_major.len() { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
523 updates = override_minor; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
524 result = minor; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
525 } else { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
526 updates = override_major; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
527 result = major; |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
528 } |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
529 for (k, v) in updates { |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
530 result.insert(k, v); |
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
531 } |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
532 } |
46127
94300498491e
copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46126
diff
changeset
|
533 result |
45959
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
534 } |
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
535 } |
46126
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
536 |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
537 /// represent the side that should prevail when merging two |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
538 /// TimeStampedPathCopies |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
539 enum MergePick { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
540 /// The "major" (p1) side prevails |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
541 Major, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
542 /// The "minor" (p2) side prevails |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
543 Minor, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
544 /// Any side could be used (because they are the same) |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
545 Any, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
546 } |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
547 |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
548 /// decide which side prevails in case of conflicting values |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
549 #[allow(clippy::if_same_then_else)] |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
550 fn compare_value<A: Fn(Revision, Revision) -> bool>( |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
551 changes: &ChangedFiles, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
552 oracle: &mut AncestorOracle<A>, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
553 dest: &HgPathBuf, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
554 src_minor: &TimeStampedPathCopy, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
555 src_major: &TimeStampedPathCopy, |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
556 ) -> MergePick { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
557 if src_major.path == src_minor.path { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
558 // we have the same value, but from other source; |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
559 if src_major.rev == src_minor.rev { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
560 // If the two entry are identical, they are both valid |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
561 MergePick::Any |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
562 } else if oracle.is_ancestor(src_major.rev, src_minor.rev) { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
563 MergePick::Minor |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
564 } else { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
565 MergePick::Major |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
566 } |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
567 } else if src_major.rev == src_minor.rev { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
568 // We cannot get copy information for both p1 and p2 in the |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
569 // same rev. So this is the same value. |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
570 unreachable!( |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
571 "conflict information from p1 and p2 in the same revision" |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
572 ); |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
573 } else { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
574 let action = changes.get_merge_case(&dest); |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
575 if src_major.path.is_none() && action == MergeCase::Salvaged { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
576 // If the file is "deleted" in the major side but was |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
577 // salvaged by the merge, we keep the minor side alive |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
578 MergePick::Minor |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
579 } else if src_minor.path.is_none() && action == MergeCase::Salvaged { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
580 // If the file is "deleted" in the minor side but was |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
581 // salvaged by the merge, unconditionnaly preserve the |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
582 // major side. |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
583 MergePick::Major |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
584 } else if action == MergeCase::Merged { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
585 // If the file was actively merged, copy information |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
586 // from each side might conflict. The major side will |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
587 // win such conflict. |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
588 MergePick::Major |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
589 } else if oracle.is_ancestor(src_major.rev, src_minor.rev) { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
590 // If the minor side is strictly newer than the major |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
591 // side, it should be kept. |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
592 MergePick::Minor |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
593 } else if src_major.path.is_some() { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
594 // without any special case, the "major" value win |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
595 // other the "minor" one. |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
596 MergePick::Major |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
597 } else if oracle.is_ancestor(src_minor.rev, src_major.rev) { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
598 // the "major" rev is a direct ancestors of "minor", |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
599 // any different value should |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
600 // overwrite |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
601 MergePick::Major |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
602 } else { |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
603 // major version is None (so the file was deleted on |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
604 // that branch) and that branch is independant (neither |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
605 // minor nor major is an ancestors of the other one.) |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
606 // We preserve the new |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
607 // information about the new file. |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
608 MergePick::Minor |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
609 } |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
610 } |
61afe6215aef
copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46063
diff
changeset
|
611 } |