mercurial/logcmdutil.py
author Yuya Nishihara <yuya@tcha.org>
Sun, 21 Jan 2018 15:34:37 +0900
changeset 36005 dd77e36eabb6
parent 36004 d4c210ee894f
child 36007 29b83c08afe0
permissions -rw-r--r--
logcmdutil: create hunksfilter and filematcher even if no diff option given It's okay since 5fe6f946f111, "log: allow matchfn to be non-null even if both --patch/--stat are off."
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
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    12
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    13
from .i18n import _
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    14
from .node import (
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    15
    hex,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    16
    nullid,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    17
)
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    18
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    19
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
    20
    dagop,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    21
    encoding,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    22
    error,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    23
    formatter,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    24
    graphmod,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    25
    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
    26
    mdiff,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    27
    patch,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    28
    pathutil,
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30506
diff changeset
    29
    pycompat,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    30
    revset,
35644
7a0a90d63a8c log: use revsetlang.formatspec() to concatenate list expression
Yuya Nishihara <yuya@tcha.org>
parents: 35643
diff changeset
    31
    revsetlang,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    32
    scmutil,
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
    33
    smartset,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    34
    templatekw,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    35
    templater,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    36
    util,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    37
)
21405
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
    38
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
    39
def getlimit(opts):
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    40
    """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
    41
    limit = opts.get('limit')
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    42
    if limit:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    43
        try:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    44
            limit = int(limit)
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    45
        except ValueError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
    46
            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
    47
        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
    48
            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
    49
    else:
10111
27457d31ae3f cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10061
diff changeset
    50
        limit = None
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    51
    return limit
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
    52
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    53
def diffordiffstat(ui, repo, diffopts, node1, node2, match,
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
    54
                   changes=None, stat=False, fp=None, prefix='',
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
    55
                   root='', listsubrepos=False, hunksfilterfn=None):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    56
    '''show diff or diffstat.'''
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    57
    if fp is None:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    58
        write = ui.write
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    59
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    60
        def write(s, **kw):
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    61
            fp.write(s)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    62
24455
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
    63
    if root:
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
    64
        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
    65
    else:
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    66
        relroot = ''
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    67
    if relroot != '':
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    68
        # 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
    69
        # subrepo
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    70
        uirelroot = match.uipath(relroot)
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    71
        relroot += '/'
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    72
        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
    73
            if not matchroot.startswith(relroot):
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    74
                ui.warn(_('warning: %s not inside relative root %s\n') % (
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    75
                    match.uipath(matchroot), uirelroot))
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
    76
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    77
    if stat:
35430
058c725925e3 diff: disable diff.noprefix option for diffstat (issue5759)
Yuya Nishihara <yuya@tcha.org>
parents: 35026
diff changeset
    78
        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
    79
        width = 80
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    80
        if not ui.plain():
12689
c52c629ce19e termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents: 12619
diff changeset
    81
            width = ui.termwidth()
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    82
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    83
    chunks = patch.diff(repo, node1, node2, match, changes, opts=diffopts,
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    84
                        prefix=prefix, relroot=relroot,
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    85
                        hunksfilterfn=hunksfilterfn)
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    86
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    87
    if fp is not None or ui.canwritewithoutlabels():
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    88
        if stat:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    89
            chunks = patch.diffstat(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
    90
        for chunk in util.filechunkiter(util.chunkbuffer(chunks)):
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    91
            write(chunk)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
    92
    else:
35961
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    93
        if stat:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    94
            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
    95
        else:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    96
            chunks = patch.difflabel(lambda chunks, **kwargs: chunks, chunks,
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    97
                                     opts=diffopts)
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    98
        if ui.canbatchlabeledwrites():
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
    99
            def gen():
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   100
                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
   101
                    yield ui.label(chunk, label=label)
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   102
            for chunk in util.filechunkiter(util.chunkbuffer(gen())):
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   103
                write(chunk)
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   104
        else:
0ff41ced4c12 diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents: 35955
diff changeset
   105
            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
   106
                write(chunk, label=label)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   107
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   108
    if listsubrepos:
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   109
        ctx1 = repo[node1]
12175
c0a8f9dea0f6 subrepos: handle modified but uncommitted .hgsub
Martin Geisler <mg@lazybytes.net>
parents: 12167
diff changeset
   110
        ctx2 = repo[node2]
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
   111
        for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
15698
43e068c15619 diff: when diffing a revision with a deleted subrepo, maintain the node context (issue3153)
Alistair Bell <alistair.bell@netronome.com>
parents: 15634
diff changeset
   112
            tempnode2 = node2
15634
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   113
            try:
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   114
                if node2 is not None:
15698
43e068c15619 diff: when diffing a revision with a deleted subrepo, maintain the node context (issue3153)
Alistair Bell <alistair.bell@netronome.com>
parents: 15634
diff changeset
   115
                    tempnode2 = ctx2.substate[subpath][1]
15634
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   116
            except KeyError:
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   117
                # A subrepo that existed in node1 was deleted between node1 and
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   118
                # node2 (inclusive). Thus, ctx2's substate won't contain that
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   119
                # subpath. The best we can do is to ignore it.
15698
43e068c15619 diff: when diffing a revision with a deleted subrepo, maintain the node context (issue3153)
Alistair Bell <alistair.bell@netronome.com>
parents: 15634
diff changeset
   120
                tempnode2 = None
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
   121
            submatch = matchmod.subdirmatcher(subpath, match)
18006
0c10cf819146 subrepo: add argument to "diff()" to pass "ui" of caller side (issue3712) (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17924
diff changeset
   122
            sub.diff(ui, diffopts, tempnode2, submatch, changes=changes,
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   123
                     stat=stat, fp=fp, prefix=prefix)
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   124
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   125
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
   126
    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
   127
    if ctx.obsolete():
9b3577796291 cmdutil: add a "changeset.obsolete" label in changeset_printer
Denis Laxalde <denis@laxalde.org>
parents: 31486
diff changeset
   128
        labels.append('changeset.obsolete')
33730
52c5ff856b49 context: rename troubled into isunstable
Boris Feld <boris.feld@octobus.net>
parents: 33726
diff changeset
   129
    if ctx.isunstable():
33781
3821dfee2cfc label: rename changeset.troubled into changeset.unstable
Boris Feld <boris.feld@octobus.net>
parents: 33771
diff changeset
   130
        labels.append('changeset.unstable')
33726
ab0c55c2ad9a context: rename troubles into instabilities
Boris Feld <boris.feld@octobus.net>
parents: 33694
diff changeset
   131
        for instability in ctx.instabilities():
33782
40739aef97f7 label: rename trouble.X into instability.X
Boris Feld <boris.feld@octobus.net>
parents: 33781
diff changeset
   132
            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
   133
    return ' '.join(labels)
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
   134
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   135
class changesetprinter(object):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   136
    '''show changeset information when templating not requested.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   137
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   138
    def __init__(self, ui, repo, makefilematcher=None, makehunksfilter=None,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   139
                 diffopts=None, buffered=False):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   140
        self.ui = ui
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   141
        self.repo = repo
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   142
        self.buffered = buffered
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   143
        self._makefilematcher = makefilematcher or (lambda ctx: None)
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   144
        self._makehunksfilter = makehunksfilter or (lambda ctx: None)
35953
64f4a6808704 logcmdutil: make default parameters of changesetprinters consistent
Yuya Nishihara <yuya@tcha.org>
parents: 35887
diff changeset
   145
        self.diffopts = diffopts or {}
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   146
        self.header = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   147
        self.hunk = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   148
        self.lastheader = None
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   149
        self.footer = None
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   150
        self._columns = templatekw.getlogcolumns()
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   151
25763
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
   152
    def flush(self, ctx):
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
   153
        rev = ctx.rev()
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   154
        if rev in self.header:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   155
            h = self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   156
            if h != self.lastheader:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   157
                self.lastheader = h
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   158
                self.ui.write(h)
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   159
            del self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   160
        if rev in self.hunk:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   161
            self.ui.write(self.hunk[rev])
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   162
            del self.hunk[rev]
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   163
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   164
    def close(self):
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   165
        if self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   166
            self.ui.write(self.footer)
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   167
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   168
    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
   169
        props = pycompat.byteskwargs(props)
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   170
        if self.buffered:
27107
c57ebef70f6f cmdutil: pass labeled=True to pushbuffer()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27065
diff changeset
   171
            self.ui.pushbuffer(labeled=True)
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   172
            self._show(ctx, copies, props)
27109
a93d53f79e6e ui: remove labeled argument from popbuffer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27107
diff changeset
   173
            self.hunk[ctx.rev()] = self.ui.popbuffer()
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   174
        else:
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   175
            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
   176
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   177
    def _show(self, ctx, copies, props):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   178
        '''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
   179
        changenode = ctx.node()
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   180
        rev = ctx.rev()
24584
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   181
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   182
        if self.ui.quiet:
34327
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34289
diff changeset
   183
            self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34289
diff changeset
   184
                          label='log.node')
24584
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   185
            return
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
   186
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   187
        columns = self._columns
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   188
        self.ui.write(columns['changeset'] % scmutil.formatchangeid(ctx),
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   189
                      label=changesetlabels(ctx))
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   190
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   191
        # 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
   192
        # compatibility
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   193
        branch = ctx.branch()
4176
f9bbcebcacea "default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4055
diff changeset
   194
        # 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
   195
        if branch != 'default':
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   196
            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
   197
28904
80be5dbe6e74 cmdutil: avoid recycling variable name "name" in namespaces code
Nathaniel Manista <nathaniel@google.com>
parents: 28891
diff changeset
   198
        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
   199
            # 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
   200
            # skip it
28904
80be5dbe6e74 cmdutil: avoid recycling variable name "name" in namespaces code
Nathaniel Manista <nathaniel@google.com>
parents: 28891
diff changeset
   201
            if nsname == 'branches':
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   202
                continue
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   203
            # 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
   204
            # should be the same
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   205
            for name in ns.names(self.repo, changenode):
23967
448bb32b8ee6 namespace: introduce logfmt to show l10n-ed messages for hg log correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23965
diff changeset
   206
                self.ui.write(ns.logfmt % name,
448bb32b8ee6 namespace: introduce logfmt to show l10n-ed messages for hg log correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23965
diff changeset
   207
                              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
   208
        if self.ui.debugflag:
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   209
            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
   210
        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
   211
            label = 'log.parent changeset.%s' % pctx.phasestr()
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   212
            self.ui.write(columns['parent'] % scmutil.formatchangeid(pctx),
22301
f6371cc62d2a log: use correct phase info for parent field (issue4347)
Sean Farley <sean.michael.farley@gmail.com>
parents: 22167
diff changeset
   213
                          label=label)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   214
24585
e191d5d8d515 changeset_printer: hide manifest node for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24584
diff changeset
   215
        if self.ui.debugflag and rev is not None:
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   216
            mnode = ctx.manifestnode()
34327
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34289
diff changeset
   217
            mrev = self.repo.manifestlog._revlog.rev(mnode)
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   218
            self.ui.write(columns['manifest']
34327
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34289
diff changeset
   219
                          % scmutil.formatrevnode(self.ui, mrev, mnode),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   220
                          label='ui.debug log.manifest')
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   221
        self.ui.write(columns['user'] % ctx.user(), label='log.user')
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   222
        self.ui.write(columns['date'] % util.datestr(ctx.date()),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   223
                      label='log.date')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   224
33730
52c5ff856b49 context: rename troubled into isunstable
Boris Feld <boris.feld@octobus.net>
parents: 33726
diff changeset
   225
        if ctx.isunstable():
33726
ab0c55c2ad9a context: rename troubles into instabilities
Boris Feld <boris.feld@octobus.net>
parents: 33694
diff changeset
   226
            instabilities = ctx.instabilities()
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   227
            self.ui.write(columns['instability'] % ', '.join(instabilities),
33783
db6b666ce1e6 label: rename log.trouble into log.instability
Boris Feld <boris.feld@octobus.net>
parents: 33782
diff changeset
   228
                          label='log.instability')
30695
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
   229
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   230
        elif ctx.obsolete():
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   231
            self._showobsfate(ctx)
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   232
33154
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   233
        self._exthook(ctx)
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   234
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   235
        if self.ui.debugflag:
24485
914caae9a86a changeset_printer: use changectx to get status tuple
Yuya Nishihara <yuya@tcha.org>
parents: 24484
diff changeset
   236
            files = ctx.p1().status(ctx)[:3]
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   237
            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
   238
                if value:
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   239
                    self.ui.write(columns[key] % " ".join(value),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   240
                                  label='ui.debug log.files')
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   241
        elif ctx.files() and self.ui.verbose:
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   242
            self.ui.write(columns['files'] % " ".join(ctx.files()),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   243
                          label='ui.note log.files')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   244
        if copies and self.ui.verbose:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   245
            copies = ['%s (%s)' % c for c in copies]
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   246
            self.ui.write(columns['copies'] % ' '.join(copies),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   247
                          label='ui.note log.copies')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   248
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   249
        extra = ctx.extra()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   250
        if extra and self.ui.debugflag:
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
   251
            for key, value in sorted(extra.items()):
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   252
                self.ui.write(columns['extra'] % (key, util.escapestr(value)),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   253
                              label='ui.debug log.extra')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   254
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   255
        description = ctx.description().strip()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   256
        if description:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   257
            if self.ui.verbose:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   258
                self.ui.write(_("description:\n"),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   259
                              label='ui.note log.description')
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   260
                self.ui.write(description,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   261
                              label='ui.note log.description')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   262
                self.ui.write("\n\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   263
            else:
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   264
                self.ui.write(columns['summary'] % description.splitlines()[0],
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   265
                              label='log.summary')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   266
        self.ui.write("\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   267
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   268
        self._showpatch(ctx)
27065
93bcc73df8d5 cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26938
diff changeset
   269
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   270
    def _showobsfate(self, ctx):
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   271
        obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx, ui=self.ui)
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   272
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   273
        if obsfate:
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   274
            for obsfateline in obsfate:
35212
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35211
diff changeset
   275
                self.ui.write(self._columns['obsolete'] % obsfateline,
34852
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   276
                              label='log.obsfate')
d45236f3d38e log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents: 34794
diff changeset
   277
33154
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   278
    def _exthook(self, ctx):
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   279
        '''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
   280
        '''
4ecc6047d45f log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents: 33102
diff changeset
   281
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   282
    def _showpatch(self, ctx):
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   283
        matchfn = self._makefilematcher(ctx)
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   284
        hunksfilterfn = self._makehunksfilter(ctx)
36004
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   285
        if not matchfn:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   286
            return
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   287
        stat = self.diffopts.get('stat')
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   288
        diff = self.diffopts.get('patch')
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   289
        diffopts = patch.diffallopts(self.ui, self.diffopts)
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   290
        node = ctx.node()
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   291
        prev = ctx.p1().node()
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   292
        if stat:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   293
            diffordiffstat(self.ui, self.repo, diffopts, prev, node,
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   294
                           match=matchfn, stat=True,
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   295
                           hunksfilterfn=hunksfilterfn)
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   296
        if stat and diff:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   297
            self.ui.write("\n")
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   298
        if diff:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   299
            diffordiffstat(self.ui, self.repo, diffopts, prev, node,
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   300
                           match=matchfn, stat=False,
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   301
                           hunksfilterfn=hunksfilterfn)
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   302
        if stat or diff:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   303
            self.ui.write("\n")
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   304
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   305
class jsonchangeset(changesetprinter):
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   306
    '''format changeset information.'''
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   307
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   308
    def __init__(self, ui, repo, makefilematcher=None, makehunksfilter=None,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   309
                 diffopts=None, buffered=False):
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   310
        changesetprinter.__init__(self, ui, repo, makefilematcher,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   311
                                  makehunksfilter, diffopts, buffered)
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   312
        self.cache = {}
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   313
        self._first = True
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   314
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   315
    def close(self):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   316
        if not self._first:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   317
            self.ui.write("\n]\n")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   318
        else:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   319
            self.ui.write("[]\n")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   320
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   321
    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
   322
        '''show a single changeset or file revision'''
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   323
        rev = ctx.rev()
24602
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
   324
        if rev is None:
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
   325
            jrev = jnode = 'null'
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
   326
        else:
32155
055cca8e167b py3: use %d to format integers into bytestrings
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32153
diff changeset
   327
            jrev = '%d' % rev
24602
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
   328
            jnode = '"%s"' % hex(ctx.node())
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   329
        j = encoding.jsonescape
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   330
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   331
        if self._first:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   332
            self.ui.write("[\n {")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   333
            self._first = False
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   334
        else:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   335
            self.ui.write(",\n {")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   336
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   337
        if self.ui.quiet:
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   338
            self.ui.write(('\n  "rev": %s') % jrev)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   339
            self.ui.write((',\n  "node": %s') % jnode)
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   340
            self.ui.write('\n }')
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   341
            return
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   342
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   343
        self.ui.write(('\n  "rev": %s') % jrev)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   344
        self.ui.write((',\n  "node": %s') % jnode)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   345
        self.ui.write((',\n  "branch": "%s"') % j(ctx.branch()))
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   346
        self.ui.write((',\n  "phase": "%s"') % ctx.phasestr())
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   347
        self.ui.write((',\n  "user": "%s"') % j(ctx.user()))
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   348
        self.ui.write((',\n  "date": [%d, %d]') % ctx.date())
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   349
        self.ui.write((',\n  "desc": "%s"') % j(ctx.description()))
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   350
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   351
        self.ui.write((',\n  "bookmarks": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   352
                      ", ".join('"%s"' % j(b) for b in ctx.bookmarks()))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   353
        self.ui.write((',\n  "tags": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   354
                      ", ".join('"%s"' % j(t) for t in ctx.tags()))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   355
        self.ui.write((',\n  "parents": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   356
                      ", ".join('"%s"' % c.hex() for c in ctx.parents()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   357
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   358
        if self.ui.debugflag:
24603
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
   359
            if rev is None:
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
   360
                jmanifestnode = 'null'
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
   361
            else:
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
   362
                jmanifestnode = '"%s"' % hex(ctx.manifestnode())
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   363
            self.ui.write((',\n  "manifest": %s') % jmanifestnode)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   364
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   365
            self.ui.write((',\n  "extra": {%s}') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   366
                          ", ".join('"%s": "%s"' % (j(k), j(v))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   367
                                    for k, v in ctx.extra().items()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   368
23734
f4e6475950f1 cmdutil.jsonchangeset: properly compute added and removed files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23501
diff changeset
   369
            files = ctx.p1().status(ctx)
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   370
            self.ui.write((',\n  "modified": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   371
                          ", ".join('"%s"' % j(f) for f in files[0]))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   372
            self.ui.write((',\n  "added": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   373
                          ", ".join('"%s"' % j(f) for f in files[1]))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   374
            self.ui.write((',\n  "removed": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   375
                          ", ".join('"%s"' % j(f) for f in files[2]))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   376
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   377
        elif self.ui.verbose:
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   378
            self.ui.write((',\n  "files": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   379
                          ", ".join('"%s"' % j(f) for f in ctx.files()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   380
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   381
            if copies:
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
   382
                self.ui.write((',\n  "copies": {%s}') %
24013
942a5a34b2d0 log: fix json-formatted output when file copies are listed (issue4523)
Augie Fackler <augie@google.com>
parents: 23967
diff changeset
   383
                              ", ".join('"%s": "%s"' % (j(k), j(v))
942a5a34b2d0 log: fix json-formatted output when file copies are listed (issue4523)
Augie Fackler <augie@google.com>
parents: 23967
diff changeset
   384
                                                        for k, v in copies))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   385
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   386
        matchfn = self._makefilematcher(ctx)
36004
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   387
        stat = self.diffopts.get('stat')
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   388
        diff = self.diffopts.get('patch')
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   389
        diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   390
        node, prev = ctx.node(), ctx.p1().node()
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   391
        if matchfn and stat:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   392
            self.ui.pushbuffer()
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   393
            diffordiffstat(self.ui, self.repo, diffopts, prev, node,
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   394
                           match=matchfn, stat=True)
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   395
            self.ui.write((',\n  "diffstat": "%s"')
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   396
                          % j(self.ui.popbuffer()))
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   397
        if matchfn and diff:
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   398
            self.ui.pushbuffer()
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   399
            diffordiffstat(self.ui, self.repo, diffopts, prev, node,
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   400
                           match=matchfn, stat=False)
d4c210ee894f logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents: 36003
diff changeset
   401
            self.ui.write((',\n  "diff": "%s"') % j(self.ui.popbuffer()))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   402
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   403
        self.ui.write("\n }")
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
   404
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   405
class changesettemplater(changesetprinter):
35107
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   406
    '''format changeset information.
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   407
b22a0d9e0a83 docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents: 35007
diff changeset
   408
    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
   409
    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
   410
    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
   411
    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
   412
    '''
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   413
33045
99c6c9fa9e6d cmdutil: use named arguments for changeset_templater.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32953
diff changeset
   414
    # 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
   415
    # adding/removing arguments before "buffered" to not break callers.
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   416
    def __init__(self, ui, repo, tmplspec, makefilematcher=None,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   417
                 makehunksfilter=None, diffopts=None, buffered=False):
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   418
        changesetprinter.__init__(self, ui, repo, makefilematcher,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   419
                                  makehunksfilter, diffopts, buffered)
35469
f1c54d003327 templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents: 35468
diff changeset
   420
        tres = formatter.templateresources(ui, repo)
35483
817a3d20dd01 templater: register keywords to defaults table
Yuya Nishihara <yuya@tcha.org>
parents: 35469
diff changeset
   421
        self.t = formatter.loadtemplater(ui, tmplspec,
817a3d20dd01 templater: register keywords to defaults table
Yuya Nishihara <yuya@tcha.org>
parents: 35469
diff changeset
   422
                                         defaults=templatekw.keywords,
817a3d20dd01 templater: register keywords to defaults table
Yuya Nishihara <yuya@tcha.org>
parents: 35469
diff changeset
   423
                                         resources=tres,
32832
11e667a8fcba formatter: factor out function to create templater from literal or map file
Yuya Nishihara <yuya@tcha.org>
parents: 32831
diff changeset
   424
                                         cache=templatekw.defaulttempl)
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31698
diff changeset
   425
        self._counter = itertools.count()
35469
f1c54d003327 templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents: 35468
diff changeset
   426
        self.cache = tres['cache']  # shared with _graphnodeformatter()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   427
32842
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
   428
        self._tref = tmplspec.ref
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
   429
        self._parts = {'header': '', 'footer': '',
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
   430
                       tmplspec.ref: tmplspec.ref,
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   431
                       'docheader': '', 'docfooter': '',
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   432
                       'separator': ''}
32947
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   433
        if tmplspec.mapfile:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   434
            # 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
   435
            # 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
   436
            tmplmodes = [
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   437
                (True, ''),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   438
                (self.ui.verbose, '_verbose'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   439
                (self.ui.quiet, '_quiet'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   440
                (self.ui.debugflag, '_debug'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   441
            ]
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   442
            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
   443
                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
   444
                    cur = t + postfix
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
   445
                    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
   446
                        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
   447
        else:
6d79e9109908 changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32951
diff changeset
   448
            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
   449
            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
   450
            self._parts.update(m)
26086
3670efdc7088 templater: move verbosity-to-template matcher to constructor
Matt Mackall <mpm@selenic.com>
parents: 26085
diff changeset
   451
26222
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   452
        if self._parts['docheader']:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   453
            self.ui.write(templater.stringify(self.t(self._parts['docheader'])))
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   454
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   455
    def close(self):
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   456
        if self._parts['docfooter']:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   457
            if not self.footer:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   458
                self.footer = ""
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
   459
            self.footer += templater.stringify(self.t(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
   460
        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
   461
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   462
    def _show(self, ctx, copies, props):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   463
        '''show a single changeset or file revision'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   464
        props = props.copy()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   465
        props['ctx'] = ctx
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   466
        props['index'] = index = next(self._counter)
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   467
        props['revcache'] = {'copies': copies}
32289
770bbfdc9644 py3: convert kwargs' keys to str using pycompat.strkwargs
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32174
diff changeset
   468
        props = pycompat.strkwargs(props)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   469
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   470
        # 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
   471
        # 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
   472
        # separator (per item)
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   473
        if self._parts['separator'] and index > 0:
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   474
            self.ui.write(templater.stringify(self.t(self._parts['separator'])))
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
   475
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   476
        # write header
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   477
        if self._parts['header']:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   478
            h = templater.stringify(self.t(self._parts['header'], **props))
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   479
            if self.buffered:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   480
                self.header[ctx.rev()] = h
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   481
            else:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   482
                if self.lastheader != h:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   483
                    self.lastheader = h
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   484
                    self.ui.write(h)
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   485
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   486
        # 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
   487
        key = self._parts[self._tref]
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   488
        self.ui.write(templater.stringify(self.t(key, **props)))
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   489
        self._showpatch(ctx)
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   490
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   491
        if self._parts['footer']:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   492
            if not self.footer:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   493
                self.footer = templater.stringify(
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
   494
                    self.t(self._parts['footer'], **props))
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   495
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   496
def templatespec(tmpl, mapfile):
32875
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   497
    if mapfile:
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   498
        return formatter.templatespec('changeset', tmpl, mapfile)
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   499
    else:
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   500
        return formatter.templatespec('', tmpl, None)
32838
615ec3f14aa9 formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32837
diff changeset
   501
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   502
def _lookuptemplate(ui, tmpl, style):
32835
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
   503
    """Find the template matching the given template spec or style
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
   504
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
   505
    See formatter.lookuptemplate() for details.
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   506
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   507
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   508
    # ui settings
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
   509
    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
   510
        tmpl = ui.config('ui', 'logtemplate')
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   511
        if tmpl:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   512
            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
   513
        else:
