rust/rhg/src/commands/status.rs
changeset 49439 b07465adbcc8
parent 49374 455fce57e89e
child 49483 b18e877ea304
equal deleted inserted replaced
49438:44d4fd09982f 49439:b07465adbcc8
   102             Arg::with_name("no-status")
   102             Arg::with_name("no-status")
   103                 .help("hide status prefix")
   103                 .help("hide status prefix")
   104                 .short("-n")
   104                 .short("-n")
   105                 .long("--no-status"),
   105                 .long("--no-status"),
   106         )
   106         )
       
   107         .arg(
       
   108             Arg::with_name("verbose")
       
   109                 .help("enable additional output")
       
   110                 .short("-v")
       
   111                 .long("--verbose"),
       
   112         )
   107 }
   113 }
   108 
   114 
   109 /// Pure data type allowing the caller to specify file states to display
   115 /// Pure data type allowing the caller to specify file states to display
   110 #[derive(Copy, Clone, Debug)]
   116 #[derive(Copy, Clone, Debug)]
   111 pub struct DisplayStates {
   117 pub struct DisplayStates {
   148             || self.unknown
   154             || self.unknown
   149             || self.ignored)
   155             || self.ignored)
   150     }
   156     }
   151 }
   157 }
   152 
   158 
       
   159 fn has_unfinished_merge(repo: &Repo) -> Result<bool, CommandError> {
       
   160     return Ok(repo.dirstate_parents()?.is_merge());
       
   161 }
       
   162 
       
   163 fn has_unfinished_state(repo: &Repo) -> Result<bool, CommandError> {
       
   164     // These are all the known values for the [fname] argument of
       
   165     // [addunfinished] function in [state.py]
       
   166     let known_state_files: &[&str] = &[
       
   167         "bisect.state",
       
   168         "graftstate",
       
   169         "histedit-state",
       
   170         "rebasestate",
       
   171         "shelvedstate",
       
   172         "transplant/journal",
       
   173         "updatestate",
       
   174     ];
       
   175     if has_unfinished_merge(repo)? {
       
   176         return Ok(true);
       
   177     };
       
   178     for f in known_state_files {
       
   179         if repo.hg_vfs().join(f).exists() {
       
   180             return Ok(true);
       
   181         }
       
   182     }
       
   183     return Ok(false);
       
   184 }
       
   185 
   153 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
   186 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
   154     // TODO: lift these limitations
   187     // TODO: lift these limitations
   155     if invocation.config.get_bool(b"ui", b"tweakdefaults")? {
   188     if invocation.config.get_bool(b"ui", b"tweakdefaults")? {
   156         return Err(CommandError::unsupported(
   189         return Err(CommandError::unsupported(
   157             "ui.tweakdefaults is not yet supported with rhg status",
   190             "ui.tweakdefaults is not yet supported with rhg status",
   176     let config = invocation.config;
   209     let config = invocation.config;
   177     let args = invocation.subcommand_args;
   210     let args = invocation.subcommand_args;
   178 
   211 
   179     let verbose = !ui.plain(None)
   212     let verbose = !ui.plain(None)
   180         && !args.is_present("print0")
   213         && !args.is_present("print0")
   181         && (config.get_bool(b"ui", b"verbose")?
   214         && (args.is_present("verbose")
       
   215             || config.get_bool(b"ui", b"verbose")?
   182             || config.get_bool(b"commands", b"status.verbose")?);
   216             || config.get_bool(b"commands", b"status.verbose")?);
   183     if verbose {
       
   184         return Err(CommandError::unsupported(
       
   185             "verbose status is not supported yet",
       
   186         ));
       
   187     }
       
   188 
   217 
   189     let all = args.is_present("all");
   218     let all = args.is_present("all");
   190     let display_states = if all {
   219     let display_states = if all {
   191         // TODO when implementing `--quiet`: it excludes clean files
   220         // TODO when implementing `--quiet`: it excludes clean files
   192         // from `--all`
   221         // from `--all`
   211     let list_copies = all
   240     let list_copies = all
   212         || args.is_present("copies")
   241         || args.is_present("copies")
   213         || config.get_bool(b"ui", b"statuscopies")?;
   242         || config.get_bool(b"ui", b"statuscopies")?;
   214 
   243 
   215     let repo = invocation.repo?;
   244     let repo = invocation.repo?;
       
   245 
       
   246     if verbose {
       
   247         if has_unfinished_state(repo)? {
       
   248             return Err(CommandError::unsupported(
       
   249                 "verbose status output is not supported by rhg (and is needed because we're in an unfinished operation)",
       
   250             ));
       
   251         };
       
   252     }
   216 
   253 
   217     if repo.has_sparse() || repo.has_narrow() {
   254     if repo.has_sparse() || repo.has_narrow() {
   218         return Err(CommandError::unsupported(
   255         return Err(CommandError::unsupported(
   219             "rhg status is not supported for sparse checkouts or narrow clones yet"
   256             "rhg status is not supported for sparse checkouts or narrow clones yet"
   220         ));
   257         ));