Show More
@@ -1,84 +1,83 b'' | |||
|
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 | 49 | // TODO: actually normalize `..` path segments etc? |
|
50 | 50 | let normalized = cwd.join(&file); |
|
51 | 51 | let stripped = normalized |
|
52 | 52 | .strip_prefix(&working_directory) |
|
53 | 53 | // TODO: error message for path arguments outside of the repo |
|
54 | 54 | .map_err(|_| CommandError::abort(""))?; |
|
55 | 55 | let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) |
|
56 | 56 | .map_err(|e| CommandError::abort(e.to_string()))?; |
|
57 | 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 { | |
|
61 | Some(rev) => { | |
|
62 | let output = cat(&repo, rev, &files).map_err(|e| (e, rev))?; | |
|
63 | invocation.ui.write_stdout(&output.concatenated)?; | |
|
64 |
|
|
|
65 | let short = format!("{:x}", output.node.short()).into_bytes(); | |
|
66 | for path in &output.missing { | |
|
67 | invocation.ui.write_stderr(&format_bytes!( | |
|
68 | b"{}: no such file in rev {}\n", | |
|
69 | path.as_bytes(), | |
|
70 | short | |
|
71 | ))?; | |
|
72 | } | |
|
73 | } | |
|
74 | if output.found_any { | |
|
75 | Ok(()) | |
|
76 | } else { | |
|
77 | Err(CommandError::Unsuccessful) | |
|
78 | } | |
|
66 | let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?; | |
|
67 | invocation.ui.write_stdout(&output.concatenated)?; | |
|
68 | if !output.missing.is_empty() { | |
|
69 | let short = format!("{:x}", output.node.short()).into_bytes(); | |
|
70 | for path in &output.missing { | |
|
71 | invocation.ui.write_stderr(&format_bytes!( | |
|
72 | b"{}: no such file in rev {}\n", | |
|
73 | path.as_bytes(), | |
|
74 | short | |
|
75 | ))?; | |
|
79 | 76 | } |
|
80 | None => Err(CommandError::unsupported( | |
|
81 | "`rhg cat` without `--rev` / `-r`", | |
|
82 |
)) |
|
|
77 | } | |
|
78 | if output.found_any { | |
|
79 | Ok(()) | |
|
80 | } else { | |
|
81 | Err(CommandError::Unsuccessful) | |
|
83 | 82 | } |
|
84 | 83 | } |
@@ -1,312 +1,337 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 | Without `--rev` | |
|
142 | $ $NO_FALLBACK rhg cat original | |
|
143 | original content | |
|
144 | With `--rev` | |
|
141 | 145 | $ $NO_FALLBACK rhg cat -r 0 original |
|
142 | 146 | original content |
|
143 | 147 | Cat copied file should not display copy metadata |
|
144 | 148 | $ hg copy original copy_of_original |
|
145 | 149 | $ hg commit -m "add copy of original" |
|
150 | $ $NO_FALLBACK rhg cat original | |
|
151 | original content | |
|
146 | 152 | $ $NO_FALLBACK rhg cat -r 1 copy_of_original |
|
147 | 153 | original content |
|
148 | 154 | |
|
155 | ||
|
149 | 156 | Fallback to Python |
|
150 | $ $NO_FALLBACK rhg cat original | |
|
151 | unsupported feature: `rhg cat` without `--rev` / `-r` | |
|
157 | $ $NO_FALLBACK rhg cat original --exclude="*.rs" | |
|
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 | 165 | [252] |
|
153 | $ rhg cat original | |
|
166 | $ rhg cat original --exclude="*.rs" | |
|
154 | 167 | original content |
|
155 | 168 | |
|
156 | 169 | $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE" |
|
157 | 170 | $ unset RHG_FALLBACK_EXECUTABLE |
|
158 | $ rhg cat original | |
|
171 | $ rhg cat original --exclude="*.rs" | |
|
159 | 172 | abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set. |
|
160 | 173 | [255] |
|
161 | 174 | $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE" |
|
162 | 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 | 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 | 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 | 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 | 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 | 200 | [252] |
|
176 | 201 | |
|
177 | 202 | Requirements |
|
178 | 203 | $ $NO_FALLBACK rhg debugrequirements |
|
179 | 204 | dotencode |
|
180 | 205 | fncache |
|
181 | 206 | generaldelta |
|
182 | 207 | persistent-nodemap |
|
183 | 208 | revlog-compression-zstd (zstd !) |
|
184 | 209 | revlogv1 |
|
185 | 210 | sparserevlog |
|
186 | 211 | store |
|
187 | 212 | |
|
188 | 213 | $ echo indoor-pool >> .hg/requires |
|
189 | 214 | $ $NO_FALLBACK rhg files |
|
190 | 215 | unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool |
|
191 | 216 | [252] |
|
192 | 217 | |
|
193 | 218 | $ $NO_FALLBACK rhg cat -r 1 copy_of_original |
|
194 | 219 | unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool |
|
195 | 220 | [252] |
|
196 | 221 | |
|
197 | 222 | $ $NO_FALLBACK rhg debugrequirements |
|
198 | 223 | unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool |
|
199 | 224 | [252] |
|
200 | 225 | |
|
201 | 226 | $ echo -e '\xFF' >> .hg/requires |
|
202 | 227 | $ $NO_FALLBACK rhg debugrequirements |
|
203 | 228 | abort: parse error in 'requires' file |
|
204 | 229 | [255] |
|
205 | 230 | |
|
206 | 231 | Persistent nodemap |
|
207 | 232 | $ cd $TESTTMP |
|
208 | 233 | $ rm -rf repository |
|
209 | 234 | $ hg --config format.use-persistent-nodemap=no init repository |
|
210 | 235 | $ cd repository |
|
211 | 236 | $ $NO_FALLBACK rhg debugrequirements | grep nodemap |
|
212 | 237 | [1] |
|
213 | 238 | $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn" |
|
214 | 239 | $ hg id -r tip |
|
215 | 240 | c3ae8dec9fad tip |
|
216 | 241 | $ ls .hg/store/00changelog* |
|
217 | 242 | .hg/store/00changelog.d |
|
218 | 243 | .hg/store/00changelog.i |
|
219 | 244 | $ $NO_FALLBACK rhg files -r c3ae8dec9fad |
|
220 | 245 | of |
|
221 | 246 | |
|
222 | 247 | $ cd $TESTTMP |
|
223 | 248 | $ rm -rf repository |
|
224 | 249 | $ hg --config format.use-persistent-nodemap=True init repository |
|
225 | 250 | $ cd repository |
|
226 | 251 | $ $NO_FALLBACK rhg debugrequirements | grep nodemap |
|
227 | 252 | persistent-nodemap |
|
228 | 253 | $ hg debugbuilddag .+5000 --overwritten-file --config "storage.revlog.nodemap.mode=warn" |
|
229 | 254 | $ hg id -r tip |
|
230 | 255 | c3ae8dec9fad tip |
|
231 | 256 | $ ls .hg/store/00changelog* |
|
232 | 257 | .hg/store/00changelog-*.nd (glob) |
|
233 | 258 | .hg/store/00changelog.d |
|
234 | 259 | .hg/store/00changelog.i |
|
235 | 260 | .hg/store/00changelog.n |
|
236 | 261 | |
|
237 | 262 | Specifying revisions by changeset ID |
|
238 | 263 | $ $NO_FALLBACK rhg files -r c3ae8dec9fad |
|
239 | 264 | of |
|
240 | 265 | $ $NO_FALLBACK rhg cat -r c3ae8dec9fad of |
|
241 | 266 | r5000 |
|
242 | 267 | |
|
243 | 268 | Crate a shared repository |
|
244 | 269 | |
|
245 | 270 | $ echo "[extensions]" >> $HGRCPATH |
|
246 | 271 | $ echo "share = " >> $HGRCPATH |
|
247 | 272 | |
|
248 | 273 | $ cd $TESTTMP |
|
249 | 274 | $ hg init repo1 |
|
250 | 275 | $ echo a > repo1/a |
|
251 | 276 | $ hg -R repo1 commit -A -m'init' |
|
252 | 277 | adding a |
|
253 | 278 | |
|
254 | 279 | $ hg share repo1 repo2 |
|
255 | 280 | updating working directory |
|
256 | 281 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
257 | 282 | |
|
258 | 283 | And check that basic rhg commands work with sharing |
|
259 | 284 | |
|
260 | 285 | $ $NO_FALLBACK rhg files -R repo2 |
|
261 | 286 | repo2/a |
|
262 | 287 | $ $NO_FALLBACK rhg -R repo2 cat -r 0 repo2/a |
|
263 | 288 | a |
|
264 | 289 | |
|
265 | 290 | Same with relative sharing |
|
266 | 291 | |
|
267 | 292 | $ hg share repo2 repo3 --relative |
|
268 | 293 | updating working directory |
|
269 | 294 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
270 | 295 | |
|
271 | 296 | $ $NO_FALLBACK rhg files -R repo3 |
|
272 | 297 | repo3/a |
|
273 | 298 | $ $NO_FALLBACK rhg -R repo3 cat -r 0 repo3/a |
|
274 | 299 | a |
|
275 | 300 | |
|
276 | 301 | Same with share-safe |
|
277 | 302 | |
|
278 | 303 | $ echo "[format]" >> $HGRCPATH |
|
279 | 304 | $ echo "use-share-safe = True" >> $HGRCPATH |
|
280 | 305 | |
|
281 | 306 | $ cd $TESTTMP |
|
282 | 307 | $ hg init repo4 |
|
283 | 308 | $ cd repo4 |
|
284 | 309 | $ echo a > a |
|
285 | 310 | $ hg commit -A -m'init' |
|
286 | 311 | adding a |
|
287 | 312 | |
|
288 | 313 | $ cd .. |
|
289 | 314 | $ hg share repo4 repo5 |
|
290 | 315 | updating working directory |
|
291 | 316 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
292 | 317 | |
|
293 | 318 | And check that basic rhg commands work with sharing |
|
294 | 319 | |
|
295 | 320 | $ cd repo5 |
|
296 | 321 | $ $NO_FALLBACK rhg files |
|
297 | 322 | a |
|
298 | 323 | $ $NO_FALLBACK rhg cat -r 0 a |
|
299 | 324 | a |
|
300 | 325 | |
|
301 | 326 | The blackbox extension is supported |
|
302 | 327 | |
|
303 | 328 | $ echo "[extensions]" >> $HGRCPATH |
|
304 | 329 | $ echo "blackbox =" >> $HGRCPATH |
|
305 | 330 | $ echo "[blackbox]" >> $HGRCPATH |
|
306 | 331 | $ echo "maxsize = 1" >> $HGRCPATH |
|
307 | 332 | $ $NO_FALLBACK rhg files > /dev/null |
|
308 | 333 | $ cat .hg/blackbox.log |
|
309 | 334 | ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files exited 0 after 0.??? seconds (glob) |
|
310 | 335 | $ cat .hg/blackbox.log.1 |
|
311 | 336 | ????/??/?? ??:??:??.??? * @d3873e73d99ef67873dac33fbcc66268d5d2b6f4 (*)> (rust) files (glob) |
|
312 | 337 |
General Comments 0
You need to be logged in to leave comments.
Login now