rust/rhg/src/commands/status.rs
changeset 48452 2afaa0145584
parent 48451 4a983b69e519
child 48453 9b0e1f64656f
equal deleted inserted replaced
48451:4a983b69e519 48452:2afaa0145584
   253                 }
   253                 }
   254                 fixup.push(to_check.into_owned())
   254                 fixup.push(to_check.into_owned())
   255             }
   255             }
   256         }
   256         }
   257     }
   257     }
       
   258     let relative_paths = (!ui.plain())
       
   259         && config
       
   260             .get_option(b"commands", b"status.relative")?
       
   261             .unwrap_or(config.get_bool(b"ui", b"relative-paths")?);
       
   262     let output = DisplayStatusPaths {
       
   263         ui,
       
   264         repo,
       
   265         no_status,
       
   266         relative_paths,
       
   267     };
   258     if display_states.modified {
   268     if display_states.modified {
   259         display_status_paths(
   269         output.display(b"M", ds_status.modified)?;
   260             ui,
       
   261             repo,
       
   262             config,
       
   263             no_status,
       
   264             &mut ds_status.modified,
       
   265             b"M",
       
   266         )?;
       
   267     }
   270     }
   268     if display_states.added {
   271     if display_states.added {
   269         display_status_paths(
   272         output.display(b"A", ds_status.added)?;
   270             ui,
       
   271             repo,
       
   272             config,
       
   273             no_status,
       
   274             &mut ds_status.added,
       
   275             b"A",
       
   276         )?;
       
   277     }
   273     }
   278     if display_states.removed {
   274     if display_states.removed {
   279         display_status_paths(
   275         output.display(b"R", ds_status.removed)?;
   280             ui,
       
   281             repo,
       
   282             config,
       
   283             no_status,
       
   284             &mut ds_status.removed,
       
   285             b"R",
       
   286         )?;
       
   287     }
   276     }
   288     if display_states.deleted {
   277     if display_states.deleted {
   289         display_status_paths(
   278         output.display(b"!", ds_status.deleted)?;
   290             ui,
       
   291             repo,
       
   292             config,
       
   293             no_status,
       
   294             &mut ds_status.deleted,
       
   295             b"!",
       
   296         )?;
       
   297     }
   279     }
   298     if display_states.unknown {
   280     if display_states.unknown {
   299         display_status_paths(
   281         output.display(b"?", ds_status.unknown)?;
   300             ui,
       
   301             repo,
       
   302             config,
       
   303             no_status,
       
   304             &mut ds_status.unknown,
       
   305             b"?",
       
   306         )?;
       
   307     }
   282     }
   308     if display_states.ignored {
   283     if display_states.ignored {
   309         display_status_paths(
   284         output.display(b"I", ds_status.ignored)?;
   310             ui,
       
   311             repo,
       
   312             config,
       
   313             no_status,
       
   314             &mut ds_status.ignored,
       
   315             b"I",
       
   316         )?;
       
   317     }
   285     }
   318     if display_states.clean {
   286     if display_states.clean {
   319         display_status_paths(
   287         output.display(b"C", ds_status.clean)?;
   320             ui,
       
   321             repo,
       
   322             config,
       
   323             no_status,
       
   324             &mut ds_status.clean,
       
   325             b"C",
       
   326         )?;
       
   327     }
   288     }
   328 
   289 
   329     let mut dirstate_write_needed = ds_status.dirty;
   290     let mut dirstate_write_needed = ds_status.dirty;
   330     let filesystem_time_at_status_start = ds_status
   291     let filesystem_time_at_status_start = ds_status
   331         .filesystem_time_at_status_start
   292         .filesystem_time_at_status_start
   414         }
   375         }
   415     }
   376     }
   416     ignore_files
   377     ignore_files
   417 }
   378 }
   418 
   379 
   419 // Probably more elegant to use a Deref or Borrow trait rather than
   380 struct DisplayStatusPaths<'a> {
   420 // harcode HgPathBuf, but probably not really useful at this point
   381     ui: &'a Ui,
   421 fn display_status_paths(
   382     repo: &'a Repo,
   422     ui: &Ui,
       
   423     repo: &Repo,
       
   424     config: &Config,
       
   425     no_status: bool,
   383     no_status: bool,
   426     paths: &mut [HgPathCow],
   384     relative_paths: bool,
   427     status_prefix: &[u8],
   385 }
   428 ) -> Result<(), CommandError> {
   386 
   429     paths.sort_unstable();
   387 impl DisplayStatusPaths<'_> {
   430     let mut relative: bool = config.get_bool(b"ui", b"relative-paths")?;
   388     // Probably more elegant to use a Deref or Borrow trait rather than
   431     relative = config
   389     // harcode HgPathBuf, but probably not really useful at this point
   432         .get_option(b"commands", b"status.relative")?
   390     fn display(
   433         .unwrap_or(relative);
   391         &self,
   434     let print_path = |path: &[u8]| {
   392         status_prefix: &[u8],
   435         // TODO optim, probably lots of unneeded copies here, especially
   393         mut paths: Vec<HgPathCow>,
   436         // if out stream is buffered
   394     ) -> Result<(), CommandError> {
   437         if no_status {
   395         paths.sort_unstable();
   438             ui.write_stdout(&format_bytes!(b"{}\n", path))
   396         let print_path = |path: &[u8]| {
       
   397             // TODO optim, probably lots of unneeded copies here, especially
       
   398             // if out stream is buffered
       
   399             if self.no_status {
       
   400                 self.ui.write_stdout(&format_bytes!(b"{}\n", path))
       
   401             } else {
       
   402                 self.ui.write_stdout(&format_bytes!(
       
   403                     b"{} {}\n",
       
   404                     status_prefix,
       
   405                     path
       
   406                 ))
       
   407             }
       
   408         };
       
   409 
       
   410         if self.relative_paths {
       
   411             relativize_paths(self.repo, paths.iter().map(Ok), |path| {
       
   412                 print_path(&path)
       
   413             })?;
   439         } else {
   414         } else {
   440             ui.write_stdout(&format_bytes!(b"{} {}\n", status_prefix, path))
   415             for path in paths {
   441         }
   416                 print_path(path.as_bytes())?
   442     };
   417             }
   443 
   418         }
   444     if relative && !ui.plain() {
   419         Ok(())
   445         relativize_paths(repo, paths.iter().map(Ok), |path| {
   420     }
   446             print_path(&path)
       
   447         })?;
       
   448     } else {
       
   449         for path in paths {
       
   450             print_path(path.as_bytes())?
       
   451         }
       
   452     }
       
   453     Ok(())
       
   454 }
   421 }
   455 
   422 
   456 /// Check if a file is modified by comparing actual repo store and file system.
   423 /// Check if a file is modified by comparing actual repo store and file system.
   457 ///
   424 ///
   458 /// This meant to be used for those that the dirstate cannot resolve, due
   425 /// This meant to be used for those that the dirstate cannot resolve, due