33499
0407a51b9d8c codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents: 33438
diff changeset
   514
            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
   515
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
   516
    if not tmpl and style:
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   517
        mapfile = style
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   518
        if not os.path.split(mapfile)[0]:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   519
            mapname = (templater.templatepath('map-cmdline.' + mapfile)
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   520
                       or templater.templatepath(mapfile))
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   521
            if mapname:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   522
                mapfile = mapname
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   523
        return templatespec(None, mapfile)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
   524
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
   525
    if not tmpl:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   526
        return templatespec(None, None)
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
   527
25511
c2a4dfe2a336 formatter: move most of template option helper to formatter
Matt Mackall <mpm@selenic.com>
parents: 25439
diff changeset
   528
    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
   529
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   530
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
   531
    """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
   532
    byte-string."""
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   533
    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
   534
    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
   535
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   536
def changesetdisplayer(ui, repo, opts, makefilematcher=None,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   537
                       makehunksfilter=None, buffered=False):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   538
    """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
   539
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   540
    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
   541
    1. option 'template'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   542
    2. option 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   543
    3. [ui] setting 'logtemplate'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   544
    4. [ui] setting 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   545
    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
   546
    regular display via changesetprinter() is done.
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   547
    """
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   548
    # options
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   549
    if not makefilematcher and (opts.get('patch') or opts.get('stat')):
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   550
        def makefilematcher(ctx):
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   551
            return scmutil.matchall(repo)
