author | Rapha?l Gom?s <rgomes@octobus.net> |
Wed, 26 Feb 2025 09:25:53 -0500 | |
changeset 53017 | 65f6f1fe43ef |
parent 52343 | 393ad2685fb4 |
permissions | -rw-r--r-- |
46434
3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
1 |
use crate::error::CommandError; |
50537
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
2 |
use crate::ui::{ |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
3 |
print_narrow_sparse_warnings, relative_paths, RelativePaths, Ui, |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
4 |
}; |
48453
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
5 |
use crate::utils::path_utils::RelativizePaths; |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
6 |
use clap::Arg; |
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
7 |
use hg::filepatterns::parse_pattern_args; |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
8 |
use hg::matchers::IntersectionMatcher; |
49984
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
9 |
use hg::narrow; |
52036
7c105b953ca4
rust-files: separate the listing of files from a revset and a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52034
diff
changeset
|
10 |
use hg::operations::list_revset_tracked_files; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
11 |
use hg::repo::Repo; |
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
12 |
use hg::utils::files::get_bytes_from_os_str; |
49980
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
13 |
use hg::utils::filter_map_results; |
48174
9ecf802b06e0
rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46925
diff
changeset
|
14 |
use hg::utils::hg_path::HgPath; |
49980
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
15 |
use rayon::prelude::*; |
45364
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
16 |
|
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
17 |
pub const HELP_TEXT: &str = " |
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
18 |
List tracked files. |
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
19 |
|
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
20 |
Returns 0 on success. |
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
21 |
"; |
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
22 |
|
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48453
diff
changeset
|
23 |
pub fn args() -> clap::Command { |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48453
diff
changeset
|
24 |
clap::command!("files") |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
25 |
.arg( |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48453
diff
changeset
|
26 |
Arg::new("rev") |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
27 |
.help("search the repository as it is in REV") |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48453
diff
changeset
|
28 |
.short('r') |
53017
65f6f1fe43ef
rhg-files: use the correct long-form flag for selecting a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52343
diff
changeset
|
29 |
.long("rev") |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48453
diff
changeset
|
30 |
.value_name("REV"), |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
31 |
) |
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
32 |
.arg( |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
33 |
Arg::new("file") |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
34 |
.value_parser(clap::value_parser!(std::ffi::OsString)) |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
35 |
.help("show only these files") |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
36 |
.action(clap::ArgAction::Append), |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
37 |
) |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
38 |
.about(HELP_TEXT) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
39 |
} |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
40 |
|
46592
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
41 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
50537
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
42 |
let relative_paths = match relative_paths(invocation.config)? { |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
43 |
RelativePaths::Legacy => true, |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
44 |
RelativePaths::Bool(v) => v, |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
45 |
}; |
46739
c184b490da37
rhg: Fall back to Python if ui.relative-paths is configured
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
46 |
|
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
47 |
let args = invocation.subcommand_args; |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
48 |
let rev = args.get_one::<String>("rev"); |
45364
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
49 |
|
46593
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46592
diff
changeset
|
50 |
let repo = invocation.repo?; |
48409
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
51 |
|
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
52 |
// It seems better if this check is removed: this would correspond to |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
53 |
// automatically enabling the extension if the repo requires it. |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
54 |
// However we need this check to be in sync with vanilla hg so hg tests |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
55 |
// pass. |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
56 |
if repo.has_sparse() |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
57 |
&& invocation.config.get(b"extensions", b"sparse").is_none() |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
58 |
{ |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
59 |
return Err(CommandError::unsupported( |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
60 |
"repo is using sparse, but sparse extension is not enabled", |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
61 |
)); |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
62 |
} |
005ae1a343f8
rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48342
diff
changeset
|
63 |
|
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
64 |
let (matcher, narrow_warnings) = narrow::matcher(repo)?; |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49984
diff
changeset
|
65 |
print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?; |
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
66 |
let matcher = match args.get_many::<std::ffi::OsString>("file") { |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
67 |
None => matcher, |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
68 |
Some(files) => { |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
69 |
let patterns: Vec<Vec<u8>> = files |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
70 |
.filter(|s| !s.is_empty()) |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
71 |
.map(get_bytes_from_os_str) |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
72 |
.collect(); |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
73 |
for file in &patterns { |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
74 |
if file.starts_with(b"set:") { |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
75 |
return Err(CommandError::unsupported("fileset")); |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
76 |
} |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
77 |
} |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
78 |
let cwd = hg::utils::current_dir()?; |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
79 |
let root = repo.working_directory_path(); |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
80 |
let ignore_patterns = parse_pattern_args(patterns, &cwd, root)?; |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
81 |
let files_matcher = |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
82 |
hg::matchers::PatternMatcher::new(ignore_patterns)?; |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
83 |
Box::new(IntersectionMatcher::new( |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
84 |
Box::new(files_matcher), |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
85 |
matcher, |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
86 |
)) |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
87 |
} |
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
88 |
}; |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49984
diff
changeset
|
89 |
|
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
90 |
if let Some(rev) = rev { |
52343
393ad2685fb4
rust: make RevlogError AmbiguousPrefix case contain the actual prefix
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
52036
diff
changeset
|
91 |
let files = list_revset_tracked_files(repo, rev, matcher)?; |
52034
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
92 |
display_files( |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
93 |
invocation.ui, |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
94 |
repo, |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
95 |
relative_paths, |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
96 |
files.iter().map::<Result<_, CommandError>, _>(|f| { |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
97 |
let (f, _, _) = f?; |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
98 |
Ok(f) |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
99 |
}), |
b7d99348ea36
rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50864
diff
changeset
|
100 |
) |
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
101 |
} else { |
49984
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
102 |
// The dirstate always reflects the sparse narrowspec. |
49980
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
103 |
let dirstate = repo.dirstate_map()?; |
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
104 |
let files_res: Result<Vec<_>, _> = |
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
105 |
filter_map_results(dirstate.iter(), |(path, entry)| { |
50864
788113f056d4
rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents:
50537
diff
changeset
|
106 |
Ok(if entry.tracked() && matcher.matches(path) { |
49984
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
107 |
Some(path) |
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
108 |
} else { |
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
109 |
None |
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
110 |
}) |
49980
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
111 |
}) |
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
112 |
.collect(); |
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
113 |
|
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
114 |
let mut files = files_res?; |
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
115 |
files.par_sort_unstable(); |
95ffa065204e
rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49978
diff
changeset
|
116 |
|
49984
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
117 |
display_files( |
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
118 |
invocation.ui, |
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
119 |
repo, |
50537
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
120 |
relative_paths, |
49984
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
121 |
files.into_iter().map::<Result<_, CommandError>, _>(Ok), |
df9eabc9837b
rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49983
diff
changeset
|
122 |
) |
45364
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
123 |
} |
5fe25f8ef5d9
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
124 |
} |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45438
diff
changeset
|
125 |
|
49983
795b5b01cbd2
rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49980
diff
changeset
|
126 |
fn display_files<'a, E>( |
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
127 |
ui: &Ui, |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
128 |
repo: &Repo, |
50537
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
129 |
relative_paths: bool, |
49983
795b5b01cbd2
rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49980
diff
changeset
|
130 |
files: impl IntoIterator<Item = Result<&'a HgPath, E>>, |
795b5b01cbd2
rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49980
diff
changeset
|
131 |
) -> Result<(), CommandError> |
795b5b01cbd2
rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49980
diff
changeset
|
132 |
where |
795b5b01cbd2
rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49980
diff
changeset
|
133 |
CommandError: From<E>, |
795b5b01cbd2
rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49980
diff
changeset
|
134 |
{ |
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
135 |
let mut stdout = ui.stdout_buffer(); |
48174
9ecf802b06e0
rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46925
diff
changeset
|
136 |
let mut any = false; |
46925
b5e8bf10436e
rhg: Make `files` work on repo-relative paths when possible
Simon Sapin <simon.sapin@octobus.net>
parents:
46745
diff
changeset
|
137 |
|
48453
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
138 |
let relativize = RelativizePaths::new(repo)?; |
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
139 |
for result in files { |
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
140 |
let path = result?; |
50537
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
141 |
if relative_paths { |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
142 |
stdout.write_all(&relativize.relativize(path))?; |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
143 |
} else { |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
144 |
stdout.write_all(path.as_bytes())?; |
9db197c73138
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50536
diff
changeset
|
145 |
} |
48453
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
146 |
stdout.write_all(b"\n")?; |
48174
9ecf802b06e0
rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46925
diff
changeset
|
147 |
any = true; |
48453
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
148 |
} |
9b0e1f64656f
rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents:
48409
diff
changeset
|
149 |
|
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
150 |
stdout.flush()?; |
46745
63bfcddddac1
rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents:
46740
diff
changeset
|
151 |
if any { |
63bfcddddac1
rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents:
46740
diff
changeset
|
152 |
Ok(()) |
63bfcddddac1
rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents:
46740
diff
changeset
|
153 |
} else { |
63bfcddddac1
rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents:
46740
diff
changeset
|
154 |
Err(CommandError::Unsuccessful) |
63bfcddddac1
rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents:
46740
diff
changeset
|
155 |
} |
45537
2f8227a12592
rhg: add `--revision` argument to `rhg files`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
156 |
} |