annotate rust/rhg/src/commands/files.rs @ 53018:65f6f1fe43ef

rhg-files: use the correct long-form flag for selecting a revision This went unnoticed forever, I guess most users pass in `-r`.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 26 Feb 2025 09:25:53 -0500
parents 393ad2685fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46502
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;
50574
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
diff changeset
2 use crate::ui::{
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
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: 50573
diff changeset
4 };
48492
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
5 use crate::utils::path_utils::RelativizePaths;
46553
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
6 use clap::Arg;
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
7 use hg::filepatterns::parse_pattern_args;
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
8 use hg::matchers::IntersectionMatcher;
50040
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
9 use hg::narrow;
52064
7c105b953ca4 rust-files: separate the listing of files from a revset and a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52062
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: 46136
diff changeset
11 use hg::repo::Repo;
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
12 use hg::utils::files::get_bytes_from_os_str;
50036
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
13 use hg::utils::filter_map_results;
48186
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;
50036
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
15 use rayon::prelude::*;
45384
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
49758
37bc3edef76f rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48492
diff changeset
23 pub fn args() -> clap::Command {
37bc3edef76f rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48492
diff changeset
24 clap::command!("files")
46553
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
25 .arg(
49758
37bc3edef76f rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48492
diff changeset
26 Arg::new("rev")
46553
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
27 .help("search the repository as it is in REV")
49758
37bc3edef76f rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48492
diff changeset
28 .short('r')
53018
65f6f1fe43ef rhg-files: use the correct long-form flag for selecting a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52375
diff changeset
29 .long("rev")
49758
37bc3edef76f rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48492
diff changeset
30 .value_name("REV"),
46553
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
31 )
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
32 .arg(
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
33 Arg::new("file")
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
34 .value_parser(clap::value_parser!(std::ffi::OsString))
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
35 .help("show only these files")
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
36 .action(clap::ArgAction::Append),
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
37 )
46553
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
38 .about(HELP_TEXT)
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
39 }
1ecaf09d9964 rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents: 46552
diff changeset
40
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
41 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
50574
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
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: 50573
diff changeset
43 RelativePaths::Legacy => true,
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
diff changeset
44 RelativePaths::Bool(v) => v,
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
diff changeset
45 };
46752
c184b490da37 rhg: Fall back to Python if ui.relative-paths is configured
Simon Sapin <simon.sapin@octobus.net>
parents: 46632
diff changeset
46
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
47 let args = invocation.subcommand_args;
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
48 let rev = args.get_one::<String>("rev");
45384
5fe25f8ef5d9 rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
49
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
50 let repo = invocation.repo?;
48457
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
diff changeset
51
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
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: 48391
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: 48391
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: 48391
diff changeset
55 // pass.
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
diff changeset
56 if repo.has_sparse()
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
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: 48391
diff changeset
58 {
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
diff changeset
59 return Err(CommandError::unsupported(
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
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: 48391
diff changeset
61 ));
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
diff changeset
62 }
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
diff changeset
63
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
64 let (matcher, narrow_warnings) = narrow::matcher(repo)?;
50041
e57f76c28f7b rhg-files: add support for narrow when specifying a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50040
diff changeset
65 print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?;
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
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: 50574
diff changeset
67 None => matcher,
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
68 Some(files) => {
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
69 let patterns: Vec<Vec<u8>> = files
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
70 .filter(|s| !s.is_empty())
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
71 .map(get_bytes_from_os_str)
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
72 .collect();
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
73 for file in &patterns {
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
74 if file.starts_with(b"set:") {
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
75 return Err(CommandError::unsupported("fileset"));
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
76 }
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
77 }
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
78 let cwd = hg::utils::current_dir()?;
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
79 let root = repo.working_directory_path();
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
80 let ignore_patterns = parse_pattern_args(patterns, &cwd, root)?;
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
81 let files_matcher =
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
82 hg::matchers::PatternMatcher::new(ignore_patterns)?;
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
83 Box::new(IntersectionMatcher::new(
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
84 Box::new(files_matcher),
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
85 matcher,
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
86 ))
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
87 }
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
88 };
50041
e57f76c28f7b rhg-files: add support for narrow when specifying a revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50040
diff changeset
89
46552
184e46550dc8 rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46543
diff changeset
90 if let Some(rev) = rev {
52375
393ad2685fb4 rust: make RevlogError AmbiguousPrefix case contain the actual prefix
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 52064
diff changeset
91 let files = list_revset_tracked_files(repo, rev, matcher)?;
52062
b7d99348ea36 rust-files: also return filenode and flags when listing a revision's files
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50891
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: 50891
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: 50891
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: 50891
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: 50891
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: 50891
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: 50891
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: 50891
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: 50891
diff changeset
100 )
46552
184e46550dc8 rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46543
diff changeset
101 } else {
50040
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
102 // The dirstate always reflects the sparse narrowspec.
50036
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
103 let dirstate = repo.dirstate_map()?;
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
104 let files_res: Result<Vec<_>, _> =
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
105 filter_map_results(dirstate.iter(), |(path, entry)| {
50891
788113f056d4 rhg: support rhg files [FILE]
Spencer Baugh <sbaugh@janestreet.com>
parents: 50574
diff changeset
106 Ok(if entry.tracked() && matcher.matches(path) {
50040
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
107 Some(path)
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
108 } else {
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
109 None
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
110 })
50036
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
111 })
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
112 .collect();
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
113
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
114 let mut files = files_res?;
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
115 files.par_sort_unstable();
95ffa065204e rhg-files: reuse centralized dirstate logic
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50034
diff changeset
116
50040
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
117 display_files(
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
118 invocation.ui,
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
diff changeset
119 repo,
50574
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
diff changeset
120 relative_paths,
50040
df9eabc9837b rust-narrow: enable narrow support for plain `rhg files`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50039
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: 50039
diff changeset
122 )
45384
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 }
45541
72b7d58d6e35 hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45449
diff changeset
125
50039
795b5b01cbd2 rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50036
diff changeset
126 fn display_files<'a, E>(
46552
184e46550dc8 rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46543
diff changeset
127 ui: &Ui,
184e46550dc8 rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46543
diff changeset
128 repo: &Repo,
50574
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
diff changeset
129 relative_paths: bool,
50039
795b5b01cbd2 rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50036
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: 50036
diff changeset
131 ) -> Result<(), CommandError>
795b5b01cbd2 rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50036
diff changeset
132 where
795b5b01cbd2 rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50036
diff changeset
133 CommandError: From<E>,
795b5b01cbd2 rhg-files: make signature of `display_files` more flexible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50036
diff changeset
134 {
46552
184e46550dc8 rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46543
diff changeset
135 let mut stdout = ui.stdout_buffer();
48186
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: 46758
diff changeset
137
48492
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
138 let relativize = RelativizePaths::new(repo)?;
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
139 for result in files {
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
140 let path = result?;
50574
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
diff changeset
141 if relative_paths {
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
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: 50573
diff changeset
143 } else {
9db197c73138 rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50573
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: 50573
diff changeset
145 }
48492
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
146 stdout.write_all(b"\n")?;
48186
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46925
diff changeset
147 any = true;
48492
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
148 }
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48457
diff changeset
149
46552
184e46550dc8 rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46543
diff changeset
150 stdout.flush()?;
46758
63bfcddddac1 rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents: 46753
diff changeset
151 if any {
63bfcddddac1 rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents: 46753
diff changeset
152 Ok(())
63bfcddddac1 rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents: 46753
diff changeset
153 } else {
63bfcddddac1 rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents: 46753
diff changeset
154 Err(CommandError::Unsuccessful)
63bfcddddac1 rhg: Exit with an error code if `files` finds nothing
Simon Sapin <simon.sapin@octobus.net>
parents: 46753
diff changeset
155 }
45543
2f8227a12592 rhg: add `--revision` argument to `rhg files`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45541
diff changeset
156 }