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