Show More
@@ -1,199 +1,202 b'' | |||
|
1 | 1 | //! Supporting macros for `tests.rs` in the same directory. |
|
2 | 2 | //! See comments there for usage. |
|
3 | 3 | |
|
4 | 4 | /// Python-like set literal |
|
5 | 5 | macro_rules! set { |
|
6 | 6 | ( |
|
7 | 7 | $Type: ty { |
|
8 | 8 | $( $value: expr ),* $(,)? |
|
9 | 9 | } |
|
10 | 10 | ) => {{ |
|
11 | 11 | #[allow(unused_mut)] |
|
12 | 12 | let mut set = <$Type>::new(); |
|
13 | 13 | $( set.insert($value); )* |
|
14 | 14 | set |
|
15 | 15 | }} |
|
16 | 16 | } |
|
17 | 17 | |
|
18 | 18 | /// `{key => value}` map literal |
|
19 | 19 | macro_rules! map { |
|
20 | 20 | ( |
|
21 | 21 | $Type: ty { |
|
22 | 22 | $( $key: expr => $value: expr ),* $(,)? |
|
23 | 23 | } |
|
24 | 24 | ) => {{ |
|
25 | 25 | #[allow(unused_mut)] |
|
26 | 26 | let mut set = <$Type>::new(); |
|
27 | 27 | $( set.insert($key, $value); )* |
|
28 | 28 | set |
|
29 | 29 | }} |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | macro_rules! copy_source { |
|
33 | 33 | ($rev: expr, $path: expr, $overwritten: tt) => { |
|
34 | 34 | CopySource { |
|
35 | 35 | rev: $rev, |
|
36 | 36 | path: $path, |
|
37 | 37 | overwritten: set!(OrdSet<Revision> $overwritten), |
|
38 | 38 | } |
|
39 | 39 | }; |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | macro_rules! compare_value { |
|
43 | 43 | ( |
|
44 | 44 | $merge_revision: expr, |
|
45 | 45 | $merge_case_for_dest: ident, |
|
46 | 46 | ($min_rev: expr, $min_path: expr, $min_overwrite: tt), |
|
47 | 47 | ($maj_rev: expr, $maj_path: expr, $maj_overwrite: tt) $(,)? |
|
48 | 48 | ) => { |
|
49 | 49 | compare_value( |
|
50 | 50 | $merge_revision, |
|
51 | 51 | || $merge_case_for_dest, |
|
52 | 52 | ©_source!($min_rev, $min_path, $min_overwrite), |
|
53 | 53 | ©_source!($maj_rev, $maj_path, $maj_overwrite), |
|
54 | 54 | ) |
|
55 | 55 | }; |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | macro_rules! tokenized_path_copies { |
|
59 | 59 | ( |
|
60 | 60 | $path_map: ident, {$( |
|
61 | 61 | $dest: expr => ( |
|
62 | 62 | $src_rev: expr, |
|
63 | 63 | $src_path: expr, |
|
64 | 64 | $src_overwrite: tt |
|
65 | 65 | ) |
|
66 | 66 | ),*} |
|
67 | 67 | $(,)* |
|
68 | 68 | ) => { |
|
69 | 69 | map!(InternalPathCopies {$( |
|
70 | 70 | $path_map.tokenize(HgPath::new($dest)) => |
|
71 | 71 | copy_source!( |
|
72 | 72 | $src_rev, |
|
73 | 73 | Option::map($src_path, |p: &str| { |
|
74 | 74 | $path_map.tokenize(HgPath::new(p)) |
|
75 | 75 | }), |
|
76 | 76 | $src_overwrite |
|
77 | 77 | ) |
|
78 | 78 | )*}) |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | macro_rules! merge_case_callback { |
|
83 | 83 | ( |
|
84 | 84 | $( $merge_path: expr => $merge_case: ident ),* |
|
85 | 85 | $(,)? |
|
86 | 86 | ) => { |
|
87 | 87 | #[allow(unused)] |
|
88 | 88 | |merge_path| -> MergeCase { |
|
89 | 89 | $( |
|
90 | 90 | if (merge_path == HgPath::new($merge_path)) { |
|
91 | 91 | return $merge_case |
|
92 | 92 | } |
|
93 | 93 | )* |
|
94 | 94 | MergeCase::Normal |
|
95 | 95 | } |
|
96 | 96 | }; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | macro_rules! merge_copies_dict { |
|
100 | 100 | ( |
|
101 | 101 | $current_merge: expr, |
|
102 | 102 | $minor_copies: tt, |
|
103 | 103 | $major_copies: tt, |
|
104 | 104 | $get_merge_case: tt $(,)? |
|
105 | 105 | ) => { |
|
106 | 106 | { |
|
107 | 107 | #[allow(unused_mut)] |
|
108 | 108 | let mut map = TwoWayPathMap::default(); |
|
109 | 109 | let minor = tokenized_path_copies!(map, $minor_copies); |
|
110 | 110 | let major = tokenized_path_copies!(map, $major_copies); |
|
111 | 111 | merge_copies_dict( |
|
112 | 112 | &map, $current_merge, minor, major, |
|
113 | 113 | merge_case_callback! $get_merge_case, |
|
114 | 114 | ) |
|
115 | 115 | .into_iter() |
|
116 | 116 | .map(|(token, source)| { |
|
117 | 117 | ( |
|
118 | 118 | map.untokenize(token).to_string(), |
|
119 | 119 | ( |
|
120 | 120 | source.rev, |
|
121 | 121 | source.path.map(|t| map.untokenize(t).to_string()), |
|
122 | 122 | source.overwritten.into_iter().collect(), |
|
123 | 123 | ), |
|
124 | 124 | ) |
|
125 | 125 | }) |
|
126 |
.collect::<OrdMap< |
|
|
126 | .collect::<OrdMap< | |
|
127 | String, | |
|
128 | (Revision, Option<String>, OrdSet<Revision>) | |
|
129 | >>() | |
|
127 | 130 | } |
|
128 | 131 | }; |
|
129 | 132 | } |
|
130 | 133 | |
|
131 | 134 | macro_rules! internal_path_copies { |
|
132 | 135 | ( |
|
133 | 136 | $( |
|
134 | 137 | $dest: expr => ( |
|
135 | 138 | $src_rev: expr, |
|
136 | 139 | $src_path: expr, |
|
137 | 140 | $src_overwrite: tt $(,)? |
|
138 | 141 | ) |
|
139 | 142 | ),* |
|
140 | 143 | $(,)* |
|
141 | 144 | ) => { |
|
142 | 145 | map!(OrdMap<_, _> {$( |
|
143 | 146 | String::from($dest) => ( |
|
144 | 147 | $src_rev, |
|
145 | 148 | $src_path, |
|
146 | 149 | set!(OrdSet<Revision> $src_overwrite) |
|
147 | 150 | ) |
|
148 | 151 | ),*}) |
|
149 | 152 | }; |
|
150 | 153 | } |
|
151 | 154 | |
|
152 | 155 | macro_rules! combine_changeset_copies { |
|
153 | 156 | ( |
|
154 | 157 | $children_count: tt, |
|
155 | 158 | [ |
|
156 | 159 | $( |
|
157 | 160 | { |
|
158 | 161 | rev: $rev: expr, |
|
159 | 162 | p1: $p1: expr, |
|
160 | 163 | p2: $p2: expr, |
|
161 | 164 | actions: [ |
|
162 | 165 | $( |
|
163 | 166 | $Action: ident($( $action_path: expr ),+) |
|
164 | 167 | ),* |
|
165 | 168 | $(,)? |
|
166 | 169 | ], |
|
167 | 170 | merge_cases: $merge: tt |
|
168 | 171 | $(,)? |
|
169 | 172 | } |
|
170 | 173 | ),* |
|
171 | 174 | $(,)? |
|
172 | 175 | ], |
|
173 | 176 | $target_rev: expr $(,)* |
|
174 | 177 | ) => {{ |
|
175 | 178 | let count = map!(HashMap<Revision, usize> $children_count); |
|
176 | 179 | let mut combine_changeset_copies = CombineChangesetCopies::new(count); |
|
177 | 180 | $( |
|
178 | 181 | let actions = vec![$( |
|
179 | 182 | $Action($( HgPath::new($action_path) ),*) |
|
180 | 183 | ),*]; |
|
181 | 184 | combine_changeset_copies.add_revision_inner( |
|
182 | 185 | $rev, $p1, $p2, actions.into_iter(), |
|
183 | 186 | merge_case_callback! $merge |
|
184 | 187 | ); |
|
185 | 188 | )* |
|
186 | 189 | combine_changeset_copies.finish($target_rev) |
|
187 | 190 | }}; |
|
188 | 191 | } |
|
189 | 192 | |
|
190 | 193 | macro_rules! path_copies { |
|
191 | 194 | ( |
|
192 | 195 | $( $expected_destination: expr => $expected_source: expr ),* $(,)? |
|
193 | 196 | ) => { |
|
194 | 197 | map!(PathCopies {$( |
|
195 | 198 | HgPath::new($expected_destination).to_owned() |
|
196 | 199 | => HgPath::new($expected_source).to_owned(), |
|
197 | 200 | ),*}) |
|
198 | 201 | }; |
|
199 | 202 | } |
General Comments 0
You need to be logged in to leave comments.
Login now