D11377: rhg: add support for calling `rhg cat` without a revision
Alphare (Raphaël Gomès)
phabricator at mercurial-scm.org
Wed Sep 1 16:42:59 UTC 2021
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
Turns out the necessary pieces were there already.
Like the Python implementation, we default to the first parent of the dirstate.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D11377
AFFECTED FILES
rust/rhg/src/commands/cat.rs
tests/test-rhg.t
CHANGE DETAILS
diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -135,40 +135,65 @@
$ echo "original content" > original
$ hg add original
$ hg commit -m "add original" original
+Without `--rev`
+ $ $NO_FALLBACK rhg cat original
+ original content
+With `--rev`
$ $NO_FALLBACK rhg cat -r 0 original
original content
Cat copied file should not display copy metadata
$ hg copy original copy_of_original
$ hg commit -m "add copy of original"
+ $ $NO_FALLBACK rhg cat original
+ original content
$ $NO_FALLBACK rhg cat -r 1 copy_of_original
original content
+
Fallback to Python
- $ $NO_FALLBACK rhg cat original
- unsupported feature: `rhg cat` without `--rev` / `-r`
+ $ $NO_FALLBACK rhg cat original --exclude="*.rs"
+ unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
+
+ USAGE:
+ rhg cat [OPTIONS] <FILE>...
+
+ For more information try --help
+
[252]
- $ rhg cat original
+ $ rhg cat original --exclude="*.rs"
original content
$ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE"
$ unset RHG_FALLBACK_EXECUTABLE
- $ rhg cat original
+ $ rhg cat original --exclude="*.rs"
abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
[255]
$ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE"
$ export RHG_FALLBACK_EXECUTABLE
- $ rhg cat original --config rhg.fallback-executable=false
+ $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=false
[1]
- $ rhg cat original --config rhg.fallback-executable=hg-non-existent
+ $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=hg-non-existent
tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$
- unsupported feature: `rhg cat` without `--rev` / `-r`
+ unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
+
+ USAGE:
+ rhg cat [OPTIONS] <FILE>...
+
+ For more information try --help
+
[252]
- $ rhg cat original --config rhg.fallback-executable=rhg
+ $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=rhg
Blocking recursive fallback. The 'rhg.fallback-executable = rhg' config points to `rhg` itself.
- unsupported feature: `rhg cat` without `--rev` / `-r`
+ unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
+
+ USAGE:
+ rhg cat [OPTIONS] <FILE>...
+
+ For more information try --help
+
[252]
Requirements
diff --git a/rust/rhg/src/commands/cat.rs b/rust/rhg/src/commands/cat.rs
--- a/rust/rhg/src/commands/cat.rs
+++ b/rust/rhg/src/commands/cat.rs
@@ -56,29 +56,28 @@
.map_err(|e| CommandError::abort(e.to_string()))?;
files.push(hg_file);
}
+ // TODO probably move this to a util function like `repo.default_rev` or
+ // something when it's used somewhere else
+ let rev = match rev {
+ Some(r) => r.to_string(),
+ None => format!("{:x}", repo.dirstate_parents()?.p1),
+ };
- match rev {
- Some(rev) => {
- let output = cat(&repo, rev, &files).map_err(|e| (e, rev))?;
- invocation.ui.write_stdout(&output.concatenated)?;
- if !output.missing.is_empty() {
- let short = format!("{:x}", output.node.short()).into_bytes();
- for path in &output.missing {
- invocation.ui.write_stderr(&format_bytes!(
- b"{}: no such file in rev {}\n",
- path.as_bytes(),
- short
- ))?;
- }
- }
- if output.found_any {
- Ok(())
- } else {
- Err(CommandError::Unsuccessful)
- }
+ let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?;
+ invocation.ui.write_stdout(&output.concatenated)?;
+ if !output.missing.is_empty() {
+ let short = format!("{:x}", output.node.short()).into_bytes();
+ for path in &output.missing {
+ invocation.ui.write_stderr(&format_bytes!(
+ b"{}: no such file in rev {}\n",
+ path.as_bytes(),
+ short
+ ))?;
}
- None => Err(CommandError::unsupported(
- "`rhg cat` without `--rev` / `-r`",
- )),
+ }
+ if output.found_any {
+ Ok(())
+ } else {
+ Err(CommandError::Unsuccessful)
}
}
To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list