##// END OF EJS Templates
rhg: fallback if `defaults` config is set for the current command...
Raphaël Gomès -
r48890:b44e1184 default
parent child Browse files
Show More
@@ -1,598 +1,606 b''
1 1 extern crate log;
2 2 use crate::ui::Ui;
3 3 use clap::App;
4 4 use clap::AppSettings;
5 5 use clap::Arg;
6 6 use clap::ArgMatches;
7 7 use format_bytes::{format_bytes, join};
8 8 use hg::config::{Config, ConfigSource};
9 9 use hg::exit_codes;
10 10 use hg::repo::{Repo, RepoError};
11 11 use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes};
12 12 use hg::utils::SliceExt;
13 13 use std::ffi::OsString;
14 14 use std::path::PathBuf;
15 15 use std::process::Command;
16 16
17 17 mod blackbox;
18 18 mod error;
19 19 mod ui;
20 20 use error::CommandError;
21 21
22 22 fn main_with_result(
23 23 process_start_time: &blackbox::ProcessStartTime,
24 24 ui: &ui::Ui,
25 25 repo: Result<&Repo, &NoRepoInCwdError>,
26 26 config: &Config,
27 27 ) -> Result<(), CommandError> {
28 28 check_extensions(config)?;
29 29
30 30 let app = App::new("rhg")
31 31 .global_setting(AppSettings::AllowInvalidUtf8)
32 32 .global_setting(AppSettings::DisableVersion)
33 33 .setting(AppSettings::SubcommandRequired)
34 34 .setting(AppSettings::VersionlessSubcommands)
35 35 .arg(
36 36 Arg::with_name("repository")
37 37 .help("repository root directory")
38 38 .short("-R")
39 39 .long("--repository")
40 40 .value_name("REPO")
41 41 .takes_value(true)
42 42 // Both ok: `hg -R ./foo log` or `hg log -R ./foo`
43 43 .global(true),
44 44 )
45 45 .arg(
46 46 Arg::with_name("config")
47 47 .help("set/override config option (use 'section.name=value')")
48 48 .long("--config")
49 49 .value_name("CONFIG")
50 50 .takes_value(true)
51 51 .global(true)
52 52 // Ok: `--config section.key1=val --config section.key2=val2`
53 53 .multiple(true)
54 54 // Not ok: `--config section.key1=val section.key2=val2`
55 55 .number_of_values(1),
56 56 )
57 57 .arg(
58 58 Arg::with_name("cwd")
59 59 .help("change working directory")
60 60 .long("--cwd")
61 61 .value_name("DIR")
62 62 .takes_value(true)
63 63 .global(true),
64 64 )
65 65 .version("0.0.1");
66 66 let app = add_subcommand_args(app);
67 67
68 68 let matches = app.clone().get_matches_safe()?;
69 69
70 70 let (subcommand_name, subcommand_matches) = matches.subcommand();
71 71
72 // Mercurial allows users to define "defaults" for commands, fallback
73 // if a default is detected for the current command
74 let defaults = config.get_str(b"defaults", subcommand_name.as_bytes());
75 if defaults?.is_some() {
76 let msg = "`defaults` config set";
77 return Err(CommandError::unsupported(msg));
78 }
79
72 80 for prefix in ["pre", "post", "fail"].iter() {
73 81 // Mercurial allows users to define generic hooks for commands,
74 82 // fallback if any are detected
75 83 let item = format!("{}-{}", prefix, subcommand_name);
76 84 let hook_for_command = config.get_str(b"hooks", item.as_bytes())?;
77 85 if hook_for_command.is_some() {
78 86 let msg = format!("{}-{} hook defined", prefix, subcommand_name);
79 87 return Err(CommandError::unsupported(msg));
80 88 }
81 89 }
82 90 let run = subcommand_run_fn(subcommand_name)
83 91 .expect("unknown subcommand name from clap despite AppSettings::SubcommandRequired");
84 92 let subcommand_args = subcommand_matches
85 93 .expect("no subcommand arguments from clap despite AppSettings::SubcommandRequired");
86 94
87 95 let invocation = CliInvocation {
88 96 ui,
89 97 subcommand_args,
90 98 config,
91 99 repo,
92 100 };
93 101 let blackbox = blackbox::Blackbox::new(&invocation, process_start_time)?;
94 102 blackbox.log_command_start();
95 103 let result = run(&invocation);
96 104 blackbox.log_command_end(exit_code(
97 105 &result,
98 106 // TODO: show a warning or combine with original error if `get_bool`
99 107 // returns an error
100 108 config
101 109 .get_bool(b"ui", b"detailed-exit-code")
102 110 .unwrap_or(false),
103 111 ));
104 112 result
105 113 }
106 114
107 115 fn main() {
108 116 // Run this first, before we find out if the blackbox extension is even
109 117 // enabled, in order to include everything in-between in the duration
110 118 // measurements. Reading config files can be slow if they’re on NFS.
111 119 let process_start_time = blackbox::ProcessStartTime::now();
112 120
113 121 env_logger::init();
114 122 let ui = ui::Ui::new();
115 123
116 124 let early_args = EarlyArgs::parse(std::env::args_os());
117 125
118 126 let initial_current_dir = early_args.cwd.map(|cwd| {
119 127 let cwd = get_path_from_bytes(&cwd);
120 128 std::env::current_dir()
121 129 .and_then(|initial| {
122 130 std::env::set_current_dir(cwd)?;
123 131 Ok(initial)
124 132 })
125 133 .unwrap_or_else(|error| {
126 134 exit(
127 135 &None,
128 136 &ui,
129 137 OnUnsupported::Abort,
130 138 Err(CommandError::abort(format!(
131 139 "abort: {}: '{}'",
132 140 error,
133 141 cwd.display()
134 142 ))),
135 143 false,
136 144 )
137 145 })
138 146 });
139 147
140 148 let mut non_repo_config =
141 149 Config::load_non_repo().unwrap_or_else(|error| {
142 150 // Normally this is decided based on config, but we don’t have that
143 151 // available. As of this writing config loading never returns an
144 152 // "unsupported" error but that is not enforced by the type system.
145 153 let on_unsupported = OnUnsupported::Abort;
146 154
147 155 exit(
148 156 &initial_current_dir,
149 157 &ui,
150 158 on_unsupported,
151 159 Err(error.into()),
152 160 false,
153 161 )
154 162 });
155 163
156 164 non_repo_config
157 165 .load_cli_args_config(early_args.config)
158 166 .unwrap_or_else(|error| {
159 167 exit(
160 168 &initial_current_dir,
161 169 &ui,
162 170 OnUnsupported::from_config(&ui, &non_repo_config),
163 171 Err(error.into()),
164 172 non_repo_config
165 173 .get_bool(b"ui", b"detailed-exit-code")
166 174 .unwrap_or(false),
167 175 )
168 176 });
169 177
170 178 if let Some(repo_path_bytes) = &early_args.repo {
171 179 lazy_static::lazy_static! {
172 180 static ref SCHEME_RE: regex::bytes::Regex =
173 181 // Same as `_matchscheme` in `mercurial/util.py`
174 182 regex::bytes::Regex::new("^[a-zA-Z0-9+.\\-]+:").unwrap();
175 183 }
176 184 if SCHEME_RE.is_match(&repo_path_bytes) {
177 185 exit(
178 186 &initial_current_dir,
179 187 &ui,
180 188 OnUnsupported::from_config(&ui, &non_repo_config),
181 189 Err(CommandError::UnsupportedFeature {
182 190 message: format_bytes!(
183 191 b"URL-like --repository {}",
184 192 repo_path_bytes
185 193 ),
186 194 }),
187 195 // TODO: show a warning or combine with original error if
188 196 // `get_bool` returns an error
189 197 non_repo_config
190 198 .get_bool(b"ui", b"detailed-exit-code")
191 199 .unwrap_or(false),
192 200 )
193 201 }
194 202 }
195 203 let repo_arg = early_args.repo.unwrap_or(Vec::new());
196 204 let repo_path: Option<PathBuf> = {
197 205 if repo_arg.is_empty() {
198 206 None
199 207 } else {
200 208 let local_config = {
201 209 if std::env::var_os("HGRCSKIPREPO").is_none() {
202 210 // TODO: handle errors from find_repo_root
203 211 if let Ok(current_dir_path) = Repo::find_repo_root() {
204 212 let config_files = vec![
205 213 ConfigSource::AbsPath(
206 214 current_dir_path.join(".hg/hgrc"),
207 215 ),
208 216 ConfigSource::AbsPath(
209 217 current_dir_path.join(".hg/hgrc-not-shared"),
210 218 ),
211 219 ];
212 220 // TODO: handle errors from
213 221 // `load_from_explicit_sources`
214 222 Config::load_from_explicit_sources(config_files).ok()
215 223 } else {
216 224 None
217 225 }
218 226 } else {
219 227 None
220 228 }
221 229 };
222 230
223 231 let non_repo_config_val = {
224 232 let non_repo_val = non_repo_config.get(b"paths", &repo_arg);
225 233 match &non_repo_val {
226 234 Some(val) if val.len() > 0 => home::home_dir()
227 235 .unwrap_or_else(|| PathBuf::from("~"))
228 236 .join(get_path_from_bytes(val))
229 237 .canonicalize()
230 238 // TODO: handle error and make it similar to python
231 239 // implementation maybe?
232 240 .ok(),
233 241 _ => None,
234 242 }
235 243 };
236 244
237 245 let config_val = match &local_config {
238 246 None => non_repo_config_val,
239 247 Some(val) => {
240 248 let local_config_val = val.get(b"paths", &repo_arg);
241 249 match &local_config_val {
242 250 Some(val) if val.len() > 0 => {
243 251 // presence of a local_config assures that
244 252 // current_dir
245 253 // wont result in an Error
246 254 let canpath = hg::utils::current_dir()
247 255 .unwrap()
248 256 .join(get_path_from_bytes(val))
249 257 .canonicalize();
250 258 canpath.ok().or(non_repo_config_val)
251 259 }
252 260 _ => non_repo_config_val,
253 261 }
254 262 }
255 263 };
256 264 config_val.or(Some(get_path_from_bytes(&repo_arg).to_path_buf()))
257 265 }
258 266 };
259 267
260 268 let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned())
261 269 {
262 270 Ok(repo) => Ok(repo),
263 271 Err(RepoError::NotFound { at }) if repo_path.is_none() => {
264 272 // Not finding a repo is not fatal yet, if `-R` was not given
265 273 Err(NoRepoInCwdError { cwd: at })
266 274 }
267 275 Err(error) => exit(
268 276 &initial_current_dir,
269 277 &ui,
270 278 OnUnsupported::from_config(&ui, &non_repo_config),
271 279 Err(error.into()),
272 280 // TODO: show a warning or combine with original error if
273 281 // `get_bool` returns an error
274 282 non_repo_config
275 283 .get_bool(b"ui", b"detailed-exit-code")
276 284 .unwrap_or(false),
277 285 ),
278 286 };
279 287
280 288 let config = if let Ok(repo) = &repo_result {
281 289 repo.config()
282 290 } else {
283 291 &non_repo_config
284 292 };
285 293 let on_unsupported = OnUnsupported::from_config(&ui, config);
286 294
287 295 let result = main_with_result(
288 296 &process_start_time,
289 297 &ui,
290 298 repo_result.as_ref(),
291 299 config,
292 300 );
293 301 exit(
294 302 &initial_current_dir,
295 303 &ui,
296 304 on_unsupported,
297 305 result,
298 306 // TODO: show a warning or combine with original error if `get_bool`
299 307 // returns an error
300 308 config
301 309 .get_bool(b"ui", b"detailed-exit-code")
302 310 .unwrap_or(false),
303 311 )
304 312 }
305 313
306 314 fn exit_code(
307 315 result: &Result<(), CommandError>,
308 316 use_detailed_exit_code: bool,
309 317 ) -> i32 {
310 318 match result {
311 319 Ok(()) => exit_codes::OK,
312 320 Err(CommandError::Abort {
313 321 message: _,
314 322 detailed_exit_code,
315 323 }) => {
316 324 if use_detailed_exit_code {
317 325 *detailed_exit_code
318 326 } else {
319 327 exit_codes::ABORT
320 328 }
321 329 }
322 330 Err(CommandError::Unsuccessful) => exit_codes::UNSUCCESSFUL,
323 331
324 332 // Exit with a specific code and no error message to let a potential
325 333 // wrapper script fallback to Python-based Mercurial.
326 334 Err(CommandError::UnsupportedFeature { .. }) => {
327 335 exit_codes::UNIMPLEMENTED
328 336 }
329 337 }
330 338 }
331 339
332 340 fn exit(
333 341 initial_current_dir: &Option<PathBuf>,
334 342 ui: &Ui,
335 343 mut on_unsupported: OnUnsupported,
336 344 result: Result<(), CommandError>,
337 345 use_detailed_exit_code: bool,
338 346 ) -> ! {
339 347 if let (
340 348 OnUnsupported::Fallback { executable },
341 349 Err(CommandError::UnsupportedFeature { .. }),
342 350 ) = (&on_unsupported, &result)
343 351 {
344 352 let mut args = std::env::args_os();
345 353 let executable_path = get_path_from_bytes(&executable);
346 354 let this_executable = args.next().expect("exepcted argv[0] to exist");
347 355 if executable_path == &PathBuf::from(this_executable) {
348 356 // Avoid spawning infinitely many processes until resource
349 357 // exhaustion.
350 358 let _ = ui.write_stderr(&format_bytes!(
351 359 b"Blocking recursive fallback. The 'rhg.fallback-executable = {}' config \
352 360 points to `rhg` itself.\n",
353 361 executable
354 362 ));
355 363 on_unsupported = OnUnsupported::Abort
356 364 } else {
357 365 // `args` is now `argv[1..]` since we’ve already consumed `argv[0]`
358 366 let mut command = Command::new(executable_path);
359 367 command.args(args);
360 368 if let Some(initial) = initial_current_dir {
361 369 command.current_dir(initial);
362 370 }
363 371 let result = command.status();
364 372 match result {
365 373 Ok(status) => std::process::exit(
366 374 status.code().unwrap_or(exit_codes::ABORT),
367 375 ),
368 376 Err(error) => {
369 377 let _ = ui.write_stderr(&format_bytes!(
370 378 b"tried to fall back to a '{}' sub-process but got error {}\n",
371 379 executable, format_bytes::Utf8(error)
372 380 ));
373 381 on_unsupported = OnUnsupported::Abort
374 382 }
375 383 }
376 384 }
377 385 }
378 386 exit_no_fallback(ui, on_unsupported, result, use_detailed_exit_code)
379 387 }
380 388
381 389 fn exit_no_fallback(
382 390 ui: &Ui,
383 391 on_unsupported: OnUnsupported,
384 392 result: Result<(), CommandError>,
385 393 use_detailed_exit_code: bool,
386 394 ) -> ! {
387 395 match &result {
388 396 Ok(_) => {}
389 397 Err(CommandError::Unsuccessful) => {}
390 398 Err(CommandError::Abort {
391 399 message,
392 400 detailed_exit_code: _,
393 401 }) => {
394 402 if !message.is_empty() {
395 403 // Ignore errors when writing to stderr, we’re already exiting
396 404 // with failure code so there’s not much more we can do.
397 405 let _ = ui.write_stderr(&format_bytes!(b"{}\n", message));
398 406 }
399 407 }
400 408 Err(CommandError::UnsupportedFeature { message }) => {
401 409 match on_unsupported {
402 410 OnUnsupported::Abort => {
403 411 let _ = ui.write_stderr(&format_bytes!(
404 412 b"unsupported feature: {}\n",
405 413 message
406 414 ));
407 415 }
408 416 OnUnsupported::AbortSilent => {}
409 417 OnUnsupported::Fallback { .. } => unreachable!(),
410 418 }
411 419 }
412 420 }
413 421 std::process::exit(exit_code(&result, use_detailed_exit_code))
414 422 }
415 423
416 424 macro_rules! subcommands {
417 425 ($( $command: ident )+) => {
418 426 mod commands {
419 427 $(
420 428 pub mod $command;
421 429 )+
422 430 }
423 431
424 432 fn add_subcommand_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
425 433 app
426 434 $(
427 435 .subcommand(commands::$command::args())
428 436 )+
429 437 }
430 438
431 439 pub type RunFn = fn(&CliInvocation) -> Result<(), CommandError>;
432 440
433 441 fn subcommand_run_fn(name: &str) -> Option<RunFn> {
434 442 match name {
435 443 $(
436 444 stringify!($command) => Some(commands::$command::run),
437 445 )+
438 446 _ => None,
439 447 }
440 448 }
441 449 };
442 450 }
443 451
444 452 subcommands! {
445 453 cat
446 454 debugdata
447 455 debugrequirements
448 456 files
449 457 root
450 458 config
451 459 status
452 460 }
453 461
454 462 pub struct CliInvocation<'a> {
455 463 ui: &'a Ui,
456 464 subcommand_args: &'a ArgMatches<'a>,
457 465 config: &'a Config,
458 466 /// References inside `Result` is a bit peculiar but allow
459 467 /// `invocation.repo?` to work out with `&CliInvocation` since this
460 468 /// `Result` type is `Copy`.
461 469 repo: Result<&'a Repo, &'a NoRepoInCwdError>,
462 470 }
463 471
464 472 struct NoRepoInCwdError {
465 473 cwd: PathBuf,
466 474 }
467 475
468 476 /// CLI arguments to be parsed "early" in order to be able to read
469 477 /// configuration before using Clap. Ideally we would also use Clap for this,
470 478 /// see <https://github.com/clap-rs/clap/discussions/2366>.
471 479 ///
472 480 /// These arguments are still declared when we do use Clap later, so that Clap
473 481 /// does not return an error for their presence.
474 482 struct EarlyArgs {
475 483 /// Values of all `--config` arguments. (Possibly none)
476 484 config: Vec<Vec<u8>>,
477 485 /// Value of the `-R` or `--repository` argument, if any.
478 486 repo: Option<Vec<u8>>,
479 487 /// Value of the `--cwd` argument, if any.
480 488 cwd: Option<Vec<u8>>,
481 489 }
482 490
483 491 impl EarlyArgs {
484 492 fn parse(args: impl IntoIterator<Item = OsString>) -> Self {
485 493 let mut args = args.into_iter().map(get_bytes_from_os_str);
486 494 let mut config = Vec::new();
487 495 let mut repo = None;
488 496 let mut cwd = None;
489 497 // Use `while let` instead of `for` so that we can also call
490 498 // `args.next()` inside the loop.
491 499 while let Some(arg) = args.next() {
492 500 if arg == b"--config" {
493 501 if let Some(value) = args.next() {
494 502 config.push(value)
495 503 }
496 504 } else if let Some(value) = arg.drop_prefix(b"--config=") {
497 505 config.push(value.to_owned())
498 506 }
499 507
500 508 if arg == b"--cwd" {
501 509 if let Some(value) = args.next() {
502 510 cwd = Some(value)
503 511 }
504 512 } else if let Some(value) = arg.drop_prefix(b"--cwd=") {
505 513 cwd = Some(value.to_owned())
506 514 }
507 515
508 516 if arg == b"--repository" || arg == b"-R" {
509 517 if let Some(value) = args.next() {
510 518 repo = Some(value)
511 519 }
512 520 } else if let Some(value) = arg.drop_prefix(b"--repository=") {
513 521 repo = Some(value.to_owned())
514 522 } else if let Some(value) = arg.drop_prefix(b"-R") {
515 523 repo = Some(value.to_owned())
516 524 }
517 525 }
518 526 Self { config, repo, cwd }
519 527 }
520 528 }
521 529
522 530 /// What to do when encountering some unsupported feature.
523 531 ///
524 532 /// See `HgError::UnsupportedFeature` and `CommandError::UnsupportedFeature`.
525 533 enum OnUnsupported {
526 534 /// Print an error message describing what feature is not supported,
527 535 /// and exit with code 252.
528 536 Abort,
529 537 /// Silently exit with code 252.
530 538 AbortSilent,
531 539 /// Try running a Python implementation
532 540 Fallback { executable: Vec<u8> },
533 541 }
534 542
535 543 impl OnUnsupported {
536 544 const DEFAULT: Self = OnUnsupported::Abort;
537 545
538 546 fn from_config(ui: &Ui, config: &Config) -> Self {
539 547 match config
540 548 .get(b"rhg", b"on-unsupported")
541 549 .map(|value| value.to_ascii_lowercase())
542 550 .as_deref()
543 551 {
544 552 Some(b"abort") => OnUnsupported::Abort,
545 553 Some(b"abort-silent") => OnUnsupported::AbortSilent,
546 554 Some(b"fallback") => OnUnsupported::Fallback {
547 555 executable: config
548 556 .get(b"rhg", b"fallback-executable")
549 557 .unwrap_or_else(|| {
550 558 exit_no_fallback(
551 559 ui,
552 560 Self::Abort,
553 561 Err(CommandError::abort(
554 562 "abort: 'rhg.on-unsupported=fallback' without \
555 563 'rhg.fallback-executable' set."
556 564 )),
557 565 false,
558 566 )
559 567 })
560 568 .to_owned(),
561 569 },
562 570 None => Self::DEFAULT,
563 571 Some(_) => {
564 572 // TODO: warn about unknown config value
565 573 Self::DEFAULT
566 574 }
567 575 }
568 576 }
569 577 }
570 578
571 579 const SUPPORTED_EXTENSIONS: &[&[u8]] = &[b"blackbox", b"share"];
572 580
573 581 fn check_extensions(config: &Config) -> Result<(), CommandError> {
574 582 let enabled = config.get_section_keys(b"extensions");
575 583
576 584 let mut unsupported = enabled;
577 585 for supported in SUPPORTED_EXTENSIONS {
578 586 unsupported.remove(supported);
579 587 }
580 588
581 589 if let Some(ignored_list) = config.get_list(b"rhg", b"ignored-extensions")
582 590 {
583 591 for ignored in ignored_list {
584 592 unsupported.remove(ignored.as_slice());
585 593 }
586 594 }
587 595
588 596 if unsupported.is_empty() {
589 597 Ok(())
590 598 } else {
591 599 Err(CommandError::UnsupportedFeature {
592 600 message: format_bytes!(
593 601 b"extensions: {} (consider adding them to 'rhg.ignored-extensions' config)",
594 602 join(unsupported, b", ")
595 603 ),
596 604 })
597 605 }
598 606 }
@@ -1,366 +1,372 b''
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 213 Fallback with filesets
214 214 $ $NO_FALLBACK rhg cat "set:c or b"
215 215 unsupported feature: fileset
216 216 [252]
217 217
218 218 Fallback with generic hooks
219 219 $ $NO_FALLBACK rhg cat original --config hooks.pre-cat=something
220 220 unsupported feature: pre-cat hook defined
221 221 [252]
222 222
223 223 $ $NO_FALLBACK rhg cat original --config hooks.post-cat=something
224 224 unsupported feature: post-cat hook defined
225 225 [252]
226 226
227 227 $ $NO_FALLBACK rhg cat original --config hooks.fail-cat=something
228 228 unsupported feature: fail-cat hook defined
229 229 [252]
230 230
231 Fallback with [defaults]
232 $ $NO_FALLBACK rhg cat original --config "defaults.cat=-r null"
233 unsupported feature: `defaults` config set
234 [252]
235
236
231 237 Requirements
232 238 $ $NO_FALLBACK rhg debugrequirements
233 239 dotencode
234 240 fncache
235 241 generaldelta
236 242 persistent-nodemap
237 243 revlog-compression-zstd (zstd !)
238 244 revlogv1
239 245 sparserevlog
240 246 store
241 247
242 248 $ echo indoor-pool >> .hg/requires
243 249 $ $NO_FALLBACK rhg files
244 250 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
245 251 [252]
246 252
247 253 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
248 254 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
249 255 [252]
250 256
251 257 $ $NO_FALLBACK rhg debugrequirements
252 258 unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool
253 259 [252]
254 260
255 261 $ echo -e '\xFF' >> .hg/requires
256 262 $ $NO_FALLBACK rhg debugrequirements
257 263 abort: parse error in 'requires' file
258 264 [255]
259 265
260 266 Persistent nodemap
261 267 $ cd $TESTTMP
262 268 $ rm -rf repository
263 269 $ hg --config format.use-persistent-nodemap=no init repository
264 270 $ cd repository
265 271 $ $NO_FALLBACK rhg debugrequirements | grep nodemap
266 272 [1]
267 273 $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn"
268 274 $ hg id -r tip
269 275 c3ae8dec9fad tip
270 276 $ ls .hg/store/00changelog*
271 277 .hg/store/00changelog.d
272 278 .hg/store/00changelog.i
273 279 $ $NO_FALLBACK rhg files -r c3ae8dec9fad
274 280 of
275 281
276 282 $ cd $TESTTMP
277 283 $ rm -rf repository
278 284 $ hg --config format.use-persistent-nodemap=True init repository
279 285 $ cd repository
280 286 $ $NO_FALLBACK rhg debugrequirements | grep nodemap
281 287 persistent-nodemap
282 288 $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn"
283 289 $ hg id -r tip
284 290 c3ae8dec9fad tip
285 291 $ ls .hg/store/00changelog*
286 292 .hg/store/00changelog-*.nd (glob)
287 293 .hg/store/00changelog.d
288 294 .hg/store/00changelog.i
289 295 .hg/store/00changelog.n
290 296
291 297 Specifying revisions by changeset ID
292 298 $ $NO_FALLBACK rhg files -r c3ae8dec9fad
293 299 of
294 300 $ $NO_FALLBACK rhg cat -r c3ae8dec9fad of
295 301 r5000
296 302
297 303 Crate a shared repository
298 304
299 305 $ echo "[extensions]" >> $HGRCPATH
300 306 $ echo "share = " >> $HGRCPATH
301 307
302 308 $ cd $TESTTMP
303 309 $ hg init repo1
304 310 $ echo a > repo1/a
305 311 $ hg -R repo1 commit -A -m'init'
306 312 adding a
307 313
308 314 $ hg share repo1 repo2
309 315 updating working directory
310 316 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
311 317
312 318 And check that basic rhg commands work with sharing
313 319
314 320 $ $NO_FALLBACK rhg files -R repo2
315 321 repo2/a
316 322 $ $NO_FALLBACK rhg -R repo2 cat -r 0 repo2/a
317 323 a
318 324
319 325 Same with relative sharing
320 326
321 327 $ hg share repo2 repo3 --relative
322 328 updating working directory
323 329 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
324 330
325 331 $ $NO_FALLBACK rhg files -R repo3
326 332 repo3/a
327 333 $ $NO_FALLBACK rhg -R repo3 cat -r 0 repo3/a
328 334 a
329 335
330 336 Same with share-safe
331 337
332 338 $ echo "[format]" >> $HGRCPATH
333 339 $ echo "use-share-safe = True" >> $HGRCPATH
334 340
335 341 $ cd $TESTTMP
336 342 $ hg init repo4
337 343 $ cd repo4
338 344 $ echo a > a
339 345 $ hg commit -A -m'init'
340 346 adding a
341 347
342 348 $ cd ..
343 349 $ hg share repo4 repo5
344 350 updating working directory
345 351 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
346 352
347 353 And check that basic rhg commands work with sharing
348 354
349 355 $ cd repo5
350 356 $ $NO_FALLBACK rhg files
351 357 a
352 358 $ $NO_FALLBACK rhg cat -r 0 a
353 359 a
354 360
355 361 The blackbox extension is supported
356 362
357 363 $ echo "[extensions]" >> $HGRCPATH
358 364 $ echo "blackbox =" >> $HGRCPATH
359 365 $ echo "[blackbox]" >> $HGRCPATH
360 366 $ echo "maxsize = 1" >> $HGRCPATH
361 367 $ $NO_FALLBACK rhg files > /dev/null
362 368 $ cat .hg/blackbox.log
363 369 ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files exited 0 after 0.??? seconds (glob)
364 370 $ cat .hg/blackbox.log.1
365 371 ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files (glob)
366 372
General Comments 0
You need to be logged in to leave comments. Login now