mercurial/logcmdutil.py
author Augie Fackler <augie@google.com>
Sun, 06 Oct 2019 09:45:02 -0400
changeset 43076 2372284d9457
parent 42504 a68350a7fc55
child 43077 687b865b95ad
permissions -rw-r--r--
formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35885
7625b4f7db70 cmdutil: split functions of log-like commands to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35874
diff changeset
     1
# logcmdutil.py - utility for log-like commands
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
     3
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8210
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10249
diff changeset
     6
# GNU General Public License version 2 or any later version.
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     7
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
     8
from __future__ import absolute_import
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
     9
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31698
diff changeset
    10
import itertools
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    11
import os
41646
d4c9eebdd72d patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
    12
import posixpath
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    13
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    14
from .i18n import _
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    15
from .node import (
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    16
    nullid,
39796
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
    17
    wdirid,
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
    18
    wdirrev,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    19
)
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    20
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    21
from . import (
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
    22
    dagop,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    23
    error,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    24
    formatter,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    25
    graphmod,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    26
    match as matchmod,
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
    27
    mdiff,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    28
    patch,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    29
    pathutil,
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30506
diff changeset
    30
    pycompat,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    31
    revset,
35644
7a0a90d63a8c log: use revsetlang.formatspec() to concatenate list expression
Yuya Nishihara <yuya@tcha.org>
parents: 35643
diff changeset
    32
    revsetlang,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    33
    scmutil,
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
    34
    smartset,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    35
    templatekw,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    36
    templater,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    37
    util,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    38
)
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37072
diff changeset
    39
from .utils import (
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37072
diff changeset
    40
    dateutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37072
diff changeset
    41
    stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37072
diff changeset
    42
)
21405
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
    43
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    44
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
    45
def getlimit(opts):
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    46
    """get the log limit according to option -l/--limit"""
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    47
    limit = opts.get('limit')
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    48
    if limit:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    49
        try:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    50
            limit = int(limit)
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    51
        except ValueError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
    52
            raise error.Abort(_('limit must be a positive integer'))
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
    53
        if limit <= 0:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
    54
            raise error.Abort(_('limit must be positive'))
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    55
    else:
10111
27457d31ae3f cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10061
diff changeset
    56
        limit = None
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    57
    return limit
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    58
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    59
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    60
def diffordiffstat(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    61
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    62
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    63
    diffopts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    64
    node1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    65
    node2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    66
    match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    67
    changes=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    68
    stat=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    69
    fp=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    70
    graphwidth=0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    71
    prefix='',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    72
    root='',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    73
    listsubrepos=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    74
    hunksfilterfn=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    75
):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    76
    '''show diff or diffstat.'''
41610
d683aca738cd diffordiffstat: avoid looking up contexts twice
Martin von Zweigbergk <martinvonz@google.com>
parents: 41097
diff changeset
    77
    ctx1 = repo[node1]
d683aca738cd diffordiffstat: avoid looking up contexts twice
Martin von Zweigbergk <martinvonz@google.com>
parents: 41097
diff changeset
    78
    ctx2 = repo[node2]
24455
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
    79
    if root:
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
    80
        relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    81
    else:
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    82
        relroot = ''
