rust/rhg/src/commands/status.rs
branchstable
changeset 50442 51041a1a4c59
parent 50441 668a871454e8
child 50460 f57f5ab0e220
equal deleted inserted replaced
50441:668a871454e8 50442:51041a1a4c59
   540     ) -> Result<(), CommandError> {
   540     ) -> Result<(), CommandError> {
   541         paths.sort_unstable();
   541         paths.sort_unstable();
   542         // TODO: get the stdout lock once for the whole loop
   542         // TODO: get the stdout lock once for the whole loop
   543         // instead of in each write
   543         // instead of in each write
   544         for StatusPath { path, copy_source } in paths {
   544         for StatusPath { path, copy_source } in paths {
   545             let relative;
   545             let relative_path;
   546             let path = if let Some(relativize) = &self.relativize {
   546             let relative_source;
   547                 relative = relativize.relativize(&path);
   547             let (path, copy_source) = if let Some(relativize) =
   548                 &*relative
   548                 &self.relativize
       
   549             {
       
   550                 relative_path = relativize.relativize(&path);
       
   551                 relative_source =
       
   552                     copy_source.as_ref().map(|s| relativize.relativize(s));
       
   553                 (&*relative_path, relative_source.as_deref())
   549             } else {
   554             } else {
   550                 path.as_bytes()
   555                 (path.as_bytes(), copy_source.as_ref().map(|s| s.as_bytes()))
   551             };
   556             };
   552             // TODO: Add a way to use `write_bytes!` instead of `format_bytes!`
   557             // TODO: Add a way to use `write_bytes!` instead of `format_bytes!`
   553             // in order to stream to stdout instead of allocating an
   558             // in order to stream to stdout instead of allocating an
   554             // itermediate `Vec<u8>`.
   559             // itermediate `Vec<u8>`.
   555             if !self.no_status {
   560             if !self.no_status {
   558             self.ui
   563             self.ui
   559                 .write_stdout_labelled(&format_bytes!(b"{}\n", path), label)?;
   564                 .write_stdout_labelled(&format_bytes!(b"{}\n", path), label)?;
   560             if let Some(source) = copy_source.filter(|_| !self.no_status) {
   565             if let Some(source) = copy_source.filter(|_| !self.no_status) {
   561                 let label = "status.copied";
   566                 let label = "status.copied";
   562                 self.ui.write_stdout_labelled(
   567                 self.ui.write_stdout_labelled(
   563                     &format_bytes!(b"  {}\n", source.as_bytes()),
   568                     &format_bytes!(b"  {}\n", source),
   564                     label,
   569                     label,
   565                 )?
   570                 )?
   566             }
   571             }
   567         }
   572         }
   568         Ok(())
   573         Ok(())