Mercurial > forks > mercurial
changeset 53265:2e74d2b6306c default
rhg: support -0 flag in `rhg files`
author | Arun Kulshreshtha <akulshreshtha@janestreet.com> |
---|---|
date | Tue, 20 May 2025 13:26:19 -0400 |
parents | d4d5b413543a |
children | |
files | rust/rhg/src/commands/files.rs tests/test-rhg.t |
diffstat | 2 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/rhg/src/commands/files.rs Wed Mar 26 12:19:19 2025 +0100 +++ b/rust/rhg/src/commands/files.rs Tue May 20 13:26:19 2025 -0400 @@ -35,6 +35,14 @@ .help("show only these files") .action(clap::ArgAction::Append), ) + .arg( + Arg::new("print0") + .required(false) + .short('0') + .long("print0") + .action(clap::ArgAction::SetTrue) + .help("end filenames with NUL, for use with xargs"), + ) .about(HELP_TEXT) } @@ -47,6 +55,11 @@ let args = invocation.subcommand_args; let rev = args.get_one::<String>("rev"); + let delimiter = if args.get_flag("print0") { + b"\0" + } else { + b"\n" + }; let repo = invocation.repo?; @@ -94,6 +107,7 @@ invocation.ui, repo, relative_paths, + delimiter, files.iter().map::<Result<_, CommandError>, _>(|f| { let (f, _, _) = f?; Ok(f) @@ -119,6 +133,7 @@ invocation.ui, repo, relative_paths, + delimiter, files.into_iter().map::<Result<_, CommandError>, _>(Ok), ) } @@ -128,6 +143,7 @@ ui: &Ui, repo: &Repo, relative_paths: bool, + delimiter: &[u8], files: impl IntoIterator<Item = Result<&'a HgPath, E>>, ) -> Result<(), CommandError> where @@ -144,7 +160,7 @@ } else { stdout.write_all(path.as_bytes())?; } - stdout.write_all(b"\n")?; + stdout.write_all(delimiter)?; any = true; }
--- a/tests/test-rhg.t Wed Mar 26 12:19:19 2025 +0100 +++ b/tests/test-rhg.t Tue May 20 13:26:19 2025 -0400 @@ -112,6 +112,12 @@ file2 file3 +Listing tracked files with NUL delimiters. + $ $NO_FALLBACK rhg files -0 | xargs -0n1 + file1 + file2 + file3 + Listing tracked files from subdirectory $ mkdir -p path/to/directory $ cd path/to/directory