##// END OF EJS Templates
rhg: add support for calling `rhg cat` without a revision...
Raphaël Gomès -
r48886:d919b0ca default
parent child Browse files
Show More
@@ -56,29 +56,28 b' pub fn run(invocation: &crate::CliInvoca'
56 .map_err(|e| CommandError::abort(e.to_string()))?;
56 .map_err(|e| CommandError::abort(e.to_string()))?;
57 files.push(hg_file);
57 files.push(hg_file);
58 }
58 }
59 // TODO probably move this to a util function like `repo.default_rev` or
60 // something when it's used somewhere else
61 let rev = match rev {
62 Some(r) => r.to_string(),
63 None => format!("{:x}", repo.dirstate_parents()?.p1),
64 };
59
65
60 match rev {
66 let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?;
61 Some(rev) => {
67 invocation.ui.write_stdout(&output.concatenated)?;
62 let output = cat(&repo, rev, &files).map_err(|e| (e, rev))?;
68 if !output.missing.is_empty() {
63 invocation.ui.write_stdout(&output.concatenated)?;
69 let short = format!("{:x}", output.node.short()).into_bytes();
64 if !output.missing.is_empty() {
70 for path in &output.missing {
65 let short = format!("{:x}", output.node.short()).into_bytes();
71 invocation.ui.write_stderr(&format_bytes!(
66 for path in &output.missing {
72 b"{}: no such file in rev {}\n",
67 invocation.ui.write_stderr(&format_bytes!(
73 path.as_bytes(),
68 b"{}: no such file in rev {}\n",
74 short
69 path.as_bytes(),
75 ))?;
70 short
71 ))?;
72 }
73 }
74 if output.found_any {
75 Ok(())
76 } else {
77 Err(CommandError::Unsuccessful)
78 }
79 }
76 }
80 None => Err(CommandError::unsupported(
77 }
81 "`rhg cat` without `--rev` / `-r`",
78 if output.found_any {
82 )),
79 Ok(())
80 } else {
81 Err(CommandError::Unsuccessful)
83 }
82 }
84 }
83 }
@@ -138,40 +138,65 b' Cat files'
138 $ echo "original content" > original
138 $ echo "original content" > original
139 $ hg add original
139 $ hg add original
140 $ hg commit -m "add original" original
140 $ hg commit -m "add original" original
141 Without `--rev`
142 $ $NO_FALLBACK rhg cat original
143 original content
144 With `--rev`
141 $ $NO_FALLBACK rhg cat -r 0 original
145 $ $NO_FALLBACK rhg cat -r 0 original
142 original content
146 original content
143 Cat copied file should not display copy metadata
147 Cat copied file should not display copy metadata
144 $ hg copy original copy_of_original
148 $ hg copy original copy_of_original
145 $ hg commit -m "add copy of original"
149 $ hg commit -m "add copy of original"
150 $ $NO_FALLBACK rhg cat original
151 original content
146 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
152 $ $NO_FALLBACK rhg cat -r 1 copy_of_original
147 original content
153 original content
148
154
155
149 Fallback to Python
156 Fallback to Python
150 $ $NO_FALLBACK rhg cat original
157 $ $NO_FALLBACK rhg cat original --exclude="*.rs"
151 unsupported feature: `rhg cat` without `--rev` / `-r`
158 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
159
160 USAGE:
161 rhg cat [OPTIONS] <FILE>...
162
163 For more information try --help
164
152 [252]
165 [252]
153 $ rhg cat original
166 $ rhg cat original --exclude="*.rs"
154 original content
167 original content
155
168
156 $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE"
169 $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE"
157 $ unset RHG_FALLBACK_EXECUTABLE
170 $ unset RHG_FALLBACK_EXECUTABLE
158 $ rhg cat original
171 $ rhg cat original --exclude="*.rs"
159 abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
172 abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
160 [255]
173 [255]
161 $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE"
174 $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE"
162 $ export RHG_FALLBACK_EXECUTABLE
175 $ export RHG_FALLBACK_EXECUTABLE
163
176
164 $ rhg cat original --config rhg.fallback-executable=false
177 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=false
165 [1]
178 [1]
166
179
167 $ rhg cat original --config rhg.fallback-executable=hg-non-existent
180 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=hg-non-existent
168 tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$
181 tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$
169 unsupported feature: `rhg cat` without `--rev` / `-r`
182 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
183
184 USAGE:
185 rhg cat [OPTIONS] <FILE>...
186
187 For more information try --help
188
170 [252]
189 [252]
171
190
172 $ rhg cat original --config rhg.fallback-executable=rhg
191 $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=rhg
173 Blocking recursive fallback. The 'rhg.fallback-executable = rhg' config points to `rhg` itself.
192 Blocking recursive fallback. The 'rhg.fallback-executable = rhg' config points to `rhg` itself.
174 unsupported feature: `rhg cat` without `--rev` / `-r`
193 unsupported feature: error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
194
195 USAGE:
196 rhg cat [OPTIONS] <FILE>...
197
198 For more information try --help
199
175 [252]
200 [252]
176
201
177 Requirements
202 Requirements
General Comments 0
You need to be logged in to leave comments. Login now