3837
7df171ea50cd Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents: 3827
diff changeset
   552
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   553
    postargs = (makefilematcher, makehunksfilter, opts, buffered)
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
   554
    if opts.get('template') == 'json':
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   555
        return jsonchangeset(ui, repo, *postargs)
3837
7df171ea50cd Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents: 3827
diff changeset
   556
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   557
    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
   558
32875
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
   559
    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
   560
        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
   561
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   562
    return changesettemplater(ui, repo, spec, *postargs)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   563
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   564
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
   565
    """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
   566
35687
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   567
    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
   568
35685
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   569
    Returns (match, pats, slowpath) where
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   570
    - 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
   571
    - 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
   572
    - 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
   573
    """
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   574
    # 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
   575
    # _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
   576
    # 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
   577
    # platforms without shell expansion (windows).
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   578
    wctx = repo[None]
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   579
    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
   580
    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
   581
    if not slowpath:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   582
        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
   583
        startctxs = []
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   584
        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
   585
            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
   586
        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
   587
            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
   588
                # 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
   589
                # 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
   590
                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
   591
                    slowpath = True
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   592
                    continue
67893a516272 log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents: 35686
diff changeset
   593
            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
   594
                # 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
   595
                # take the slow path.
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   596
                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
   597
                    slowpath = True
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   598
                    continue
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   599
                else:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   600
                    raise error.Abort(_('cannot follow file not in parent '
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   601
                                        'revision: "%s"') % f)
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   602
            filelog = repo.file(f)
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   603
            if not filelog:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   604
                # 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
   605
                # 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
   606
                if follow:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   607
                    raise error.Abort(
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   608
                        _('cannot follow nonexistent file: "%s"') % f)
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   609
                slowpath = True
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   610
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   611
        # 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
   612
        # 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
   613
        # 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
   614
        # 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
   615
        if slowpath:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   616
            for path in match.files():
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   617
                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
   618
                    break
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   619
            else:
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   620
                slowpath = False
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   621
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   622
    return match, pats, slowpath
