##// END OF EJS Templates
rhg-cat: fallback in presence of a fileset...
Raphaël Gomès -
r48888:4a6fa6b6 default
parent child Browse files
Show More
@@ -1,88 +1,93
1 1 use crate::error::CommandError;
2 2 use clap::Arg;
3 3 use format_bytes::format_bytes;
4 4 use hg::operations::cat;
5 5 use hg::utils::hg_path::HgPathBuf;
6 6 use micro_timer::timed;
7 7 use std::convert::TryFrom;
8 8
9 9 pub const HELP_TEXT: &str = "
10 10 Output the current or given revision of files
11 11 ";
12 12
13 13 pub fn args() -> clap::App<'static, 'static> {
14 14 clap::SubCommand::with_name("cat")
15 15 .arg(
16 16 Arg::with_name("rev")
17 17 .help("search the repository as it is in REV")
18 18 .short("-r")
19 19 .long("--revision")
20 20 .value_name("REV")
21 21 .takes_value(true),
22 22 )
23 23 .arg(
24 24 clap::Arg::with_name("files")
25 25 .required(true)
26 26 .multiple(true)
27 27 .empty_values(false)
28 28 .value_name("FILE")
29 29 .help("Activity to start: activity@category"),
30 30 )
31 31 .about(HELP_TEXT)
32 32 }
33 33
34 34 #[timed]
35 35 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
36 36 let rev = invocation.subcommand_args.value_of("rev");
37 37 let file_args = match invocation.subcommand_args.values_of("files") {
38 38 Some(files) => files.collect(),
39 39 None => vec![],
40 40 };
41 41
42 42 let repo = invocation.repo?;
43 43 let cwd = hg::utils::current_dir()?;
44 44 let working_directory = repo.working_directory_path();
45 45 let working_directory = cwd.join(working_directory); // Make it absolute
46 46
47 47 let mut files = vec![];
48 48 for file in file_args.iter() {
49 if file.starts_with("set:") {
50 let message = "fileset";
51 return Err(CommandError::unsupported(message));
52 }
53
49 54 let normalized = cwd.join(&file);
50 55 // TODO: actually normalize `..` path segments etc?
51 56 let dotted = normalized.components().any(|c| c.as_os_str() == "..");
52 57 if file == &"." || dotted {
53 58 let message = "`..` or `.` path segment";
54 59 return Err(CommandError::unsupported(message));
55 60 }
56 61 let stripped = normalized
57 62 .strip_prefix(&working_directory)
58 63 // TODO: error message for path arguments outside of the repo
59 64 .map_err(|_| CommandError::abort(""))?;
60 65 let hg_file = HgPathBuf::try_from(stripped.to_path_buf())
61 66 .map_err(|e| CommandError::abort(e.to_string()))?;
62 67 files.push(hg_file);
63 68 }
64 69 // TODO probably move this to a util function like `repo.default_rev` or
65 70 // something when it's used somewhere else
66 71 let rev = match rev {
67 72 Some(r) => r.to_string(),
68 73 None => format!("{:x}", repo.dirstate_parents()?.p1),
69 74 };
70 75
71 76 let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?;
72 77 invocation.ui.write_stdout(&output.concatenated)?;
73 78 if !output.missing.is_empty() {
74 79 let short = format!("{:x}", output.node.short()).into_bytes();
75 80 for path in &output.missing {
76 81 invocation.ui.write_stderr(&format_bytes!(
77 82 b"{}: no such file in rev {}\n",
78 83 path.as_bytes(),
79 84 short
80 85 ))?;
81 86 }
82 87 }
83 88 if output.found_any {
84 89 Ok(())
85 90 } else {
86 91 Err(CommandError::Unsuccessful)
87 92 }
88 93 }
@@ -1,348 +1,353
1 1 #require rhg
2 2
3 3 $ NO_FALLBACK="env RHG_ON_UNSUPPORTED=abort"
4 4
5 5 Unimplemented command
6 6 $ $NO_FALLBACK rhg unimplemented-command
7 7 unsupported feature: error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context
8 8
9 9 USAGE:
10 10 rhg [OPTIONS] <SUBCOMMAND>
11 11
12 12 For more information try --help
13 13
14 14 [252]
15 15 $ rhg unimplemented-command --config rhg.on-unsupported=abort-silent
16 16 [252]
17 17
18 18 Finding root
19 19 $ $NO_FALLBACK rhg root
20 20 abort: no repository found in '$TESTTMP' (.hg not found)!
21 21 [255]
22 22
23 23 $ hg init repository
24 24 $ cd repository
25 25 $ $NO_FALLBACK rhg root
26 26 $TESTTMP/repository
27 27
28 28 Reading and setting configuration
29 29 $ echo "[ui]" >> $HGRCPATH
30 30 $ echo "username = user1" >> $HGRCPATH
31 31 $ $NO_FALLBACK rhg config ui.username
32 32 user1
33 33 $ echo "[ui]" >> .hg/hgrc
34 34 $ echo "username = user2" >> .hg/hgrc
35 35 $ $NO_FALLBACK rhg config ui.username
36 36 user2
37 37 $ $NO_FALLBACK rhg --config ui.username=user3 config ui.username
38 38 user3
39 39
40 40 Unwritable file descriptor
41 41 $ $NO_FALLBACK rhg root > /dev/full
42 42 abort: No space left on device (os error 28)
43 43 [255]
44 44
45 45 Deleted repository
46 46 $ rm -rf `pwd`
47 47 $ $NO_FALLBACK rhg root
48 48 abort: error getting current working directory: $ENOENT$
49 49 [255]
50 50
51 51 Listing tracked files
52 52 $ cd $TESTTMP
53 53 $ hg init repository
54 54 $ cd repository
55 55 $ for i in 1 2 3; do
56 56 > echo $i >> file$i
57 57 > hg add file$i
58 58 > done
59 59 > hg commit -m "commit $i" -q
60 60
61 61 Listing tracked files from root
62 62 $ $NO_FALLBACK rhg files
63 63 file1
64 64 file2
65 65 file3
66 66
67 67 Listing tracked files from subdirectory
68 68 $ mkdir -p path/to/directory
69 69 $ cd path/to/directory
70 70 $ $NO_FALLBACK rhg files
71 71 ../../../file1
72 72 ../../../file2
73 73 ../../../file3
74 74
75 75 Listing tracked files through broken pipe
76 76 $ $NO_FALLBACK rhg files | head -n 1
77 77 ../../../file1
78 78
79 79 Debuging data in inline index
80 80 $ cd $TESTTMP
81 81 $ rm -rf repository
82 82 $ hg init repository
83 83 $ cd repository
84 84 $ for i in 1 2 3 4 5 6; do
85 85 > echo $i >> file-$i
86 86 > hg add file-$i
87 87 > hg commit -m "Commit $i" -q
88 88 > done
89 89 $ $NO_FALLBACK rhg debugdata -c 2
90 90 8d0267cb034247ebfa5ee58ce59e22e57a492297
91 91 test
92 92 0 0
93 93 file-3
94 94
95 95 Commit 3 (no-eol)
96 96 $ $NO_FALLBACK rhg debugdata -m 2
97 97 file-1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
98 98 file-2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc)
99 99 file-3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc)
100 100
101 101 Debuging with full node id
102 102 $ $NO_FALLBACK rhg debugdata -c `hg log -r 0 -T '{node}'`
103 103 d1d1c679d3053e8926061b6f45ca52009f011e3f
104 104 test
105 105 0 0
106 106 file-1
107 107
108 108 Commit 1 (no-eol)
109 109
110 110 Specifying revisions by changeset ID
111 111 $ hg log -T '{node}\n'
112 112 c6ad58c44207b6ff8a4fbbca7045a5edaa7e908b
113 113 d654274993d0149eecc3cc03214f598320211900
114 114 f646af7e96481d3a5470b695cf30ad8e3ab6c575
115 115 cf8b83f14ead62b374b6e91a0e9303b85dfd9ed7
116 116 91c6f6e73e39318534dc415ea4e8a09c99cd74d6
117 117 6ae9681c6d30389694d8701faf24b583cf3ccafe
118 118 $ $NO_FALLBACK rhg files -r cf8b83
119 119 file-1
120 120 file-2
121 121 file-3
122 122 $ $NO_FALLBACK rhg cat -r cf8b83 file-2
123 123 2
124 124 $ $NO_FALLBACK rhg cat -r c file-2
125 125 abort: ambiguous revision identifier: c
126 126 [255]
127 127 $ $NO_FALLBACK rhg cat -r d file-2
128 128 2
129 129 $ $NO_FALLBACK rhg cat -r 0000 file-2
130 130 abort: invalid revision identifier: 0000
131 131 [255]
132 132
133 133 Cat files
134 134 $ cd $TESTTMP
135 135 $ rm -rf repository
136 136 $ hg init repository
137 137 $ cd repository
138 138 $ echo "original content" > original
139 139 $ hg add original
140 140 $ hg commit -m "add original" original
141 141 Without `--rev`
142 142 $ $NO_FALLBACK rhg cat original
143 143 original content
144 144 With `--rev`
145 145 $ $NO_FALLBACK rhg cat -r 0 original
146 146 original content
147 147 Cat copied file should not display copy metadata
148 148 $ hg copy original copy_of_original
149 149 $ hg commit -m "add copy of original"
150 150 $ $NO_FALLBACK rhg cat original
151 151 original content
152 152 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
153 153 original content
154 154
155 155
156 156 Fallback to Python
157 157 $ $NO_FALLBACK rhg cat original --exclude="*.rs"
158 158 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
159 159
160 160 USAGE:
161 161 rhg cat [OPTIONS] <FILE>...
162 162
163 163 For more information try --help
164 164
165 165 [252]
166 166 $ rhg cat original --exclude="*.rs"
167 167 original content
168 168
169 169 $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE"
170 170 $ unset RHG_FALLBACK_EXECUTABLE
171 171 $ rhg cat original --exclude="*.rs"
172 172 abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
173 173 [255]
174 174 $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE"
175 175 $ export RHG_FALLBACK_EXECUTABLE
176 176
177 177 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=false
178 178 [1]
179 179
180 180 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=hg-non-existent
181 181 tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$
182 182 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
183 183
184 184 USAGE:
185 185 rhg cat [OPTIONS] <FILE>...
186 186
187 187 For more information try --help
188 188
189 189 [252]
190 190
191 191 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=rhg
192 192 Blocking recursive fallback. The 'rhg.fallback-executable = rhg' config points to `rhg` itself.
193 193 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
194 194
195 195 USAGE:
196 196 rhg cat [OPTIONS] <FILE>...
197 197
198 198 For more information try --help
199 199
200 200 [252]
201 201
202 202 Fallback with shell path segments
203 203 $ $NO_FALLBACK rhg cat .
204 204 unsupported feature: `..` or `.` path segment
205 205 [252]
206 206 $ $NO_FALLBACK rhg cat ..
207 207 unsupported feature: `..` or `.` path segment
208 208 [252]
209 209 $ $NO_FALLBACK rhg cat ../..
210 210 unsupported feature: `..` or `.` path segment
211 211 [252]
212 212
213 Fallback with filesets
214 $ $NO_FALLBACK rhg cat "set:c or b"
215 unsupported feature: fileset
216 [252]
217
213 218 Requirements
214 219 $ $NO_FALLBACK rhg debugrequirements
215 220 dotencode
216 221 fncache
217 222 generaldelta
218 223 persistent-nodemap
219 224 revlog-compression-zstd (zstd !)
220 225 revlogv1
221 226 sparserevlog
222 227 store
223 228
224 229 $ echo indoor-pool >> .hg/requires
225 230 $ $NO_FALLBACK rhg files
226 231 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
227 232 [252]
228 233
229 234 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
230 235 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
231 236 [252]
232 237
233 238 $ $NO_FALLBACK rhg debugrequirements
234 239 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
235 240 [252]
236 241
237 242 $ echo -e '\xFF' >> .hg/requires
238 243 $ $NO_FALLBACK rhg debugrequirements
239 244 abort: parse error in 'requires' file
240 245 [255]
241 246
242 247 Persistent nodemap
243 248 $ cd $TESTTMP
244 249 $ rm -rf repository
245 250 $ hg --config format.use-persistent-nodemap=no init repository
246 251 $ cd repository
247 252 $ $NO_FALLBACK rhg debugrequirements | grep nodemap
248 253 [1]
249 254 $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn"
250 255 $ hg id -r tip
251 256 c3ae8dec9fad tip
252 257 $ ls .hg/store/00changelog*
253 258 .hg/store/00changelog.d
254 259 .hg/store/00changelog.i
255 260 $ $NO_FALLBACK rhg files -r c3ae8dec9fad
256 261 of
257 262
258 263 $ cd $TESTTMP
259 264 $ rm -rf repository
260 265 $ hg --config format.use-persistent-nodemap=True init repository
261 266 $ cd repository
262 267 $ $NO_FALLBACK rhg debugrequirements | grep nodemap
263 268 persistent-nodemap
264 269 $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn"
265 270 $ hg id -r tip
266 271 c3ae8dec9fad tip
267 272 $ ls .hg/store/00changelog*
268 273 .hg/store/00changelog-*.nd (glob)
269 274 .hg/store/00changelog.d
270 275 .hg/store/00changelog.i
271 276 .hg/store/00changelog.n
272 277
273 278 Specifying revisions by changeset ID
274 279 $ $NO_FALLBACK rhg files -r c3ae8dec9fad
275 280 of
276 281 $ $NO_FALLBACK rhg cat -r c3ae8dec9fad of
277 282 r5000
278 283
279 284 Crate a shared repository
280 285
281 286 $ echo "[extensions]" >> $HGRCPATH
282 287 $ echo "share = " >> $HGRCPATH
283 288
284 289 $ cd $TESTTMP
285 290 $ hg init repo1
286 291 $ echo a > repo1/a
287 292 $ hg -R repo1 commit -A -m'init'
288 293 adding a
289 294
290 295 $ hg share repo1 repo2
291 296 updating working directory
292 297 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
293 298
294 299 And check that basic rhg commands work with sharing
295 300
296 301 $ $NO_FALLBACK rhg files -R repo2
297 302 repo2/a
298 303 $ $NO_FALLBACK rhg -R repo2 cat -r 0 repo2/a
299 304 a
300 305
301 306 Same with relative sharing
302 307
303 308 $ hg share repo2 repo3 --relative
304 309 updating working directory
305 310 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
306 311
307 312 $ $NO_FALLBACK rhg files -R repo3
308 313 repo3/a
309 314 $ $NO_FALLBACK rhg -R repo3 cat -r 0 repo3/a
310 315 a
311 316
312 317 Same with share-safe
313 318
314 319 $ echo "[format]" >> $HGRCPATH
315 320 $ echo "use-share-safe = True" >> $HGRCPATH
316 321
317 322 $ cd $TESTTMP
318 323 $ hg init repo4
319 324 $ cd repo4
320 325 $ echo a > a
321 326 $ hg commit -A -m'init'
322 327 adding a
323 328
324 329 $ cd ..
325 330 $ hg share repo4 repo5
326 331 updating working directory
327 332 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
328 333
329 334 And check that basic rhg commands work with sharing
330 335
331 336 $ cd repo5
332 337 $ $NO_FALLBACK rhg files
333 338 a
334 339 $ $NO_FALLBACK rhg cat -r 0 a
335 340 a
336 341
337 342 The blackbox extension is supported
338 343
339 344 $ echo "[extensions]" >> $HGRCPATH
340 345 $ echo "blackbox =" >> $HGRCPATH
341 346 $ echo "[blackbox]" >> $HGRCPATH
342 347 $ echo "maxsize = 1" >> $HGRCPATH
343 348 $ $NO_FALLBACK rhg files > /dev/null
344 349 $ cat .hg/blackbox.log
345 350 ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files exited 0 after 0.??? seconds (glob)
346 351 $ cat .hg/blackbox.log.1
347 352 ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files (glob)
348 353
General Comments 0
You need to be logged in to leave comments. Login now