Mercurial > hg
comparison rust/rhg/src/commands/cat.rs @ 48237:027ebad952ac
rhg: internally, return a structured representation from hg cat
The purpose of this change is to make it possible to support limited templating in `hg cat`, so we could print separators between files etc.
The templating itself is not implemented yet, so this functionality is unused in `rhg cat`.
However, in our fork of hg we're implementing a slightly different command `hg jscat` which makes use of this.
So accepting this change will let us minimize the size of the patch we're maintaining on our side.
Differential Revision: https://phab.mercurial-scm.org/D11679
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Fri, 15 Oct 2021 14:05:20 +0100 |
parents | 6b5773f89183 |
children | 698b70b9e8ea |
comparison
equal
deleted
inserted
replaced
48236:f8dc78716ad2 | 48237:027ebad952ac |
---|---|
64 .map_err(|_| CommandError::abort(""))?; | 64 .map_err(|_| CommandError::abort(""))?; |
65 let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) | 65 let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) |
66 .map_err(|e| CommandError::abort(e.to_string()))?; | 66 .map_err(|e| CommandError::abort(e.to_string()))?; |
67 files.push(hg_file); | 67 files.push(hg_file); |
68 } | 68 } |
69 let files = files.iter().map(|file| file.as_ref()).collect(); | |
69 // TODO probably move this to a util function like `repo.default_rev` or | 70 // TODO probably move this to a util function like `repo.default_rev` or |
70 // something when it's used somewhere else | 71 // something when it's used somewhere else |
71 let rev = match rev { | 72 let rev = match rev { |
72 Some(r) => r.to_string(), | 73 Some(r) => r.to_string(), |
73 None => format!("{:x}", repo.dirstate_parents()?.p1), | 74 None => format!("{:x}", repo.dirstate_parents()?.p1), |
74 }; | 75 }; |
75 | 76 |
76 let output = cat(&repo, &rev, files).map_err(|e| (e, rev.as_str()))?; | 77 let output = cat(&repo, &rev, files).map_err(|e| (e, rev.as_str()))?; |
77 invocation.ui.write_stdout(&output.concatenated)?; | 78 for (_file, contents) in output.results { |
79 invocation.ui.write_stdout(&contents)?; | |
80 } | |
78 if !output.missing.is_empty() { | 81 if !output.missing.is_empty() { |
79 let short = format!("{:x}", output.node.short()).into_bytes(); | 82 let short = format!("{:x}", output.node.short()).into_bytes(); |
80 for path in &output.missing { | 83 for path in &output.missing { |
81 invocation.ui.write_stderr(&format_bytes!( | 84 invocation.ui.write_stderr(&format_bytes!( |
82 b"{}: no such file in rev {}\n", | 85 b"{}: no such file in rev {}\n", |