659dfbd852e2 log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents: 35684
diff changeset
   623
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   624
def _fileancestors(repo, revs, match, followfirst):
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   625
    fctxs = []
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   626
    for r in revs:
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   627
        ctx = repo[r]
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   628
        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
   629
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   630
    # 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
   631
    # 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
   632
    # --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
   633
    # 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
   634
    # of the graph traversal.
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   635
    fcache = {}
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   636
    def filematcher(ctx):
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   637
        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
   638
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   639
    def revgen():
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   640
        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
   641
            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
   642
            yield rev
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   643
    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
   644
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   645
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
   646
    '''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
   647
    return None
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
   648
35642
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   649
_opt2logrevset = {
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   650
    'no_merges':        ('not merge()', None),
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   651
    'only_merges':      ('merge()', None),
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   652
    '_matchfiles':      (None, '_matchfiles(%ps)'),
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   653
    'date':             ('date(%s)', None),
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   654
    'branch':           ('branch(%s)', '%lr'),
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   655
    '_patslog':         ('filelog(%s)', '%lr'),
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   656
    'keyword':          ('keyword(%s)', '%lr'),
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   657
    'prune':            ('ancestors(%s)', 'not %lr'),
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   658
    'user':             ('user(%s)', '%lr'),
35642
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   659
}
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   660
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   661
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
   662
    """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
   663
    opts = dict(opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   664
    # follow or not follow?
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   665
    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
   666
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   667
    # 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
   668
    # the same time
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   669
    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
   670
    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
   671
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   672
    if slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   673
        # See walkchangerevs() slow path.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   674
        #
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   675
        # 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
   676
        # 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
   677
        # 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
   678
        # "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
   679
        # 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
   680
        # directory.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   681
        matchargs = ['r:', 'd:relpath']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   682
        for p in pats:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   683
            matchargs.append('p:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   684
        for p in opts.get('include', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   685
            matchargs.append('i:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   686
        for p in opts.get('exclude', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   687
            matchargs.append('x:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   688
        opts['_matchfiles'] = matchargs
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   689
    elif not follow:
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   690
        opts['_patslog'] = list(pats)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   691
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   692
    expr = []
23501
424d669118d3 log: fix log revset instability
Durham Goode <durham@fb.com>
parents: 23500
diff changeset
   693
    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
   694
        if not val:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   695
            continue
35642
e64baf32782a log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents: 35548
diff changeset
   696
        if op not in _opt2logrevset:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   697
            continue
35644
7a0a90d63a8c log: use revsetlang.formatspec() to concatenate list expression
Yuya Nishihara <yuya@tcha.org>
parents: 35643
diff changeset
   698
        revop, listop = _opt2logrevset[op]
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   699
        if revop and '%' not in revop:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   700
            expr.append(revop)
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   701
        elif not listop:
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   702
            expr.append(revsetlang.formatspec(revop, val))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   703
        else:
35645
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   704
            if revop:
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   705
                val = [revsetlang.formatspec(revop, v) for v in val]
b6b7855c79aa log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents: 35644
diff changeset
   706
            expr.append(revsetlang.formatspec(listop, val))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   707
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   708
    if expr:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   709
        expr = '(' + ' and '.join(expr) + ')'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   710
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   711
        expr = None
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   712
    return expr
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   713
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   714
def _initialrevs(repo, opts):
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   715
    """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
   716
    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
   717
    if opts.get('rev'):
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   718
        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
   719
    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
   720
        revs = smartset.baseset()
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   721
    elif follow:
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   722
        revs = repo.revs('.')
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   723
    else:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
   724
        revs = smartset.spanset(repo)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   725
        revs.reverse()
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   726
    return revs
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
   727
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   728
def getrevs(repo, pats, opts):
35548
b14c8bcfbad9 log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35547
diff changeset
   729
    """Return (revs, filematcher) where revs is a smartset
b14c8bcfbad9 log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35547
diff changeset
   730
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   731
    filematcher is a callable taking a changectx and returning a match
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   732
    objects filtering the files to be detailed when displaying the revision.
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   733
    """
35684
1c929b4942a3 log: resolve --follow with -rREV in cmdutil.getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35683
diff changeset
   734
    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
   735
    followfirst = opts.get('follow_first')
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   736
    limit = getlimit(opts)
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   737
    revs = _initialrevs(repo, opts)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   738
    if not revs:
35548
b14c8bcfbad9 log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35547
diff changeset
   739
        return smartset.baseset(), None
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   740
    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
   741
    filematcher = None
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   742
    if follow:
35688
84d0e99c063a log: replace "not pats" with matcher attribute for consistency
Yuya Nishihara <yuya@tcha.org>
parents: 35687
diff changeset
   743
        if slowpath or match.always():
35686
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   744
            revs = dagop.revancestors(repo, revs, followfirst=followfirst)
b25fa5da4ca2 log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35685
diff changeset
   745
        else:
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   746
            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
   747
        revs.reverse()
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   748
    if filematcher is None:
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   749
        filematcher = _makenofollowfilematcher(repo, pats, opts)
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   750
    if filematcher is None:
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   751
        def filematcher(ctx):
35690
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   752
            return match
3e394e0558d7 log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents: 35689
diff changeset
   753
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   754
    expr = _makerevset(repo, match, pats, slowpath, opts)
35543
a7f7eff4ec08 log: merge getlogrevs() and getgraphlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35483
diff changeset
   755
    if opts.get('graph') and opts.get('rev'):
24060
eb1c9700d19d graphlog: move comment and flag denoting revs might be unsorted
Yuya Nishihara <yuya@tcha.org>
parents: 24059
diff changeset
   756
        # 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
   757
        # _makerevset because it might depend on the order of revs
29346
38e0c83c7ee4 revset: record if a set is in topographical order
Martijn Pieters <mjpieters@fb.com>
parents: 29335
diff changeset
   758
        if not (revs.isdescending() or revs.istopo()):
29335
631617262e55 graphmod: avoid sorting when already sorted
Martijn Pieters <mjpieters@fb.com>
parents: 29327
diff changeset
   759
            revs.sort(reverse=True)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   760
    if expr:
35547
b6dbc860570d log: don't expand aliases in revset built from command options
Yuya Nishihara <yuya@tcha.org>
parents: 35545
diff changeset
   761
        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
   762
        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
   763
    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
   764
        revs = revs.slice(0, limit)
35548
b14c8bcfbad9 log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35547
diff changeset
   765
    return revs, filematcher
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   766
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   767
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
   768
    """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
   769
    (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
   770
    """
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   771
    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
   772
    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
   773
        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
   774
            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
   775
        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
   776
            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
   777
        try:
34905
5c7dbb730179 log: switch to FROMLINE:TOLINE syntax for -L/--line-range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34904
diff changeset
   778
            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
   779
        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
   780
            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
   781
        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
   782
        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
   783
        linerangebyfname.append(
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   784
            (fname, util.processlinerange(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
   785
    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
   786
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   787
def getlinerangerevs(repo, userrevs, 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
   788
    """Return (revs, filematcher, hunksfilter).
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   789
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   790
    "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
   791
    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
   792
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   793
    "filematcher(ctx) -> match" is a factory function returning a match object
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
   794
    for a given revision for file patterns specified in --line-range option.
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   795
36002
f8ad57d24252 log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents: 35961
diff changeset
   796
    "hunksfilter(ctx) -> filterfn(fctx, hunks)" is a factory function
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
   797
    returning a hunks filtering function.
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   798
    """
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   799
    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
   800
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   801
    # 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
   802
    linerangesbyrev = {}
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   803
    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
   804
        if fname not in wctx:
0ccfc468423a log: handle removed files with --line-range patterns
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34905
diff changeset
   805
            raise error.Abort(_('cannot follow file not in parent '
0ccfc468423a log: handle removed files with --line-range patterns
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34905
diff changeset
   806
                                'revision: "%s"') % fname)
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
   807
        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
   808
        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
   809
            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
   810
            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
   811
                continue
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   812
            linerangesbyrev.setdefault(
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   813
                rev, {}).setdefault(
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   814
                    fctx.path(), []).append(linerange)
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   815
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   816
    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
   817
        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
   818
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   819
    def hunksfilter(ctx):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   820
        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
   821
        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
   822
            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
   823
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   824
        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
   825
            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
   826
            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
   827
                for hr, lines in hunks:
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   828
                    if hr is None: # binary
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   829
                        yield hr, lines
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   830
                        continue
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   831
                    if any(mdiff.hunkinrange(hr[2:], lr)
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   832
                           for lr in lineranges):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   833
                        yield hr, lines
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   834
            else:
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   835
                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
   836
                    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
   837
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   838
        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
   839
36005
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   840
    def filematcher(ctx):
dd77e36eabb6 logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents: 36004
diff changeset
   841
        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
   842
        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
   843
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   844
    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
   845
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   846
    return revs, filematcher, hunksfilter
84c6b9384d6a log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34856
diff changeset
   847
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   848
def _graphnodeformatter(ui, displayer):
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   849
    spec = ui.config('ui', 'graphnodetemplate')
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   850
    if not spec:
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   851
        return templatekw.showgraphnode  # fast path for "{graphnode}"
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   852
32045
3eceeede26e9 graphlog: optionally strip quotes from graphnode template (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 32005
diff changeset
   853
    spec = templater.unquotestring(spec)
35469
f1c54d003327 templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents: 35468
diff changeset
   854
    tres = formatter.templateresources(ui)
35886
b0014780c7fc logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35885
diff changeset
   855
    if isinstance(displayer, changesettemplater):
35469
f1c54d003327 templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents: 35468
diff changeset
   856
        tres['cache'] = displayer.cache  # reuse cache of slow templates
35483
817a3d20dd01 templater: register keywords to defaults table
Yuya Nishihara <yuya@tcha.org>
parents: 35469
diff changeset
   857
    templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords,
817a3d20dd01 templater: register keywords to defaults table
Yuya Nishihara <yuya@tcha.org>
parents: 35469
diff changeset
   858
                                    resources=tres)
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   859
    def formatnode(repo, ctx):
35483
817a3d20dd01 templater: register keywords to defaults table
Yuya Nishihara <yuya@tcha.org>
parents: 35469
diff changeset
   860
        props = {'ctx': ctx, 'repo': repo, 'revcache': {}}
32873
2ecce24dfcd3 templater: add simple interface for unnamed template (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32862
diff changeset
   861
        return templ.render(props)
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   862
    return formatnode
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   863
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   864
def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=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
   865
    props = props or {}
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   866
    formatnode = _graphnodeformatter(ui, displayer)
28375
97cb1aeaca78 graphmod: refactor state handling
Martijn Pieters <mjpieters@fb.com>
parents: 28322
diff changeset
   867
    state = graphmod.asciistate()
28600
0d6137891114 graphmod: allow for different styles for different edge types
Martijn Pieters <mjpieters@fb.com>
parents: 28570
diff changeset
   868
    styles = state['styles']
28999
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   869
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   870
    # 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
   871
    if ui.plain('graph'):
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   872
        # 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
   873
        styles.update(dict.fromkeys(styles, '|'))
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   874
    else:
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   875
        edgetypes = {
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   876
            'parent': graphmod.PARENT,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   877
            'grandparent': graphmod.GRANDPARENT,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   878
            'missing': graphmod.MISSINGPARENT
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   879
        }
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   880
        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
   881
            # experimental config: experimental.graphstyle.*
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   882
            styles[key] = ui.config('experimental', 'graphstyle.%s' % name,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   883
                                    styles[key])
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   884
            if not styles[key]:
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   885
                styles[key] = None
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   886
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   887
        # experimental config: experimental.graphshorten
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
   888
        state['graphshorten'] = ui.configbool('experimental', 'graphshorten')
28891
ac30adb260ea graphmod: shorten graph
santiagopim <santiagopim@gmail.com>
parents: 28861
diff changeset
   889
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   890
    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
   891
        char = formatnode(repo, ctx)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   892
        copies = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   893
        if getrenamed and ctx.rev():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   894
            copies = []
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   895
            for fn in ctx.files():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   896
                rename = getrenamed(fn, ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   897
                if rename:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   898
                    copies.append((fn, rename[0]))
33858
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
   899
        edges = edgefn(type, char, state, rev, parents)
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
   900
        firstedge = next(edges)
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
   901
        width = firstedge[2]
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   902
        displayer.show(ctx, copies=copies,
35350
82ee401135dd py3: handle keyword arguments correctly in cmdutil.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35277
diff changeset
   903
                       _graphwidth=width, **pycompat.strkwargs(props))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   904
        lines = displayer.hunk.pop(rev).split('\n')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   905
        if not lines[-1]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   906
            del lines[-1]
25763
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
   907
        displayer.flush(ctx)
33858
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33856
diff changeset
   908
        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
   909
            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
   910
            lines = []
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   911
    displayer.close()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
   912
35543
a7f7eff4ec08 log: merge getlogrevs() and getgraphlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35483
diff changeset
   913
def graphlog(ui, repo, revs, filematcher, opts):
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   914
    # Parameters are identical to log command ones
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   915
    revdag = graphmod.dagwalker(repo, revs)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   916
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   917
    getrenamed = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   918
    if opts.get('copies'):
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   919
        endrev = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   920
        if opts.get('rev'):
20760
d5fa413346e7 cmdutil: changed max method for lazy call
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20759
diff changeset
   921
            endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
   922
        getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
31078
a113284f54a0 graphlog: restore pager lost at 1cec1d863008
Yuya Nishihara <yuya@tcha.org>
parents: 31023
diff changeset
   923
a113284f54a0 graphlog: restore pager lost at 1cec1d863008
Yuya Nishihara <yuya@tcha.org>
parents: 31023
diff changeset
   924
    ui.pager('log')
36003
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   925
    displayer = changesetdisplayer(ui, repo, opts, makefilematcher=filematcher,
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   926
                                   buffered=True)
fcde8946c553 logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36002
diff changeset
   927
    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
   928
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   929
def checkunsupportedgraphflags(pats, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   930
    for op in ["newest_first"]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   931
        if op in opts and opts[op]:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   932
            raise error.Abort(_("-G/--graph option is incompatible with --%s")
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   933
                             % op.replace("_", "-"))
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   934
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   935
def graphrevs(repo, nodes, opts):
35887
572f36e9a780 logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35886
diff changeset
   936
    limit = getlimit(opts)
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   937
    nodes.reverse()
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   938
    if limit is not None:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   939
        nodes = nodes[:limit]
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
   940
    return graphmod.nodes(repo, nodes)