[PATCH V3] status: add a flag to terse the output (issue4119)

Pulkit Goyal 7895pulkit at gmail.com
Wed Jun 28 22:32:32 EDT 2017


>> Ignored files are not considered while tersing unless -i flag is passed or
>> 'i'
>> is there is the terse flag value.
>
>
> On the other hand (having played a bit locally with this), it's
> surprising that `hg status --terse i` does show ignored files even
> without a `--ignored` flag. In fact the same occurs with `hg status
> --terse c` (shows "clean" files, even without `--clean`) so this is not
> specific to "ignored" files. Is this intended?

Yeah this is intended and I agree it's surprising. I will change it to
consider the ignored files while tersing if `-i` is passed, but don't
show them in status until `--ignored` is there. Same for clean files.
Does it sound good to you?

>> +def tersestatus(root, statlist, status, ignorefn, ignore):
>> +    """
>> +    Returns a list of statuses with directory collapsed if all the files
>> in the
>> +    directory has the same status.
>> +    """
>
> Considering how the function is use in commands.py (stat =
> cmdutil.tersestatus(repo.root, stat, ...)), I think it should return a
> mercurial.scmutil.status instance instead of a plain list for consistency.
>
> Looking at function arguments:
> * "statlist" is not a proper name since this is not a list but a
>    scmutil.status object
> * "status" is misleading as it is actually the value of --terse option.
>
Will fix these.

>> +    indexes = {'m': 0, 'a': 1, 'r': 2, 'd': 3, 'u': 4, 'i': 5, 'c': 6}
>> +    absentdir = absentones(statlist[2], statlist[3])
>> +    finalrs = [[]] * len(indexes)
>> +    didsomethingchanged = False
>> +
>> +    for st in pycompat.bytestr(status):
>> +
>> +        try:
>> +            ind = indexes[st]
>> +        except KeyError:
>> +            # TODO: Need a better error message here
>> +            raise error.Abort("'%s' not recognized" % st)
>> +
>> +        sfiles = statlist[ind]
>
> The code might be easier to follow if "statlist" was queried by
> attribute name instead of relying on tuple indexing.
> For instance:
>
>   statusnames = {'m': 'modified', 'a': 'added', ...}
>   finalrs = scmutil.status([], [], [], [], [], [], [])
>   for st in pycompat.bytestr(status):
>      try:
>         statusname = statusnames[st]
>      except KeyError:
>         raise error.Abort(...)
>      sfiles = getattr(statlist, statusname)
>      rs = getattr(finalrs, statusname)
>      # rs.append()/rs.extend()
>
>
> (Not a big deal, might be improved later.)

Will do this.

>>
>> +      The -t/--terse option abbreviates the output by showing directory
>> name
>> +      if all the files in it share the same status. The option expects a
>> value
>> +      which can be a string formed by using 'm', 'a', 'r', 'd', 'u', 'i',
>> 'c'
>> +      where, 'm' stands for 'modified', 'a' for 'added', 'r' for
>> 'removed',
>> +      'd' for 'deleted', 'u' for 'unknown', 'i' for 'ignored' and 'c' for
>> clean.
>
>
> Might be worth also having a "A" for "all" that'd be symmetrical with
> -A/--all flag to avoid typing `--terse marduic`.

That's a good idea, will do.
>
>> +    if terse:
>> +        stat = cmdutil.tersestatus(repo.root, stat, terse,
>> +                                    repo.dirstate._ignore,
>> opts.get('ignore'))
>
>
> Isn't it opts.get('ignored')?
>
> Also, the last (wrapped) line has an extra leading space.

Ah, I will fix these too.


More information about the Mercurial-devel mailing list