src/topic/revset.py
author Augie Fackler <raf@durin42.com>
Fri, 11 Dec 2015 12:53:20 -0500
changeset 1874 ec28b6c3414a
parent 1870 8dd5200b4086
permissions -rw-r--r--
topic: fix changing topics of commits that have an amend_source Includes a test for this specific case, but we should probably spend more time squinting at the interactions between the current topic wrapper function and commitctx for memctx instances.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
from mercurial import revset
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
     2
from mercurial import util
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
     4
from . import constants, destination
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
     5
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
     6
try:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
     7
    mkmatcher = revset._stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
     8
except AttributeError:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
     9
    mkmatcher = util.stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    10
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
    11
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
def topicset(repo, subset, x):
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
    """`topic([topic])`
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
    Specified topic or all changes with any topic specified.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
    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
    17
    as a regular expression.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    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
    20
    """
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
    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
    22
    if args:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
        # match a specific topic
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
        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
    25
        if topic == '.':
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
    26
            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
    27
        _kind, _pattern, matcher = mkmatcher(topic)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
    else:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
        matcher = lambda t: bool(t)
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
    drafts = subset.filter(lambda r: repo[r].mutable())
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
    31
    return drafts.filter(
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
    32
        lambda r: matcher(repo[r].extra().get(constants.extrakey, '')))
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    34
def ngtipset(repo, subset, x):
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    35
    """`ngtip([branch])`
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    36
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    37
    The untopiced tip.
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    38
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    39
    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
    40
    """
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    41
    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
    42
    # match a specific topic
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    43
    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
    44
    if branch == '.':
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    45
        branch = repo['.'].branch()
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    46
    return subset & destination.ngtip(repo, branch)
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    47
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
def modsetup():
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
    revset.symbols.update({'topic': topicset})
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
    50
    revset.symbols.update({'ngtip': ngtipset})