41620
74f53d3bd685 patch: accept second matcher that applies only to copy sources (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41619
diff changeset
    83
    copysourcematch = None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    84
41647
ec37db02fc72 diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents: 41646
diff changeset
    85
    def compose(f, g):
ec37db02fc72 diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents: 41646
diff changeset
    86
        return lambda x: f(g(x))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    87
41646
d4c9eebdd72d patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
    88
    def pathfn(f):
d4c9eebdd72d patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
    89
        return posixpath.join(prefix, f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    90
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    91
    if relroot != '':
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    92
        # XXX relative roots currently don't work if the root is within a
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    93
        # subrepo
41655
df59b1078983 diff: respect ui.relative-paths for warning about path outside --root
Martin von Zweigbergk <martinvonz@google.com>
parents: 41647
diff changeset
    94
        uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
df59b1078983 diff: respect ui.relative-paths for warning about path outside --root
Martin von Zweigbergk <martinvonz@google.com>
parents: 41647
diff changeset
    95
        uirelroot = uipathfn(pathfn(relroot))
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    96
        relroot += '/'
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    97
        for matchroot in match.files():
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    98
            if not matchroot.startswith(relroot):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
    99
                ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   100
                    _('warning: %s not inside relative root %s\n')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   101
                    % (uipathfn(pathfn(matchroot)), uirelroot)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   102
                )
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
   103
41619
035cae1d197f patch: let caller pass in root-filtering matcher (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
   104
        relrootmatch = scmutil.match(ctx2, pats=[relroot], default='path')
035cae1d197f patch: let caller pass in root-filtering matcher (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
   105
        match = matchmod.intersectmatchers(match, relrootmatch)
41620
74f53d3bd685 patch: accept second matcher that applies only to copy sources (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41619
diff changeset
   106
        copysourcematch = relrootmatch
41619
035cae1d197f patch: let caller pass in root-filtering matcher (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
   107
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   108
        checkroot = repo.ui.configbool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   109
            'devel', 'all-warnings'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   110
        ) or repo.ui.configbool('devel', 'check-relroot')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   111
41647
ec37db02fc72 diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents: 41646
diff changeset
   112
        def relrootpathfn(f):
41646
d4c9eebdd72d patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
   113
            if checkroot and not f.startswith(relroot):
d4c9eebdd72d patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
   114
                raise AssertionError(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   115
                    "file %s doesn't start with relroot %s" % (f, relroot)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   116
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   117
            return f[len(relroot) :]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   118
41647
ec37db02fc72 diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents: 41646
diff changeset
   119
        pathfn = compose(relrootpathfn, pathfn)
41646
d4c9eebdd72d patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
   120
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   121
    if stat:
35430
058c725925e3 diff: disable diff.noprefix option for diffstat (issue5759)
Yuya Nishihara <yuya@tcha.org>
parents: 35026
diff changeset
   122
        diffopts = diffopts.copy(context=0, noprefix=False)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   123
        width = 80
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   124
        if not ui.plain():
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   125
            width = ui.termwidth() - graphwidth
41670
db69a763bc89 diff: make --stat respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41655
diff changeset
   126
        # If an explicit --root was given, don't respect ui.relative-paths
db69a763bc89 diff: make --stat respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41655
diff changeset
   127
        if not relroot:
db69a763bc89 diff: make --stat respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41655
diff changeset
   128
            pathfn = compose(scmutil.getuipathfn(repo), pathfn)
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   129
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   130
    chunks = ctx2.diff(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   131
        ctx1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   132
        match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   133
        changes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   134
        opts=diffopts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   135
        pathfn=pathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   136
        copysourcematch=copysourcematch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   137
        hunksfilterfn=hunksfilterfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   138
    )
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   139
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   140
    if fp is not None or ui.canwritewithoutlabels():
36008
006ff7268c5c diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents: 36007
diff changeset
   141
        out = fp or ui
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   142
        if stat:
36115
c1104fe76e69 py3: preserve chunks as an iterable of bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36008
diff changeset
   143
            chunks = [patch.diffstat(util.iterlines(chunks), width=width)]
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   144
        for chunk in util.filechunkiter(util.chunkbuffer(chunks)):
36008
006ff7268c5c diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents: 36007
diff changeset
   145
            out.write(chunk)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   146
    else:
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   147
        if stat:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   148
            chunks = patch.diffstatui(util.iterlines(chunks), width=width)
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   149
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   150
            chunks = patch.difflabel(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   151
                lambda chunks, **kwargs: chunks, chunks, opts=diffopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   152
            )
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   153
        if ui.canbatchlabeledwrites():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   154
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   155
            def gen():
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   156
                for chunk, label in chunks:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   157
                    yield ui.label(chunk, label=label)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   158
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   159
            for chunk in util.filechunkiter(util.chunkbuffer(gen())):
36008
006ff7268c5c diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents: 36007
diff changeset
   160
                ui.write(chunk)
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   161
        else:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   162
            for chunk, label in chunks:
36008
006ff7268c5c diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents: 36007
diff changeset
   163
                ui.write(chunk, label=label)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   164
42010
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   165
    for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   166
        tempnode2 = node2
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   167
        try:
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   168
            if node2 is not None:
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   169
                tempnode2 = ctx2.substate[subpath][1]
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   170
        except KeyError:
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   171
            # A subrepo that existed in node1 was deleted between node1 and
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   172
            # node2 (inclusive). Thus, ctx2's substate won't contain that
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   173
            # subpath. The best we can do is to ignore it.
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   174
            tempnode2 = None
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   175
        submatch = matchmod.subdirmatcher(subpath, match)
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   176
        subprefix = repo.wvfs.reljoin(prefix, subpath)
db26dbbee74d diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 41996
diff changeset
   177
        if listsubrepos or match.exact(subpath) or any(submatch.files()):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   178
            sub.diff(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   179
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   180
                diffopts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   181
                tempnode2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   182
                submatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   183
                changes=changes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   184
                stat=stat,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   185
                fp=fp,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   186
                prefix=subprefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   187
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   188
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   189
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   190
class changesetdiffer(object):
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   191
    """Generate diff of changeset with pre-configured filtering functions"""
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   192
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   193
    def _makefilematcher(self, ctx):
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   194
        return scmutil.matchall(ctx.repo())
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   195
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   196
    def _makehunksfilter(self, ctx):
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   197
        return None
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   198
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   199
    def showdiff(self, ui, ctx, diffopts, graphwidth=0, stat=False):
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   200
        repo = ctx.repo()
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   201
        node = ctx.node()
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   202
        prev = ctx.p1().node()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   203
        diffordiffstat(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   204
            ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   205
            repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   206
            diffopts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   207
            prev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   208
            node,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   209
            match=self._makefilematcher(ctx),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   210
            stat=stat,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   211
            graphwidth=graphwidth,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   212
            hunksfilterfn=self._makehunksfilter(ctx),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   213
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   214
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   215
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   216
def changesetlabels(ctx):
30694
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
   217
    labels = ['log.changeset', 'changeset.%s' % ctx.phasestr()]
31698
9b3577796291 cmdutil: add a "changeset.obsolete" label in changeset_printer
Denis Laxalde <denis@laxalde.org>
parents: 31486
diff changeset
   218
    if ctx.obsolete():
9b3577796291 cmdutil: add a "changeset.obsolete" label in changeset_printer
Denis Laxalde <denis@laxalde.org>
parents: 31486
diff changeset
   219
        labels.append('changeset.obsolete')
33730
52c5ff856b49 context: rename troubled into isunstable
Boris Feld <boris.feld@octobus.net>
parents: 33726
diff changeset
   220
    if ctx.isunstable():
33781
3821dfee2cfc label: rename changeset.troubled into changeset.unstable
Boris Feld <boris.feld@octobus.net>
parents: 33771
diff changeset
   221
        labels.append('changeset.unstable')
33726
ab0c55c2ad9a context: rename troubles into instabilities
Boris Feld <boris.feld@octobus.net>
parents: 33694
diff changeset
   222
        for instability in ctx.instabilities():
33782
40739aef97f7 label: rename trouble.X into instability.X
Boris Feld <boris.feld@octobus.net>
parents: 33781
diff changeset
   223
            labels.append('instability.%s' % instability)
30694
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
   224
    return ' '.join(labels)
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
   225
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   226
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   227
class changesetprinter(object):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   228
    '''show changeset information when templating not requested.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   229
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   230
    def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   231
        self.ui = ui
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   232
        self.repo = repo
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   233
        self.buffered = buffered
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   234
        self._differ = differ or changesetdiffer()
37837
e0f30c91dfd8 log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents: 37773
diff changeset
   235
        self._diffopts = patch.diffallopts(ui, diffopts)
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   236
        self._includestat = diffopts and diffopts.get('stat')
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   237
        self._includediff = diffopts and diffopts.get('patch')
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   238
        self.header = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   239
        self.hunk = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   240
        self.lastheader = None
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   241
        self.footer = None
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   242
        self._columns = templatekw.getlogcolumns()
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   243
25763
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
   244
    def flush(self, ctx):
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
   245
        rev = ctx.rev()
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   246
        if rev in self.header:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   247
            h = self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   248
            if h != self.lastheader:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   249
                self.lastheader = h
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   250
                self.ui.write(h)
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   251
            del self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   252
        if rev in self.hunk:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   253
            self.ui.write(self.hunk[rev])
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   254
            del self.hunk[rev]
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   255
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   256
    def close(self):
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   257
        if self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   258
            self.ui.write(self.footer)
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   259
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   260
    def show(self, ctx, copies=None, **props):
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33045
diff changeset
   261
        props = pycompat.byteskwargs(props)
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   262
        if self.buffered:
27107
c57ebef70f6f cmdutil: pass labeled=True to pushbuffer()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27065
diff changeset
   263
            self.ui.pushbuffer(labeled=True)
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   264
            self._show(ctx, copies, props)
27109
a93d53f79e6e ui: remove labeled argument from popbuffer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27107
diff changeset
   265
            self.hunk[ctx.rev()] = self.ui.popbuffer()
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   266
        else:
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   267
            self._show(ctx, copies, props)
34856
890afefa7296 diff: pass a diff hunks filter function from changeset_printer to patch.diff()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34852
diff changeset
   268
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   269
    def _show(self, ctx, copies, props):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   270
        '''show a single changeset or file revision'''
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   271
        changenode = ctx.node()
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   272
        graphwidth = props.get('graphwidth', 0)
24584
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   273
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   274
        if self.ui.quiet:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   275
            self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   276
                "%s\n" % scmutil.formatchangeid(ctx), label='log.node'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   277
            )
24584
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   278
            return
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   279
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   280
        columns = self._columns
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   281
        self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   282
            columns['changeset'] % scmutil.formatchangeid(ctx),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   283
            label=changesetlabels(ctx),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   284
        )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   285
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   286
        # branches are shown first before any other names due to backwards
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   287
        # compatibility
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   288
        branch = ctx.branch()
4176
f9bbcebcacea "default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4055
diff changeset
   289
        # don't show the default branch name
f9bbcebcacea "default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4055
diff changeset
   290
        if branch != 'default':
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   291
            self.ui.write(columns['branch'] % branch, label='log.branch')
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   292
28904
80be5dbe6e74 cmdutil: avoid recycling variable name "name" in namespaces code
Nathaniel Manista <nathaniel@google.com>
parents: 28891
diff changeset
   293
        for nsname, ns in self.repo.names.iteritems():
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   294
            # branches has special logic already handled above, so here we just
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   295
            # skip it
28904
80be5dbe6e74 cmdutil: avoid recycling variable name "name" in namespaces code
Nathaniel Manista <nathaniel@google.com>
parents: 28891
diff changeset
   296
            if nsname == 'branches':
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   297
                continue
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   298
            # we will use the templatename as the color name since those two
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   299
            # should be the same
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   300
            for name in ns.names(self.repo, changenode):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   301
                self.ui.write(ns.logfmt % name, label='log.%s' % ns.colorname)
22765
55dcc7fb731c log: do not hide the public phase in debug mode (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22764
diff changeset
   302
        if self.ui.debugflag:
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   303
            self.ui.write(columns['phase'] % ctx.phasestr(), label='log.phase')
26433
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 26426
diff changeset
   304
        for pctx in scmutil.meaningfulparents(self.repo, ctx):
24483
870d2eb82f6d changeset_printer: use context objects consistently to show parents
Yuya Nishihara <yuya@tcha.org>
parents: 24480
diff changeset
   305
            label = 'log.parent changeset.%s' % pctx.phasestr()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   306
            self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   307
                columns['parent'] % scmutil.formatchangeid(pctx), label=label
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   308
            )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   309
39796
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
   310
        if self.ui.debugflag:
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   311
            mnode = ctx.manifestnode()
39796
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
   312
            if mnode is None:
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
   313
                mnode = wdirid
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
   314
                mrev = wdirrev
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
   315
            else:
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39795
diff changeset
   316
                mrev = self.repo.manifestlog.rev(mnode)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   317
            self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   318
                columns['manifest']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   319
                % scmutil.formatrevnode(self.ui, mrev, mnode),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   320
                label='ui.debug log.manifest',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   321
            )
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   322
        self.ui.write(columns['user'] % ctx.user(), label='log.user')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   323
        self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   324
            columns['date'] % dateutil.datestr(ctx.date()), label='log.date'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   325
        )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   326
33730
52c5ff856b49 context: rename troubled into isunstable
Boris Feld <boris.feld@octobus.net>
parents: 33726
diff changeset
   327
        if ctx.isunstable():
33726
ab0c55c2ad9a context: rename troubles into instabilities
Boris Feld <boris.feld@octobus.net>
parents: 33694
diff changeset
   328
            instabilities = ctx.instabilities()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   329
            self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   330
                columns['instability'] % ', '.join(instabilities),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   331
                label='log.instability',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   332
            )
30695
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
   333
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   334
        elif ctx.obsolete():
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   335
            self._showobsfate(ctx)
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   336
33154
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   337
        self._exthook(ctx)
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   338
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   339
        if self.ui.debugflag:
24485
914caae9a86a changeset_printer: use changectx to get status tuple
Yuya Nishihara <yuya@tcha.org>
parents: 24484
diff changeset
   340
            files = ctx.p1().status(ctx)[:3]
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   341
            for key, value in zip(['files', 'files+', 'files-'], files):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   342
                if value:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   343
                    self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   344
                        columns[key] % " ".join(value),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   345
                        label='ui.debug log.files',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   346
                    )
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   347
        elif ctx.files() and self.ui.verbose:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   348
            self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   349
                columns['files'] % " ".join(ctx.files()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   350
                label='ui.note log.files',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   351
            )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   352
        if copies and self.ui.verbose:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   353
            copies = ['%s (%s)' % c for c in copies]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   354
            self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   355
                columns['copies'] % ' '.join(copies), label='ui.note log.copies'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   356
            )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   357
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   358
        extra = ctx.extra()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   359
        if extra and self.ui.debugflag:
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
   360
            for key, value in sorted(extra.items()):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   361
                self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   362
                    columns['extra'] % (key, stringutil.escapestr(value)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   363
                    label='ui.debug log.extra',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   364
                )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   365
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   366
        description = ctx.description().strip()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   367
        if description:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   368
            if self.ui.verbose:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   369
                self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   370
                    _("description:\n"), label='ui.note log.description'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   371
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   372
                self.ui.write(description, label='ui.note log.description')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   373
                self.ui.write("\n\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   374
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   375
                self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   376
                    columns['summary'] % description.splitlines()[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   377
                    label='log.summary',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   378
                )
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   379
        self.ui.write("\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   380
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   381
        self._showpatch(ctx, graphwidth)
27065
93bcc73df8d5 cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26938
diff changeset
   382
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   383
    def _showobsfate(self, ctx):
36517
69477bac8926 log: do not invoke templatekw.showobsfate() as a function
Yuya Nishihara <yuya@tcha.org>
parents: 36513
diff changeset
   384
        # TODO: do not depend on templater
69477bac8926 log: do not invoke templatekw.showobsfate() as a function
Yuya Nishihara <yuya@tcha.org>
parents: 36513
diff changeset
   385
        tres = formatter.templateresources(self.repo.ui, self.repo)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   386
        t = formatter.maketemplater(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   387
            self.repo.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   388
            '{join(obsfate, "\n")}',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   389
            defaults=templatekw.keywords,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   390
            resources=tres,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   391
        )
37103
be3f33f5e232 templater: switch 'revcache' based on new mapping items
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
   392
        obsfate = t.renderdefault({'ctx': ctx}).splitlines()
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   393
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   394
        if obsfate:
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   395
            for obsfateline in obsfate:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   396
                self.ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   397
                    self._columns['obsolete'] % obsfateline, label='log.obsfate'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   398
                )
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   399
33154
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   400
    def _exthook(self, ctx):
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   401
        '''empty method used by extension as a hook point
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   402
        '''
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   403
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   404
    def _showpatch(self, ctx, graphwidth=0):
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   405
        if self._includestat:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   406
            self._differ.showdiff(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   407
                self.ui, ctx, self._diffopts, graphwidth, stat=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   408
            )
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   409
        if self._includestat and self._includediff:
36004
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   410
            self.ui.write("\n")
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   411
        if self._includediff:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   412
            self._differ.showdiff(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   413
                self.ui, ctx, self._diffopts, graphwidth, stat=False
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   414
            )
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   415
        if self._includestat or self._includediff:
36004
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   416
            self.ui.write("\n")
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   417
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   418
37773
0f084741cd66 logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents: 37772
diff changeset
   419
class changesetformatter(changesetprinter):
0f084741cd66 logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents: 37772
diff changeset
   420
    """Format changeset information by generic formatter"""
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   421
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   422
    def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   423
        self, ui, repo, fm, differ=None, diffopts=None, buffered=False
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   424
    ):
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   425
        changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
37837
e0f30c91dfd8 log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents: 37773
diff changeset
   426
        self._diffopts = patch.difffeatureopts(ui, diffopts, git=True)
37773
0f084741cd66 logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents: 37772
diff changeset
   427
        self._fm = fm
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   428
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   429
    def close(self):
37772
814151cd8c4a logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents: 37771
diff changeset
   430
        self._fm.end()
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   431
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   432
    def _show(self, ctx, copies, props):
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   433
        '''show a single changeset or file revision'''
37772
814151cd8c4a logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents: 37771
diff changeset
   434
        fm = self._fm
814151cd8c4a logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents: 37771
diff changeset
   435
        fm.startitem()
39705
fa681452b249 log: make changesetformatter pass in changectx to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 38570
diff changeset
   436
        fm.context(ctx=ctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   437
        fm.data(rev=scmutil.intrev(ctx), node=fm.hexfunc(scmutil.binnode(ctx)))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   438
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   439
        if self.ui.quiet:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   440
            return
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   441
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   442
        fm.data(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   443
            branch=ctx.branch(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   444
            phase=ctx.phasestr(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   445
            user=ctx.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   446
            date=fm.formatdate(ctx.date()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   447
            desc=ctx.description(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   448
            bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   449
            tags=fm.formatlist(ctx.tags(), name='tag'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   450
            parents=fm.formatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   451
                [fm.hexfunc(c.node()) for c in ctx.parents()], name='node'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   452
            ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   453
        )
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   454
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   455
        if self.ui.debugflag:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   456
            fm.data(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   457
                manifest=fm.hexfunc(ctx.manifestnode() or wdirid),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   458
                extra=fm.formatdict(ctx.extra()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   459
            )
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   460
23734
f4e6475950f1 cmdutil.jsonchangeset: properly compute added and removed files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23501
diff changeset
   461
            files = ctx.p1().status(ctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   462
            fm.data(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   463
                modified=fm.formatlist(files[0], name='file'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   464
                added=fm.formatlist(files[1], name='file'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   465
                removed=fm.formatlist(files[2], name='file'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   466
            )
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   467
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   468
        elif self.ui.verbose:
37772
814151cd8c4a logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents: 37771
diff changeset
   469
            fm.data(files=fm.formatlist(ctx.files(), name='file'))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   470
            if copies:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   471
                fm.data(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   472
                    copies=fm.formatdict(copies, key='name', value='source')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   473
                )
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   474
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   475
        if self._includestat:
36004
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   476
            self.ui.pushbuffer()
37837
e0f30c91dfd8 log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents: 37773
diff changeset
   477
            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
37772
814151cd8c4a logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents: 37771
diff changeset
   478
            fm.data(diffstat=self.ui.popbuffer())
37838
3fe1c9263024 log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 37837
diff changeset
   479
        if self._includediff:
36004
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   480
            self.ui.pushbuffer()
37837
e0f30c91dfd8 log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents: 37773
diff changeset
   481
            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
37772
814151cd8c4a logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents: 37771
diff changeset
   482
            fm.data(diff=self.ui.popbuffer())
4825
3cf94964c56b hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4824
diff changeset
   483
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   484
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   485
class changesettemplater(changesetprinter):
35107
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   486
    '''format changeset information.
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   487
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   488
    Note: there are a variety of convenience functions to build a
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   489
    changesettemplater for common cases. See functions such as:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   490
    maketemplater, changesetdisplayer, buildcommittemplate, or other
35107
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   491
    functions that use changesest_templater.
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   492
    '''
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   493
33045
99c6c9fa9e6d cmdutil: use named arguments for changeset_templater.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32953
diff changeset
   494
    # Arguments before "buffered" used to be positional. Consider not
99c6c9fa9e6d cmdutil: use named arguments for changeset_templater.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32953
diff changeset
   495
    # adding/removing arguments before "buffered" to not break callers.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   496
    def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   497
        self, ui, repo, tmplspec, differ=None, diffopts=None, buffered=False
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   498
    ):
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   499
        changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
37072
d64ae4fef471 log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents: 36989
diff changeset
   500
        # tres is shared with _graphnodeformatter()
d64ae4fef471 log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents: 36989
diff changeset
   501
        self._tresources = tres = formatter.templateresources(ui, repo)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   502
        self.t = formatter.loadtemplater(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   503
            ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   504
            tmplspec,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   505
            defaults=templatekw.keywords,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   506
            resources=tres,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   507
            cache=templatekw.defaulttempl,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   508
        )
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31698
diff changeset
   509
        self._counter = itertools.count()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   510
32842
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
   511
        self._tref = tmplspec.ref
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   512
        self._parts = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   513
            'header': '',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   514
            'footer': '',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   515
            tmplspec.ref: tmplspec.ref,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   516
            'docheader': '',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   517
            'docfooter': '',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   518
            'separator': '',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   519
        }
32947
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   520
        if tmplspec.mapfile:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   521
            # find correct templates for current mode, for backward
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   522
            # compatibility with 'log -v/-q/--debug' using a mapfile
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   523
            tmplmodes = [
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   524
                (True, ''),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   525
                (self.ui.verbose, '_verbose'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   526
                (self.ui.quiet, '_quiet'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   527
                (self.ui.debugflag, '_debug'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   528
            ]
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   529
            for mode, postfix in tmplmodes:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   530
                for t in self._parts:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   531
                    cur = t + postfix
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   532
                    if mode and cur in self.t:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   533
                        self._parts[t] = cur
32953
6d79e9109908 changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32951
diff changeset
   534
        else:
6d79e9109908 changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32951
diff changeset
   535
            partnames = [p for p in self._parts.keys() if p != tmplspec.ref]
6d79e9109908 changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32951
diff changeset
   536
            m = formatter.templatepartsmap(tmplspec, self.t, partnames)
6d79e9109908 changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32951
diff changeset
   537
            self._parts.update(m)
26086
3670efdc7088 templater: move verbosity-to-template matcher to constructor
Matt Mackall <mpm@selenic.com>
parents: 26085
diff changeset
   538
26222
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   539
        if self._parts['docheader']:
36989
de117f579431 templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents: 36988
diff changeset
   540
            self.ui.write(self.t.render(self._parts['docheader'], {}))
26222
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   541
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   542
    def close(self):
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   543
        if self._parts['docfooter']:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   544
            if not self.footer:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   545
                self.footer = ""
36989
de117f579431 templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents: 36988
diff changeset
   546
            self.footer += self.t.render(self._parts['docfooter'], {})
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   547
        return super(changesettemplater, self).close()
26222
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   548
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   549
    def _show(self, ctx, copies, props):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   550
        '''show a single changeset or file revision'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   551
        props = props.copy()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   552
        props['ctx'] = ctx
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   553
        props['index'] = index = next(self._counter)
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   554
        props['revcache'] = {'copies': copies}
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   555
        graphwidth = props.get('graphwidth', 0)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   556
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   557
        # write separator, which wouldn't work well with the header part below
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   558
        # since there's inherently a conflict between header (across items) and
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   559
        # separator (per item)
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   560
        if self._parts['separator'] and index > 0:
36989
de117f579431 templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents: 36988
diff changeset
   561
            self.ui.write(self.t.render(self._parts['separator'], {}))
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   562
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   563
        # write header
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   564
        if self._parts['header']:
36989
de117f579431 templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents: 36988
diff changeset
   565
            h = self.t.render(self._parts['header'], props)
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   566
            if self.buffered:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   567
                self.header[ctx.rev()] = h
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   568
            else:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   569
                if self.lastheader != h:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   570
                    self.lastheader = h
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   571
                    self.ui.write(h)
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   572
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   573
        # write changeset metadata, then patch if requested
32842
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
   574
        key = self._parts[self._tref]
36989
de117f579431 templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents: 36988
diff changeset
   575
        self.ui.write(self.t.render(key, props))
41097
6a63ba61e71f log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 40285
diff changeset
   576
        self._showpatch(ctx, graphwidth)
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   577
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   578
        if self._parts['footer']:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   579
            if not self.footer:
36989
de117f579431 templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents: 36988
diff changeset
   580
                self.footer = self.t.render(self._parts['footer'], props)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   581
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   582
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   583
def templatespec(tmpl, mapfile):
40285
96164fb9b913 logcmdutil: add a helpful assertion to catch mistyped templates early
Augie Fackler <augie@google.com>
parents: 39796
diff changeset
   584
    if pycompat.ispy3:
96164fb9b913 logcmdutil: add a helpful assertion to catch mistyped templates early
Augie Fackler <augie@google.com>
parents: 39796
diff changeset
   585
        assert not isinstance(tmpl, str), 'tmpl must not be a str'
32875
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   586
    if mapfile:
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   587
        return formatter.templatespec('changeset', tmpl, mapfile)
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   588
    else:
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   589
        return formatter.templatespec('', tmpl, None)
32838
615ec3f14aa9 formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32837
diff changeset
   590
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   591
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   592
def _lookuptemplate(ui, tmpl, style):
32835
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
   593
    """Find the template matching the given template spec or style
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
   594
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
   595
    See formatter.lookuptemplate() for details.
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   596
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   597
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   598
    # ui settings
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   599
    if not tmpl and not style:  # template are stronger than style
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   600
        tmpl = ui.config('ui', 'logtemplate')
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   601
        if tmpl:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   602
            return templatespec(templater.unquotestring(tmpl), None)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   603
        else:
33499
0407a51b9d8c codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents: 33438
diff changeset
   604
            style = util.expandpath(ui.config('ui', 'style'))
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   605
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
   606
    if not tmpl and style:
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   607
        mapfile = style
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   608
        if not os.path.split(mapfile)[0]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   609
            mapname = templater.templatepath(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   610
                'map-cmdline.' + mapfile
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   611
            ) or templater.templatepath(mapfile)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   612
            if mapname:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   613
                mapfile = mapname
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   614
        return templatespec(None, mapfile)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   615
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
   616
    if not tmpl:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   617
        return templatespec(None, None)
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
   618
25511
c2a4dfe2a336 formatter: move most of template option helper to formatter
Matt Mackall <mpm@selenic.com>
parents: 25439
diff changeset
   619
    return formatter.lookuptemplate(ui, 'changeset', tmpl)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   620
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   621
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   622
def maketemplater(ui, repo, tmpl, buffered=False):
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   623
    """Create a changesettemplater from a literal template 'tmpl'
35107
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   624
    byte-string."""
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   625
    spec = templatespec(tmpl, None)
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   626
    return changesettemplater(ui, repo, spec, buffered=buffered)
32837
50586a0a946f cmdutil: factor out helper to create changeset_templater with literal template
Yuya Nishihara <yuya@tcha.org>
parents: 32835
diff changeset
   627
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   628
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   629
def changesetdisplayer(ui, repo, opts, differ=None, buffered=False):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   630
    """show one changeset using template or regular display.
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   631
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   632
    Display format will be the first non-empty hit of:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   633
    1. option 'template'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   634
    2. option 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   635
    3. [ui] setting 'logtemplate'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   636
    4. [ui] setting 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   637
    If all of these values are either the unset or the empty string,
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   638
    regular display via changesetprinter() is done.
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   639
    """
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   640
    postargs = (differ, opts, buffered)
41996
77ef3498ceb3 template: add CBOR output format
Yuya Nishihara <yuya@tcha.org>
parents: 41670
diff changeset
   641
    if opts.get('template') in {'cbor', 'json'}:
37773
0f084741cd66 logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents: 37772
diff changeset
   642
        fm = ui.formatter('log', opts)
0f084741cd66 logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents: 37772
diff changeset
   643
        return changesetformatter(ui, repo, fm, *postargs)
3837
7df171ea50cd Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents: 3827
diff changeset
   644
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   645
    spec = _lookuptemplate(ui, opts.get('template'), opts.get('style'))
32839
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
   646
32875
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   647
    if not spec.ref and not spec.tmpl and not spec.mapfile:
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   648
        return changesetprinter(ui, repo, *postargs)
34083
08346a8fa65f cleanup: rename "matchfn" to "match" where obviously a matcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 34081
diff changeset
   649
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   650
    return changesettemplater(ui, repo, spec, *postargs)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   651
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   652
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   653
def _makematcher(repo, revs, pats, opts):
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   654
    """Build matcher and expanded patterns from log options
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   655
35687
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   656
    If --follow, revs are the revisions to follow from.
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   657
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   658
    Returns (match, pats, slowpath) where
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   659
    - match: a matcher built from the given pats and -I/-X opts
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   660
    - pats: patterns used (globs are expanded on Windows)
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   661
    - slowpath: True if patterns aren't as simple as scanning filelogs
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   662
    """
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   663
    # pats/include/exclude are passed to match.match() directly in
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   664
    # _matchfiles() revset but walkchangerevs() builds its matcher with
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   665
    # scmutil.match(). The difference is input pats are globbed on
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   666
    # platforms without shell expansion (windows).
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   667
    wctx = repo[None]
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   668
    match, pats = scmutil.matchandpats(wctx, pats, opts)
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   669
    slowpath = match.anypats() or (not match.always() and opts.get('removed'))
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   670
    if not slowpath:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   671
        follow = opts.get('follow') or opts.get('follow_first')
35687
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   672
        startctxs = []
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   673
        if follow and opts.get('rev'):
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   674
            startctxs = [repo[r] for r in revs]
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   675
        for f in match.files():
35687
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   676
            if follow and startctxs:
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   677
                # No idea if the path was a directory at that revision, so
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   678
                # take the slow path.
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   679
                if any(f not in c for c in startctxs):
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   680
                    slowpath = True
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   681
                    continue
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   682
            elif follow and f not in wctx:
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   683
                # If the file exists, it may be a directory, so let it
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   684
                # take the slow path.
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   685
                if os.path.exists(repo.wjoin(f)):
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   686
                    slowpath = True
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   687
                    continue
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   688
                else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   689
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   690
                        _('cannot follow file not in parent ' 'revision: "%s"')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   691
                        % f
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   692
                    )
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   693
            filelog = repo.file(f)
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   694
            if not filelog:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   695
                # A zero count may be a directory or deleted file, so
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   696
                # try to find matching entries on the slow path.
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   697
                if follow:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   698
                    raise error.Abort(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   699
                        _('cannot follow nonexistent file: "%s"') % f
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   700
                    )
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   701
                slowpath = True
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   702
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   703
        # We decided to fall back to the slowpath because at least one
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   704
        # of the paths was not a file. Check to see if at least one of them
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   705
        # existed in history - in that case, we'll continue down the
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   706
        # slowpath; otherwise, we can turn off the slowpath
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   707
        if slowpath:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   708
            for path in match.files():
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   709
                if path == '.' or path in repo.store:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   710
                    break
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   711
            else:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   712
                slowpath = False
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   713
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   714
    return match, pats, slowpath
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   715
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   716
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   717
def _fileancestors(repo, revs, match, followfirst):
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   718
    fctxs = []
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   719
    for r in revs:
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   720
        ctx = repo[r]
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   721
        fctxs.extend(ctx[f].introfilectx() for f in ctx.walk(match))
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   722
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   723
    # When displaying a revision with --patch --follow FILE, we have
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   724
    # to know which file of the revision must be diffed. With
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   725
    # --follow, we want the names of the ancestors of FILE in the
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   726
    # revision, stored in "fcache". "fcache" is populated as a side effect
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   727
    # of the graph traversal.
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   728
    fcache = {}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   729
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   730
    def filematcher(ctx):
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   731
        return scmutil.matchfiles(repo, fcache.get(ctx.rev(), []))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   732
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   733
    def revgen():
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   734
        for rev, cs in dagop.filectxancestors(fctxs, followfirst=followfirst):
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   735
            fcache[rev] = [c.path() for c in cs]
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   736
            yield rev
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   737
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   738
    return smartset.generatorset(revgen(), iterasc=False), filematcher
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   739
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   740
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   741
def _makenofollowfilematcher(repo, pats, opts):
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
   742
    '''hook for extensions to override the filematcher for non-follow cases'''
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
   743
    return None
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
   744
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   745
35642
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   746
_opt2logrevset = {
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   747
    'no_merges': ('not merge()', None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   748
    'only_merges': ('merge()', None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   749
    '_matchfiles': (None, '_matchfiles(%ps)'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   750
    'date': ('date(%s)', None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   751
    'branch': ('branch(%s)', '%lr'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   752
    '_patslog': ('filelog(%s)', '%lr'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   753
    'keyword': ('keyword(%s)', '%lr'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   754
    'prune': ('ancestors(%s)', 'not %lr'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   755
    'user': ('user(%s)', '%lr'),
35642
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   756
}
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   757
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   758
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   759
def _makerevset(repo, match, pats, slowpath, opts):
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   760
    """Return a revset string built from log options and file patterns"""
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   761
    opts = dict(opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   762
    # follow or not follow?
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   763
    follow = opts.get('follow') or opts.get('follow_first')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   764
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   765
    # branch and only_branch are really aliases and must be handled at
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   766
    # the same time
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   767
    opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   768
    opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
   769
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   770
    if slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   771
        # See walkchangerevs() slow path.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   772
        #
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   773
        # pats/include/exclude cannot be represented as separate
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   774
        # revset expressions as their filtering logic applies at file
35743
3c2a6246fd63 log: fix typo in comment about _matchfiles()
Yuya Nishihara <yuya@tcha.org>
parents: 35690
diff changeset
   775
        # level. For instance "-I a -X b" matches a revision touching
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   776
        # "a" and "b" while "file(a) and not file(b)" does
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   777
        # not. Besides, filesets are evaluated against the working
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   778
        # directory.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   779
        matchargs = ['r:', 'd:relpath']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   780
        for p in pats:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   781
            matchargs.append('p:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   782
        for p in opts.get('include', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   783
            matchargs.append('i:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   784
        for p in opts.get('exclude', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   785
            matchargs.append('x:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   786
        opts['_matchfiles'] = matchargs
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   787
    elif not follow:
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   788
        opts['_patslog'] = list(pats)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   789
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   790
    expr = []
23501
424d669118d3 log: fix log revset instability
Durham Goode <durham@fb.com>
parents: 23500
diff changeset
   791
    for op, val in sorted(opts.iteritems()):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   792
        if not val:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   793
            continue
35642
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   794
        if op not in _opt2logrevset:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   795
            continue
35644
7a0a90d63a8c log: use revsetlang.formatspec() to concatenate list expression
Yuya Nishihara <yuya@tcha.org>
parents: 35643
diff changeset
   796
        revop, listop = _opt2logrevset[op]
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   797
        if revop and '%' not in revop:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   798
            expr.append(revop)
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   799
        elif not listop:
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   800
            expr.append(revsetlang.formatspec(revop, val))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   801
        else:
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   802
            if revop:
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   803
                val = [revsetlang.formatspec(revop, v) for v in val]
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   804
            expr.append(revsetlang.formatspec(listop, val))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   805
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   806
    if expr:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   807
        expr = '(' + ' and '.join(expr) + ')'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   808
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   809
        expr = None
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   810
    return expr
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   811
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   812
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   813
def _initialrevs(repo, opts):
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   814
    """Return the initial set of revisions to be filtered or followed"""
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   815
    follow = opts.get('follow') or opts.get('follow_first')
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   816
    if opts.get('rev'):
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   817
        revs = scmutil.revrange(repo, opts['rev'])
24064
c260887cdbcd log: fix --follow null parent not to include revision 0
Yuya Nishihara <yuya@tcha.org>
parents: 24063
diff changeset
   818
    elif follow and repo.dirstate.p1() == nullid:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
   819
        revs = smartset.baseset()
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   820
    elif follow:
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   821
        revs = repo.revs('.')
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   822
    else:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
   823
        revs = smartset.spanset(repo)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   824
        revs.reverse()
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   825
    return revs
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   826
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   827
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   828
def getrevs(repo, pats, opts):
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   829
    """Return (revs, differ) where revs is a smartset
35548
b14c8bcfbad9 log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35547
diff changeset
   830
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   831
    differ is a changesetdiffer with pre-configured file matcher.
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   832
    """
35684
1c929b4942a3 log: resolve --follow with -rREV in cmdutil.getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35683
diff changeset
   833
    follow = opts.get('follow') or opts.get('follow_first')
1c929b4942a3 log: resolve --follow with -rREV in cmdutil.getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35683
diff changeset
   834
    followfirst = opts.get('follow_first')
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   835
    limit = getlimit(opts)
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   836
    revs = _initialrevs(repo, opts)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   837
    if not revs:
35548
b14c8bcfbad9 log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35547
diff changeset
   838
        return smartset.baseset(), None
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   839
    match, pats, slowpath = _makematcher(repo, revs, pats, opts)
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   840
    filematcher = None
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   841
    if follow:
35688
84d0e99c063a log: replace "not pats" with matcher attribute for consistency
Yuya Nishihara <yuya@tcha.org>
parents: 35687
diff changeset
   842
        if slowpath or match.always():
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   843
            revs = dagop.revancestors(repo, revs, followfirst=followfirst)
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   844
        else:
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   845
            revs, filematcher = _fileancestors(repo, revs, match, followfirst)
35684
1c929b4942a3 log: resolve --follow with -rREV in cmdutil.getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35683
diff changeset
   846
        revs.reverse()
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   847
    if filematcher is None:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   848
        filematcher = _makenofollowfilematcher(repo, pats, opts)
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   849
    if filematcher is None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   850
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   851
        def filematcher(ctx):
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   852
            return match
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   853
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   854
    expr = _makerevset(repo, match, pats, slowpath, opts)
42308
1ce46f0ee218 log: remove an unnecessary "and opts.get('rev')" condition
Martin von Zweigbergk <martinvonz@google.com>
parents: 42010
diff changeset
   855
    if opts.get('graph'):
24060
eb1c9700d19d graphlog: move comment and flag denoting revs might be unsorted
Yuya Nishihara <yuya@tcha.org>
parents: 24059
diff changeset
   856
        # User-specified revs might be unsorted, but don't sort before
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   857
        # _makerevset because it might depend on the order of revs
42309
604c086ddde6 log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents: 42308
diff changeset
   858
        if repo.ui.configbool('experimental', 'log.topo'):
604c086ddde6 log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents: 42308
diff changeset
   859
            if not revs.istopo():
604c086ddde6 log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents: 42308
diff changeset
   860
                revs = dagop.toposort(revs, repo.changelog.parentrevs)
604c086ddde6 log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents: 42308
diff changeset
   861
                # TODO: try to iterate the set lazily
42319
b162229ebe0d log: flag topo-sorted set as such
Yuya Nishihara <yuya@tcha.org>
parents: 42309
diff changeset
   862
                revs = revset.baseset(list(revs), istopo=True)
42309
604c086ddde6 log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents: 42308
diff changeset
   863
        elif not (revs.isdescending() or revs.istopo()):
29335
631617262e55 graphmod: avoid sorting when already sorted
Martijn Pieters <mjpieters@fb.com>
parents: 29327
diff changeset
   864
            revs.sort(reverse=True)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   865
    if expr:
35547
b6dbc860570d log: don't expand aliases in revset built from command options
Yuya Nishihara <yuya@tcha.org>
parents: 35545
diff changeset
   866
        matcher = revset.match(None, expr)
34019
205c47e30a93 revset: make match function follow given subset if specified (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34018
diff changeset
   867
        revs = matcher(repo, revs)
18243
b3b1b8e127e5 log: use "hidden" filtering instead of manual check at display time
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18235
diff changeset
   868
    if limit is not None:
35544
8494944940e5 log: use smartset.slice() to limit number of revisions to be displayed
Yuya Nishihara <yuya@tcha.org>
parents: 35543
diff changeset
   869
        revs = revs.slice(0, limit)
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   870
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   871
    differ = changesetdiffer()
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   872
    differ._makefilematcher = filematcher
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   873
    return revs, differ
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   874
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   875
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   876
def _parselinerangeopt(repo, opts):
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   877
    """Parse --line-range log option and return a list of tuples (filename,
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   878
    (fromline, toline)).
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   879
    """
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   880
    linerangebyfname = []
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   881
    for pat in opts.get('line_range', []):
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   882
        try:
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   883
            pat, linerange = pat.rsplit(',', 1)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   884
        except ValueError:
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   885
            raise error.Abort(_('malformatted line-range pattern %s') % pat)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   886
        try:
34905
5c7dbb730179 log: switch to FROMLINE:TOLINE syntax for -L/--line-range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34904
diff changeset
   887
            fromline, toline = map(int, linerange.split(':'))
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   888
        except ValueError:
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   889
            raise error.Abort(_("invalid line range for %s") % pat)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   890
        msg = _("line range pattern '%s' must match exactly one file") % pat
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   891
        fname = scmutil.parsefollowlinespattern(repo, None, pat, msg)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   892
        linerangebyfname.append(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   893
            (fname, util.processlinerange(fromline, toline))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   894
        )
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   895
    return linerangebyfname
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   896
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   897
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   898
def getlinerangerevs(repo, userrevs, opts):
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   899
    """Return (revs, differ).
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   900
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   901
    "revs" are revisions obtained by processing "line-range" log options and
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   902
    walking block ancestors of each specified file/line-range.
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   903
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   904
    "differ" is a changesetdiffer with pre-configured file matcher and hunks
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   905
    filter.
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   906
    """
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   907
    wctx = repo[None]
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   908
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   909
    # Two-levels map of "rev -> file ctx -> [line range]".
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   910
    linerangesbyrev = {}
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   911
    for fname, (fromline, toline) in _parselinerangeopt(repo, opts):
34907
0ccfc468423a log: handle removed files with --line-range patterns
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34905
diff changeset
   912
        if fname not in wctx:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   913
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   914
                _('cannot follow file not in parent ' 'revision: "%s"') % fname
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   915
            )
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   916
        fctx = wctx.filectx(fname)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   917
        for fctx, linerange in dagop.blockancestors(fctx, fromline, toline):
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   918
            rev = fctx.introrev()
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   919
            if rev not in userrevs:
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   920
                continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   921
            linerangesbyrev.setdefault(rev, {}).setdefault(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   922
                fctx.path(), []
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   923
            ).append(linerange)
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   924
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   925
    def nofilterhunksfn(fctx, hunks):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   926
        return hunks
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   927
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   928
    def hunksfilter(ctx):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   929
        fctxlineranges = linerangesbyrev.get(ctx.rev())
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   930
        if fctxlineranges is None:
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   931
            return nofilterhunksfn
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   932
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   933
        def filterfn(fctx, hunks):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   934
            lineranges = fctxlineranges.get(fctx.path())
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   935
            if lineranges is not None:
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   936
                for hr, lines in hunks:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   937
                    if hr is None:  # binary
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   938
                        yield hr, lines
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   939
                        continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   940
                    if any(mdiff.hunkinrange(hr[2:], lr) for lr in lineranges):
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   941
                        yield hr, lines
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   942
            else:
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   943
                for hunk in hunks:
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   944
                    yield hunk
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   945
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   946
        return filterfn
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   947
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   948
    def filematcher(ctx):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   949
        files = list(linerangesbyrev.get(ctx.rev(), []))
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   950
        return scmutil.matchfiles(repo, files)
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   951
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   952
    revs = sorted(linerangesbyrev, reverse=True)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   953
36007
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   954
    differ = changesetdiffer()
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   955
    differ._makefilematcher = filematcher
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   956
    differ._makehunksfilter = hunksfilter
29b83c08afe0 log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents: 36005
diff changeset
   957
    return revs, differ
34857
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   958
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   959
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   960
def _graphnodeformatter(ui, displayer):
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   961
    spec = ui.config('ui', 'graphnodetemplate')
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   962
    if not spec:
36513
6ad140dc4269 templatekw: extract non-templatekw function as getgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 36441
diff changeset
   963
        return templatekw.getgraphnode  # fast path for "{graphnode}"
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   964
32045
3eceeede26e9 graphlog: optionally strip quotes from graphnode template (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 32005
diff changeset
   965
    spec = templater.unquotestring(spec)
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   966
    if isinstance(displayer, changesettemplater):
36982
255f635c3204 templater: convert resources to a table of callables for future extension
Yuya Nishihara <yuya@tcha.org>
parents: 36920
diff changeset
   967
        # reuse cache of slow templates
37072
d64ae4fef471 log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents: 36989
diff changeset
   968
        tres = displayer._tresources
d64ae4fef471 log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents: 36989
diff changeset
   969
    else:
d64ae4fef471 log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents: 36989
diff changeset
   970
        tres = formatter.templateresources(ui)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   971
    templ = formatter.maketemplater(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   972
        ui, spec, defaults=templatekw.keywords, resources=tres
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   973
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   974
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   975
    def formatnode(repo, ctx):
37103
be3f33f5e232 templater: switch 'revcache' based on new mapping items
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
   976
        props = {'ctx': ctx, 'repo': repo}
36988
317382151ac3 templater: rename .render(mapping) to .renderdefault(mapping) (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36982
diff changeset
   977
        return templ.renderdefault(props)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   978
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   979
    return formatnode
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   980
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   981
42504
a68350a7fc55 log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42502
diff changeset
   982
def displaygraph(ui, repo, dag, displayer, edgefn, getcopies=None, props=None):
34189
e9898ad31115 cmdutil: allow extra properties to be added to each context
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34121
diff changeset
   983
    props = props or {}
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   984
    formatnode = _graphnodeformatter(ui, displayer)
28375
97cb1aeaca78 graphmod: refactor state handling
Martijn Pieters <mjpieters@fb.com>
parents: 28322
diff changeset
   985
    state = graphmod.asciistate()
28600
0d6137891114 graphmod: allow for different styles for different edge types
Martijn Pieters <mjpieters@fb.com>
parents: 28570
diff changeset
   986
    styles = state['styles']
28999
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   987
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   988
    # only set graph styling if HGPLAIN is not set.
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   989
    if ui.plain('graph'):
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   990
        # set all edge styles to |, the default pre-3.8 behaviour
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   991
        styles.update(dict.fromkeys(styles, '|'))
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   992
    else:
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   993
        edgetypes = {
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   994
            'parent': graphmod.PARENT,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   995
            'grandparent': graphmod.GRANDPARENT,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
   996
            'missing': graphmod.MISSINGPARENT,
28999
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   997
        }
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   998
        for name, key in edgetypes.items():
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   999
            # experimental config: experimental.graphstyle.*
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1000
            styles[key] = ui.config(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1001
                'experimental', 'graphstyle.%s' % name, styles[key]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1002
            )
28999
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  1003
            if not styles[key]:
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  1004
                styles[key] = None
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  1005
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  1006
        # experimental config: experimental.graphshorten
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  1007
        state['graphshorten'] = ui.configbool('experimental', 'graphshorten')
28891
ac30adb260ea graphmod: shorten graph
santiagopim <santiagopim@gmail.com>
parents: 28861
diff changeset
  1008
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1009
    for rev, type, ctx, parents in dag:
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  1010
        char = formatnode(repo, ctx)
42504
a68350a7fc55 log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42502
diff changeset
  1011
        copies = getcopies(ctx) if getcopies else None
33858
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
  1012
        edges = edgefn(type, char, state, rev, parents)
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
  1013
        firstedge = next(edges)
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
  1014
        width = firstedge[2]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1015
        displayer.show(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1016
            ctx, copies=copies, graphwidth=width, **pycompat.strkwargs(props)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1017
        )
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1018
        lines = displayer.hunk.pop(rev).split('\n')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1019
        if not lines[-1]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1020
            del lines[-1]
25763
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
  1021
        displayer.flush(ctx)
33858
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
  1022
        for type, char, width, coldata in itertools.chain([firstedge], edges):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1023
            graphmod.ascii(ui, state, type, char, lines, coldata)
33858
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
  1024
            lines = []
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1025
    displayer.close()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1026
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1027
36198
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1028
def displaygraphrevs(ui, repo, revs, displayer, getrenamed):
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1029
    revdag = graphmod.dagwalker(repo, revs)
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
  1030
    displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed)
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1031
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1032
42504
a68350a7fc55 log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42502
diff changeset
  1033
def displayrevs(ui, repo, revs, displayer, getcopies):
36198
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1034
    for rev in revs:
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1035
        ctx = repo[rev]
42504
a68350a7fc55 log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42502
diff changeset
  1036
        copies = getcopies(ctx) if getcopies else None
36198
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1037
        displayer.show(ctx, copies=copies)
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1038
        displayer.flush(ctx)
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1039
    displayer.close()
7bc10d3f68b4 log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 36196
diff changeset
  1040
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1041
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1042
def checkunsupportedgraphflags(pats, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1043
    for op in ["newest_first"]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1044
        if op in opts and opts[op]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1045
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1046
                _("-G/--graph option is incompatible with --%s")
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1047
                % op.replace("_", "-")
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1048
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42504
diff changeset
  1049
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1050
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1051
def graphrevs(repo, nodes, opts):
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
  1052
    limit = getlimit(opts)
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1053
    nodes.reverse()
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1054
    if limit is not None:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1055
        nodes = nodes[:limit]
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1056
    return graphmod.nodes(repo, nodes)