[PATCH 1 of 3] cmdutil: add a function to terse the status

Pulkit Goyal 7895pulkit at gmail.com
Thu Jun 15 10:06:15 EDT 2017


On Thu, Jun 15, 2017 at 2:32 AM, Pulkit Goyal <7895pulkit at gmail.com> wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1497462524 -19800
> #      Wed Jun 14 23:18:44 2017 +0530
> # Node ID 622220c3eb0a6ae2f0e7dfc94ac103ad4bfc53aa
> # Parent  f12a51d828c6bac3ed7683bd07f7d04232727da5
> cmdutil: add a function to terse the status
>
> This function will be used to terse the output of `hg status`. It collapses a
> directory if all the files (except ignored) shares the same status and consider
> ignored ones when ignore is passed through either terse or normally. A further
> patch will add tests which will make things clearer.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -402,6 +402,115 @@
>
>      return commit(ui, repo, recordinwlock, pats, opts)
>
> +def tersestatus(repo, statlist, status, ignore):
> +    """
> +    Returns a list of statuses with directory collapsed if all the files in the
> +    directory has the same status.
> +    """
> +
> +    def numfiles(dirname):
> +        """
> +        Calculates the number of tracked files in a given directory which also
> +        includes files which were removed or deleted. Considers ignored files
> +        if ignore argument is True or 'i' is present in status argument.
> +        """
> +        if 'i' in status or ignore:
> +            def match(fname):
> +                return False
> +        else:
> +            match = repo.dirstate._ignore
> +        lendir = 0
> +        abspath = repo.root + pycompat.ossep + dirname
> +        for f in os.listdir(abspath):

While testing more, I found that this can raise OSError if the abspath
is a directory which is removed or deleted. I will include that in a
v2 if required or else do a followup.


More information about the Mercurial-devel mailing list