##// END OF EJS Templates
rhg: in rhg cat cli, fix the long name of the --rev flag...
Arseniy Alekseyev -
r48986:08c8cd25 default
parent child Browse files
Show More
@@ -1,93 +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 .long("--revision")
19 .long("--rev")
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 .help("Activity to start: activity@category"),
29 .help("Files to output"),
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 49 if file.starts_with("set:") {
50 50 let message = "fileset";
51 51 return Err(CommandError::unsupported(message));
52 52 }
53 53
54 54 let normalized = cwd.join(&file);
55 55 // TODO: actually normalize `..` path segments etc?
56 56 let dotted = normalized.components().any(|c| c.as_os_str() == "..");
57 57 if file == &"." || dotted {
58 58 let message = "`..` or `.` path segment";
59 59 return Err(CommandError::unsupported(message));
60 60 }
61 61 let stripped = normalized
62 62 .strip_prefix(&working_directory)
63 63 // TODO: error message for path arguments outside of the repo
64 64 .map_err(|_| CommandError::abort(""))?;
65 65 let hg_file = HgPathBuf::try_from(stripped.to_path_buf())
66 66 .map_err(|e| CommandError::abort(e.to_string()))?;
67 67 files.push(hg_file);
68 68 }
69 69 // TODO probably move this to a util function like `repo.default_rev` or
70 70 // something when it's used somewhere else
71 71 let rev = match rev {
72 72 Some(r) => r.to_string(),
73 73 None => format!("{:x}", repo.dirstate_parents()?.p1),
74 74 };
75 75
76 76 let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?;
77 77 invocation.ui.write_stdout(&output.concatenated)?;
78 78 if !output.missing.is_empty() {
79 79 let short = format!("{:x}", output.node.short()).into_bytes();
80 80 for path in &output.missing {
81 81 invocation.ui.write_stderr(&format_bytes!(
82 82 b"{}: no such file in rev {}\n",
83 83 path.as_bytes(),
84 84 short
85 85 ))?;
86 86 }
87 87 }
88 88 if output.found_any {
89 89 Ok(())
90 90 } else {
91 91 Err(CommandError::Unsuccessful)
92 92 }
93 93 }
@@ -1,381 +1,383
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 $ $NO_FALLBACK rhg cat --rev cf8b83 file-2
125 2
124 126 $ $NO_FALLBACK rhg cat -r c file-2
125 127 abort: ambiguous revision identifier: c
126 128 [255]
127 129 $ $NO_FALLBACK rhg cat -r d file-2
128 130 2
129 131 $ $NO_FALLBACK rhg cat -r 0000 file-2
130 132 abort: invalid revision identifier: 0000
131 133 [255]
132 134
133 135 Cat files
134 136 $ cd $TESTTMP
135 137 $ rm -rf repository
136 138 $ hg init repository
137 139 $ cd repository
138 140 $ echo "original content" > original
139 141 $ hg add original
140 142 $ hg commit -m "add original" original
141 143 Without `--rev`
142 144 $ $NO_FALLBACK rhg cat original
143 145 original content
144 146 With `--rev`
145 147 $ $NO_FALLBACK rhg cat -r 0 original
146 148 original content
147 149 Cat copied file should not display copy metadata
148 150 $ hg copy original copy_of_original
149 151 $ hg commit -m "add copy of original"
150 152 $ $NO_FALLBACK rhg cat original
151 153 original content
152 154 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
153 155 original content
154 156
155 157
156 158 Fallback to Python
157 159 $ $NO_FALLBACK rhg cat original --exclude="*.rs"
158 160 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
159 161
160 162 USAGE:
161 163 rhg cat [OPTIONS] <FILE>...
162 164
163 165 For more information try --help
164 166
165 167 [252]
166 168 $ rhg cat original --exclude="*.rs"
167 169 original content
168 170
169 171 $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE"
170 172 $ unset RHG_FALLBACK_EXECUTABLE
171 173 $ rhg cat original --exclude="*.rs"
172 174 abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
173 175 [255]
174 176 $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE"
175 177 $ export RHG_FALLBACK_EXECUTABLE
176 178
177 179 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=false
178 180 [1]
179 181
180 182 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=hg-non-existent
181 183 tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$
182 184 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
183 185
184 186 USAGE:
185 187 rhg cat [OPTIONS] <FILE>...
186 188
187 189 For more information try --help
188 190
189 191 [252]
190 192
191 193 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=rhg
192 194 Blocking recursive fallback. The 'rhg.fallback-executable = rhg' config points to `rhg` itself.
193 195 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
194 196
195 197 USAGE:
196 198 rhg cat [OPTIONS] <FILE>...
197 199
198 200 For more information try --help
199 201
200 202 [252]
201 203
202 204 Fallback with shell path segments
203 205 $ $NO_FALLBACK rhg cat .
204 206 unsupported feature: `..` or `.` path segment
205 207 [252]
206 208 $ $NO_FALLBACK rhg cat ..
207 209 unsupported feature: `..` or `.` path segment
208 210 [252]
209 211 $ $NO_FALLBACK rhg cat ../..
210 212 unsupported feature: `..` or `.` path segment
211 213 [252]
212 214
213 215 Fallback with filesets
214 216 $ $NO_FALLBACK rhg cat "set:c or b"
215 217 unsupported feature: fileset
216 218 [252]
217 219
218 220 Fallback with generic hooks
219 221 $ $NO_FALLBACK rhg cat original --config hooks.pre-cat=something
220 222 unsupported feature: pre-cat hook defined
221 223 [252]
222 224
223 225 $ $NO_FALLBACK rhg cat original --config hooks.post-cat=something
224 226 unsupported feature: post-cat hook defined
225 227 [252]
226 228
227 229 $ $NO_FALLBACK rhg cat original --config hooks.fail-cat=something
228 230 unsupported feature: fail-cat hook defined
229 231 [252]
230 232
231 233 Fallback with [defaults]
232 234 $ $NO_FALLBACK rhg cat original --config "defaults.cat=-r null"
233 235 unsupported feature: `defaults` config set
234 236 [252]
235 237
236 238
237 239 Requirements
238 240 $ $NO_FALLBACK rhg debugrequirements
239 241 dotencode
240 242 fncache
241 243 generaldelta
242 244 persistent-nodemap
243 245 revlog-compression-zstd (zstd !)
244 246 revlogv1
245 247 sparserevlog
246 248 store
247 249
248 250 $ echo indoor-pool >> .hg/requires
249 251 $ $NO_FALLBACK rhg files
250 252 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
251 253 [252]
252 254
253 255 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
254 256 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
255 257 [252]
256 258
257 259 $ $NO_FALLBACK rhg debugrequirements
258 260 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
259 261 [252]
260 262
261 263 $ echo -e '\xFF' >> .hg/requires
262 264 $ $NO_FALLBACK rhg debugrequirements
263 265 abort: parse error in 'requires' file
264 266 [255]
265 267
266 268 Persistent nodemap
267 269 $ cd $TESTTMP
268 270 $ rm -rf repository
269 271 $ hg --config format.use-persistent-nodemap=no init repository
270 272 $ cd repository
271 273 $ $NO_FALLBACK rhg debugrequirements | grep nodemap
272 274 [1]
273 275 $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn"
274 276 $ hg id -r tip
275 277 c3ae8dec9fad tip
276 278 $ ls .hg/store/00changelog*
277 279 .hg/store/00changelog.d
278 280 .hg/store/00changelog.i
279 281 $ $NO_FALLBACK rhg files -r c3ae8dec9fad
280 282 of
281 283
282 284 $ cd $TESTTMP
283 285 $ rm -rf repository
284 286 $ hg --config format.use-persistent-nodemap=True init repository
285 287 $ cd repository
286 288 $ $NO_FALLBACK rhg debugrequirements | grep nodemap
287 289 persistent-nodemap
288 290 $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn"
289 291 $ hg id -r tip
290 292 c3ae8dec9fad tip
291 293 $ ls .hg/store/00changelog*
292 294 .hg/store/00changelog-*.nd (glob)
293 295 .hg/store/00changelog.d
294 296 .hg/store/00changelog.i
295 297 .hg/store/00changelog.n
296 298
297 299 Specifying revisions by changeset ID
298 300 $ $NO_FALLBACK rhg files -r c3ae8dec9fad
299 301 of
300 302 $ $NO_FALLBACK rhg cat -r c3ae8dec9fad of
301 303 r5000
302 304
303 305 Crate a shared repository
304 306
305 307 $ echo "[extensions]" >> $HGRCPATH
306 308 $ echo "share = " >> $HGRCPATH
307 309
308 310 $ cd $TESTTMP
309 311 $ hg init repo1
310 312 $ echo a > repo1/a
311 313 $ hg -R repo1 commit -A -m'init'
312 314 adding a
313 315
314 316 $ hg share repo1 repo2
315 317 updating working directory
316 318 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
317 319
318 320 And check that basic rhg commands work with sharing
319 321
320 322 $ $NO_FALLBACK rhg files -R repo2
321 323 repo2/a
322 324 $ $NO_FALLBACK rhg -R repo2 cat -r 0 repo2/a
323 325 a
324 326
325 327 Same with relative sharing
326 328
327 329 $ hg share repo2 repo3 --relative
328 330 updating working directory
329 331 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
330 332
331 333 $ $NO_FALLBACK rhg files -R repo3
332 334 repo3/a
333 335 $ $NO_FALLBACK rhg -R repo3 cat -r 0 repo3/a
334 336 a
335 337
336 338 Same with share-safe
337 339
338 340 $ echo "[format]" >> $HGRCPATH
339 341 $ echo "use-share-safe = True" >> $HGRCPATH
340 342
341 343 $ cd $TESTTMP
342 344 $ hg init repo4
343 345 $ cd repo4
344 346 $ echo a > a
345 347 $ hg commit -A -m'init'
346 348 adding a
347 349
348 350 $ cd ..
349 351 $ hg share repo4 repo5
350 352 updating working directory
351 353 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
352 354
353 355 And check that basic rhg commands work with sharing
354 356
355 357 $ cd repo5
356 358 $ $NO_FALLBACK rhg files
357 359 a
358 360 $ $NO_FALLBACK rhg cat -r 0 a
359 361 a
360 362
361 363 The blackbox extension is supported
362 364
363 365 $ echo "[extensions]" >> $HGRCPATH
364 366 $ echo "blackbox =" >> $HGRCPATH
365 367 $ echo "[blackbox]" >> $HGRCPATH
366 368 $ echo "maxsize = 1" >> $HGRCPATH
367 369 $ $NO_FALLBACK rhg files > /dev/null
368 370 $ cat .hg/blackbox.log
369 371 ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files exited 0 after 0.??? seconds (glob)
370 372 $ cat .hg/blackbox.log.1
371 373 ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files (glob)
372 374
373 375 Subrepos are not supported
374 376
375 377 $ touch .hgsub
376 378 $ $NO_FALLBACK rhg files
377 379 unsupported feature: subrepos (.hgsub is present)
378 380 [252]
379 381 $ rhg files
380 382 a
381 383 $ rm .hgsub
General Comments 0
You need to be logged in to leave comments. Login now