tests/printrevset.py
author Yuya Nishihara <yuya@tcha.org>
Sat, 12 Sep 2020 21:06:16 +0900
changeset 45565 c1d0f83d62c4
parent 45564 a717de1cb624
child 48875 6000f5b25c9b
permissions -rw-r--r--
log: introduce struct that carries log traversal options I tried to refactor logcmdutil.getrevs() without using an options struct, but none of these attempts didn't work out. Since every stage of getrevs() needs various log command options (e.g. both matcher and revset query need file patterns), it isn't possible to cleanly split getrevs() into a command layer and a core logic. So, this patch introduces a named struct to carry command options in slightly abstracted way, which will be later used by "hg grep" and "hg churn". More fields will be added to the walkopt struct. Type hints aren't verified. I couldn't figure out how to teach pytype to load its own attr type stubs in place of our .thirdparty.attr. Conditional import didn't work. s/^from \.thirdparty // is the only way I found pytype could parse the @attr.ib decorator.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
from __future__ import absolute_import
45565
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
     2
from mercurial.thirdparty import attr
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
from mercurial import (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
     4
    cmdutil,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
     5
    commands,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
     6
    extensions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
     7
    logcmdutil,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
     8
    revsetlang,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
     9
    smartset,
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
)
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    12
from mercurial.utils import stringutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    13
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
45565
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    15
def logrevset(repo, wopts):
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    16
    revs = logcmdutil._initialrevs(repo, wopts)
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
    if not revs:
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
        return None
45565
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    19
    match, pats, slowpath = logcmdutil._makematcher(repo, revs, wopts)
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    20
    wopts = attr.evolve(wopts, pats=pats)
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    21
    return logcmdutil._makerevset(repo, wopts, slowpath)
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    23
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
def uisetup(ui):
45565
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    25
    def printrevset(orig, repo, wopts):
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    26
        revs, filematcher = orig(repo, wopts)
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    27
        if wopts.opts.get(b'print_revset'):
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    28
            expr = logrevset(repo, wopts)
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
            if expr:
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
                tree = revsetlang.parse(expr)
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
                tree = revsetlang.analyze(tree)
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
            else:
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
                tree = []
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
            ui = repo.ui
45565
c1d0f83d62c4 log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents: 45564
diff changeset
    35
            ui.write(b'%s\n' % stringutil.pprint(wopts.opts.get(b'rev', [])))
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
            ui.write(revsetlang.prettyformat(tree) + b'\n')
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
            ui.write(stringutil.prettyrepr(revs) + b'\n')
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
            revs = smartset.baseset()  # display no revisions
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
        return revs, filematcher
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    40
39058
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
    extensions.wrapfunction(logcmdutil, 'getrevs', printrevset)
a271466cb53a tests: extract printrevset extension from test-glog-beautifygraph.t
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
    aliases, entry = cmdutil.findcmd(b'log', commands.table)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    43
    entry[1].append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    44
        (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    45
            b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    46
            b'print-revset',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    47
            False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    48
            b'print generated revset and exit (DEPRECATED)',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    49
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39058
diff changeset
    50
    )