[PATCH 4 of 4] revset: extract function that validates sort() arguments

Martin von Zweigbergk martinvonz at google.com
Thu Jun 16 11:47:08 EDT 2016


On Thu, Jun 16, 2016 at 6:35 AM, Martijn Pieters <mj at zopatista.com> wrote:
> On 15 June 2016 at 14:42, Yuya Nishihara <yuya at tcha.org> wrote:
>> # HG changeset patch
>> # User Yuya Nishihara <yuya at tcha.org>
>> # Date 1465607869 -32400
>> #      Sat Jun 11 10:17:49 2016 +0900
>> # Node ID 3c4f66dd14659be71eb26ce77da991cb2a1babe8
>> # Parent  daaf43a9a70c5b62652b864b6c2f440ac58a2215
>> revset: extract function that validates sort() arguments
>>
>> This function will be used in _optimize() to get rid of noop sort() call while
>> validating its arguments.
>>
>> diff --git a/mercurial/revset.py b/mercurial/revset.py
>> --- a/mercurial/revset.py
>> +++ b/mercurial/revset.py
>> @@ -1843,25 +1843,8 @@ def roots(repo, subset, x):
>>      'date': lambda c: c.date()[0],
>>  }
>>
>> - at predicate('sort(set[, [-]key... [, ...]])', safe=True)
>> -def sort(repo, subset, x):
>> -    """Sort set by keys. The default sort order is ascending, specify a key
>> -    as ``-key`` to sort in descending order.
>> -
>> -    The keys can be:
>> -
>> -    - ``rev`` for the revision number,
>> -    - ``branch`` for the branch name,
>> -    - ``desc`` for the commit message (description),
>> -    - ``user`` for user name (``author`` can be used as an alias),
>> -    - ``date`` for the commit date
>> -    - ``topo`` for a reverse topographical sort
>> -
>> -    The ``topo`` sort order cannot be combined with other sort keys. This sort
>> -    takes one optional argument, ``topo.firstbranch``, which takes a revset that
>> -    specifies what topographical branches to prioritize in the sort.
>> -
>> -    """
>> +def _getsortargs(x):
>> +    """Parse sort options into (set, [(key, reverse)], opts)"""
>>      args = getargsdict(x, 'sort', 'set keys topo.firstbranch')
>>      if 'set' not in args:
>>          # i18n: "sort" is a keyword
>> @@ -1896,7 +1879,28 @@ def sort(repo, subset, x):
>>                  'topo.firstbranch can only be used when using the topo sort '
>>                  'key'))
>>
>> -    s = args['set']
>> +    return args['set'], keyflags, opts
>> +
>> + at predicate('sort(set[, [-]key... [, ...]])', safe=True)
>> +def sort(repo, subset, x):
>> +    """Sort set by keys. The default sort order is ascending, specify a key
>> +    as ``-key`` to sort in descending order.
>> +
>> +    The keys can be:
>> +
>> +    - ``rev`` for the revision number,
>> +    - ``branch`` for the branch name,
>> +    - ``desc`` for the commit message (description),
>> +    - ``user`` for user name (``author`` can be used as an alias),
>> +    - ``date`` for the commit date
>> +    - ``topo`` for a reverse topographical sort
>> +
>> +    The ``topo`` sort order cannot be combined with other sort keys. This sort
>> +    takes one optional argument, ``topo.firstbranch``, which takes a revset that
>> +    specifies what topographical branches to prioritize in the sort.
>> +
>> +    """
>> +    s, keyflags, opts = _getsortargs(x)
>>      revs = getset(repo, subset, s)
>>
>>      if not keyflags:
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at mercurial-scm.org
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
> This whole series looks great to me. Thanks for doing this!

I agree. Pushed to the committed repo, thanks.

>
> --
> Martijn Pieters
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list