hgext3rd/topic/revset.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 10 Oct 2017 16:12:44 +0200
branchstable
changeset 3049 02c4a0b550ab
parent 2924 430fb1758d28
child 3156 31493a1b0e39
permissions -rw-r--r--
obsfate: update test The obsfate templatekw and the obsfateprinter behavior was different when displaying or not the current user in obsfate users. Update the test to makes the behavior fix more visible.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1935
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     1
from __future__ import absolute_import
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     2
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     3
from mercurial import (
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
     4
    registrar,
1935
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     5
    revset,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     6
    util,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     7
)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
1935
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
     9
from . import (
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
    10
    constants,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
    11
    destination,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
    12
    stack,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
    13
)
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
    14
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    15
try:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    16
    mkmatcher = revset._stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    17
except AttributeError:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    18
    mkmatcher = util.stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    19
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    20
revsetpredicate = registrar.revsetpredicate()
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    21
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    22
@revsetpredicate('topic([topic])')
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
def topicset(repo, subset, x):
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    24
    """Specified topic or all changes with any topic specified.
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
    If `topic` starts with `re:` the remainder of the name is treated
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
    as a regular expression.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    TODO: make `topic(revset)` work the same as `branch(revset)`.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
    """
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
    args = revset.getargs(x, 0, 1, 'topic takes one or no arguments')
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
    if args:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
        # match a specific topic
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
        topic = revset.getstring(args[0], 'topic() argument must be a string')
1864
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
    35
        if topic == '.':
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
    36
            topic = repo['.'].extra().get('topic', '')
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    37
        _kind, _pattern, matcher = mkmatcher(topic)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
    else:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
        matcher = lambda t: bool(t)
2686
fc3a66ad635b compat: fix topicset for mercurial 4.1
Boris Feld <boris.feld@octobus.net>
parents: 2682
diff changeset
    40
2692
96843c68acc8 topic: directly use the '_notpublic' revset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2686
diff changeset
    41
    mutable = revset._notpublic(repo, revset.fullreposet(repo), ())
2651
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    42
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    43
    rawchange = repo.changelog.changelogrevision
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    44
    key = constants.extrakey
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    45
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    46
    def matchtopic(r):
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    47
        topic = rawchange(r).extra.get(key)
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    48
        if topic is None:
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    49
            return False
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    50
        return matcher(topic)
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
    51
    return (subset & mutable).filter(matchtopic)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    53
@revsetpredicate('ngtip([branch])')
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    54
def ngtipset(repo, subset, x):
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    55
    """The untopiced tip.
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    56
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    57
    Name is horrible so that people change it.
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    58
    """
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    59
    args = revset.getargs(x, 1, 1, 'topic takes one')
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    60
    # match a specific topic
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    61
    branch = revset.getstring(args[0], 'ngtip() argument must be a string')
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    62
    if branch == '.':
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    63
        branch = repo['.'].branch()
1986
042356d5ba59 ngtip: rely on topicmap for 'ngtip'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1943
diff changeset
    64
    return subset & revset.baseset(destination.ngtip(repo, branch))
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    65
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    66
@revsetpredicate('stack()')
1910
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    67
def stackset(repo, subset, x):
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
    68
    """All relevant changes in the current topic,
1910
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    69
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    70
    This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    71
    unstable changeset after there future parent (as if evolve where already
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    72
    run)."""
2681
aa4db71a6224 topics: return a parse error if stack() revset is passed with argument
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2669
diff changeset
    73
    err = 'stack() takes no argument, it works on current topic'
aa4db71a6224 topics: return a parse error if stack() revset is passed with argument
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2669
diff changeset
    74
    revset.getargs(x, 0, 0, err)
1910
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    75
    topic = repo.currenttopic
2669
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
    76
    topic = None
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
    77
    branch = None
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
    78
    if not topic and repo.currenttopic:
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
    79
        topic = repo.currenttopic
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
    80
    if not topic:
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
    81
        branch = repo[None].branch()
2915
b3abdb3d819e stack: replace 'getstack' with direct call to 'stack'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2712
diff changeset
    82
    return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset