hgext3rd/topic/revset.py
branchmercurial-4.2
changeset 3001 67b59d1657cf
parent 2924 430fb1758d28
child 3156 31493a1b0e39
equal deleted inserted replaced
2808:f47ed78ab17b 3001:67b59d1657cf
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
     3 from mercurial import (
     3 from mercurial import (
       
     4     registrar,
     4     revset,
     5     revset,
     5     util,
     6     util,
     6 )
     7 )
     7 
     8 
     8 from . import (
     9 from . import (
    14 try:
    15 try:
    15     mkmatcher = revset._stringmatcher
    16     mkmatcher = revset._stringmatcher
    16 except AttributeError:
    17 except AttributeError:
    17     mkmatcher = util.stringmatcher
    18     mkmatcher = util.stringmatcher
    18 
    19 
       
    20 revsetpredicate = registrar.revsetpredicate()
    19 
    21 
       
    22 @revsetpredicate('topic([topic])')
    20 def topicset(repo, subset, x):
    23 def topicset(repo, subset, x):
    21     """`topic([topic])`
    24     """Specified topic or all changes with any topic specified.
    22     Specified topic or all changes with any topic specified.
       
    23 
    25 
    24     If `topic` starts with `re:` the remainder of the name is treated
    26     If `topic` starts with `re:` the remainder of the name is treated
    25     as a regular expression.
    27     as a regular expression.
    26 
    28 
    27     TODO: make `topic(revset)` work the same as `branch(revset)`.
    29     TODO: make `topic(revset)` work the same as `branch(revset)`.
    46         if topic is None:
    48         if topic is None:
    47             return False
    49             return False
    48         return matcher(topic)
    50         return matcher(topic)
    49     return (subset & mutable).filter(matchtopic)
    51     return (subset & mutable).filter(matchtopic)
    50 
    52 
       
    53 @revsetpredicate('ngtip([branch])')
    51 def ngtipset(repo, subset, x):
    54 def ngtipset(repo, subset, x):
    52     """`ngtip([branch])`
    55     """The untopiced tip.
    53 
       
    54     The untopiced tip.
       
    55 
    56 
    56     Name is horrible so that people change it.
    57     Name is horrible so that people change it.
    57     """
    58     """
    58     args = revset.getargs(x, 1, 1, 'topic takes one')
    59     args = revset.getargs(x, 1, 1, 'topic takes one')
    59     # match a specific topic
    60     # match a specific topic
    60     branch = revset.getstring(args[0], 'ngtip() argument must be a string')
    61     branch = revset.getstring(args[0], 'ngtip() argument must be a string')
    61     if branch == '.':
    62     if branch == '.':
    62         branch = repo['.'].branch()
    63         branch = repo['.'].branch()
    63     return subset & revset.baseset(destination.ngtip(repo, branch))
    64     return subset & revset.baseset(destination.ngtip(repo, branch))
    64 
    65 
       
    66 @revsetpredicate('stack()')
    65 def stackset(repo, subset, x):
    67 def stackset(repo, subset, x):
    66     """`stack()`
    68     """All relevant changes in the current topic,
    67     All relevant changes in the current topic,
       
    68 
    69 
    69     This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving
    70     This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving
    70     unstable changeset after there future parent (as if evolve where already
    71     unstable changeset after there future parent (as if evolve where already
    71     run)."""
    72     run)."""
    72     err = 'stack() takes no argument, it works on current topic'
    73     err = 'stack() takes no argument, it works on current topic'
    76     branch = None
    77     branch = None
    77     if not topic and repo.currenttopic:
    78     if not topic and repo.currenttopic:
    78         topic = repo.currenttopic
    79         topic = repo.currenttopic
    79     if not topic:
    80     if not topic:
    80         branch = repo[None].branch()
    81         branch = repo[None].branch()
    81     return revset.baseset(stack.getstack(repo, branch=branch, topic=topic)[1:]) & subset
    82     return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset
    82 
       
    83 
       
    84 def modsetup(ui):
       
    85     revset.symbols.update({'topic': topicset})
       
    86     revset.symbols.update({'ngtip': ngtipset})
       
    87     revset.symbols.update({'stack': stackset})