mercurial/cmdutil.py
author Yuya Nishihara <yuya@tcha.org>
Tue, 30 Sep 2014 23:15:56 +0900
branchstable
changeset 22582 4fe5fa49eac8
parent 22303 0c838e7459a5
child 22588 cd1b43226b34
permissions -rw-r--r--
templater: fix precedence of --style and --template options Since e3eb480a9391, --template option is ignored if --style is specified, which is wrong according to the doc of show_changeset(): Display format will be the first non-empty hit of: 1. option 'template' 2. option 'style' ...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2957
6e062d9b188f fix comment.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2885
diff changeset
     1
# cmdutil.py - help for command processing in mercurial
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
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 6190
diff changeset
     8
from node import hex, nullid, nullrev, short
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
     9
from i18n import _
14269
66257848c154 cmdutil: fix errors reported by pyflakes test
Sune Foldager <cryo@cyanite.org>
parents: 14259
diff changeset
    10
import os, sys, errno, re, tempfile
15214
231aac5280ba rebase: move updatedirstate into cmdutil so it can be shared
Matt Mackall <mpm@selenic.com>
parents: 14986
diff changeset
    11
import util, scmutil, templater, patch, error, templatekw, revlog, copies
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 12032
diff changeset
    12
import match as matchmod
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
    13
import context, repair, graphmod, revset, phases, obsolete, pathutil
17811
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
    14
import changelog
18538
94317c2d53b8 commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents: 18364
diff changeset
    15
import bookmarks
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
    16
import lock as lockmod
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    17
10401
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    18
def parsealiases(cmd):
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    19
    return cmd.lstrip("^").split("|")
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    20
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    21
def findpossible(cmd, table, strict=False):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    22
    """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    23
    Return cmd -> (aliases, command table entry)
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    24
    for each matching command.
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    25
    Return debug commands (or their aliases) only if no normal command matches.
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    26
    """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    27
    choice = {}
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    28
    debugchoice = {}
15600
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    29
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    30
    if cmd in table:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    31
        # short-circuit exact matches, "log" alias beats "^log|history"
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    32
        keys = [cmd]
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    33
    else:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    34
        keys = table.keys()
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    35
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    36
    for e in keys:
10401
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    37
        aliases = parsealiases(e)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    38
        found = None
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    39
        if cmd in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    40
            found = cmd
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    41
        elif not strict:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    42
            for a in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    43
                if a.startswith(cmd):
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    44
                    found = a
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    45
                    break
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    46
        if found is not None:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    47
            if aliases[0].startswith("debug") or found.startswith("debug"):
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5177
diff changeset
    48
                debugchoice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    49
            else:
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5177
diff changeset
    50
                choice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    51
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    52
    if not choice and debugchoice:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    53
        choice = debugchoice
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    54
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    55
    return choice
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    56
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    57
def findcmd(cmd, table, strict=True):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    58
    """Return (aliases, command table entry) for command string."""
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    59
    choice = findpossible(cmd, table, strict)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    60
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5843
diff changeset
    61
    if cmd in choice:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    62
        return choice[cmd]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    63
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    64
    if len(choice) > 1:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    65
        clist = choice.keys()
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    66
        clist.sort()
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7404
diff changeset
    67
        raise error.AmbiguousCommand(cmd, clist)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    68
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    69
    if choice:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    70
        return choice.values()[0]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    71
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7404
diff changeset
    72
    raise error.UnknownCommand(cmd)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    73
10402
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    74
def findrepo(p):
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    75
    while not os.path.isdir(os.path.join(p, ".hg")):
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    76
        oldp, p = p, os.path.dirname(p)
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    77
        if p == oldp:
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    78
            return None
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    79
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    80
    return p
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    81
14289
d68ddccf276b cmdutil: bail_if_changed to bailifchanged
Matt Mackall <mpm@selenic.com>
parents: 14269
diff changeset
    82
def bailifchanged(repo):
13878
a8d13ee0ce68 misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents: 13769
diff changeset
    83
    if repo.dirstate.p2() != nullid:
5716
be367cbafe70 cmdutil: make bail_if_changed bail on uncommitted merge
Matt Mackall <mpm@selenic.com>
parents: 5610
diff changeset
    84
        raise util.Abort(_('outstanding uncommitted merge'))
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    85
    modified, added, removed, deleted = repo.status()[:4]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    86
    if modified or added or removed or deleted:
19804
061ce98c888d cmdutil.bailifchanged: standardize error message for dirty working dir
Siddharth Agarwal <sid0@fb.com>
parents: 19730
diff changeset
    87
        raise util.Abort(_('uncommitted changes'))
15231
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
    88
    ctx = repo[None]
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
    89
    for s in sorted(ctx.substate):
15231
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
    90
        if ctx.sub(s).dirty():
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
    91
            raise util.Abort(_("uncommitted changes in subrepo %s") % s)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    92
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
    93
def logmessage(ui, opts):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    94
    """ get the log message according to -m and -l option """
7667
bd5c37d792e6 cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7643
diff changeset
    95
    message = opts.get('message')
bd5c37d792e6 cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7643
diff changeset
    96
    logfile = opts.get('logfile')
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    97
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    98
    if message and logfile:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    99
        raise util.Abort(_('options --message and --logfile are mutually '
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   100
                           'exclusive'))
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   101
    if not message and logfile:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   102
        try:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   103
            if logfile == '-':
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
   104
                message = ui.fin.read()
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   105
            else:
14249
f4766e1bb0b3 cmdutil: normalize log message eols when reading from file
Patrick Mezard <pmezard@gmail.com>
parents: 14232
diff changeset
   106
                message = '\n'.join(util.readfile(logfile).splitlines())
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   107
        except IOError, inst:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   108
            raise util.Abort(_("can't read commit message '%s': %s") %
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   109
                             (logfile, inst.strerror))
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   110
    return message
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   111
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   112
def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   113
    """get appropriate commit message editor according to '--edit' option
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   114
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   115
    'finishdesc' is a function to be called with edited commit message
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   116
    (= 'description' of the new changeset) just after editing, but
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   117
    before checking empty-ness. It should return actual text to be
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   118
    stored into history. This allows to change description before
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   119
    storing.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   120
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   121
    'extramsg' is a extra message to be shown in the editor instead of
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   122
    'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   123
    is automatically added.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   124
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   125
    'getcommiteditor' returns 'commitforceeditor' regardless of
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   126
    'edit', if one of 'finishdesc' or 'extramsg' is specified, because
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   127
    they are specific for usage in MQ.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   128
    """
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   129
    if edit or finishdesc or extramsg:
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   130
        return lambda r, c, s: commitforceeditor(r, c, s,
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   131
                                                 finishdesc=finishdesc,
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   132
                                                 extramsg=extramsg)
21405
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   133
    else:
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   134
        return commiteditor
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   135
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   136
def loglimit(opts):
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   137
    """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
   138
    limit = opts.get('limit')
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   139
    if limit:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   140
        try:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   141
            limit = int(limit)
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   142
        except ValueError:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   143
            raise util.Abort(_('limit must be a positive integer'))
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   144
        if limit <= 0:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   145
            raise util.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
   146
    else:
10111
27457d31ae3f cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10061
diff changeset
   147
        limit = None
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   148
    return limit
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   149
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   150
def makefilename(repo, pat, node, desc=None,
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   151
                  total=None, seqno=None, revwidth=None, pathname=None):
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   152
    node_expander = {
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   153
        'H': lambda: hex(node),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   154
        'R': lambda: str(repo.changelog.rev(node)),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   155
        'h': lambda: short(node),
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   156
        'm': lambda: re.sub('[^\w]', '_', str(desc))
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   157
        }
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   158
    expander = {
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   159
        '%': lambda: '%',
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   160
        'b': lambda: os.path.basename(repo.root),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   161
        }
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   162
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   163
    try:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   164
        if node:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   165
            expander.update(node_expander)
4836
0e2d0a78f81a archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4825
diff changeset
   166
        if node:
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   167
            expander['r'] = (lambda:
4836
0e2d0a78f81a archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4825
diff changeset
   168
                    str(repo.changelog.rev(node)).zfill(revwidth or 0))
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   169
        if total is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   170
            expander['N'] = lambda: str(total)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   171
        if seqno is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   172
            expander['n'] = lambda: str(seqno)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   173
        if total is not None and seqno is not None:
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3657
diff changeset
   174
            expander['n'] = lambda: str(seqno).zfill(len(str(total)))
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   175
        if pathname is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   176
            expander['s'] = lambda: os.path.basename(pathname)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   177
            expander['d'] = lambda: os.path.dirname(pathname) or '.'
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   178
            expander['p'] = lambda: pathname
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   179
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   180
        newname = []
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   181
        patlen = len(pat)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   182
        i = 0
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   183
        while i < patlen:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   184
            c = pat[i]
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   185
            if c == '%':
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   186
                i += 1
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   187
                c = pat[i]
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   188
                c = expander[c]()
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   189
            newname.append(c)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   190
            i += 1
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   191
        return ''.join(newname)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   192
    except KeyError, inst:
8761
0289f384e1e5 Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents: 8731
diff changeset
   193
        raise util.Abort(_("invalid format spec '%%%s' in output filename") %
3072
bc3fe3b5b785 Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2958
diff changeset
   194
                         inst.args[0])
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   195
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   196
def makefileobj(repo, pat, node=None, desc=None, total=None,
19944
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   197
                seqno=None, revwidth=None, mode='wb', modemap=None,
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   198
                pathname=None):
7319
eae1767cc6a8 export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7308
diff changeset
   199
13769
8796fb6af67e cmdutil: fix mode handling in make_file
Adrian Buehlmann <adrian@cadifra.com>
parents: 13534
diff changeset
   200
    writable = mode not in ('r', 'rb')
7319
eae1767cc6a8 export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7308
diff changeset
   201
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   202
    if not pat or pat == '-':
14637
5e9d691229d5 cmdutil: use ui descriptors in makefileobj
Idan Kamara <idankk86@gmail.com>
parents: 14635
diff changeset
   203
        fp = writable and repo.ui.fout or repo.ui.fin
14948
32302480b402 cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14671
diff changeset
   204
        if util.safehasattr(fp, 'fileno'):
14638
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   205
            return os.fdopen(os.dup(fp.fileno()), mode)
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   206
        else:
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   207
            # if this fp can't be duped properly, return
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   208
            # a dummy object that can be closed
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   209
            class wrappedfileobj(object):
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   210
                noop = lambda x: None
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   211
                def __init__(self, f):
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   212
                    self.f = f
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   213
                def __getattr__(self, attr):
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   214
                    if attr == 'close':
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   215
                        return self.noop
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   216
                    else:
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   217
                        return getattr(self.f, attr)
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   218
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   219
            return wrappedfileobj(fp)
14948
32302480b402 cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14671
diff changeset
   220
    if util.safehasattr(pat, 'write') and writable:
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   221
        return pat
14948
32302480b402 cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14671
diff changeset
   222
    if util.safehasattr(pat, 'read') and 'r' in mode:
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   223
        return pat
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   224
    fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname)
19944
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   225
    if modemap is not None:
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   226
        mode = modemap.get(fn, mode)
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   227
        if mode == 'wb':
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   228
            modemap[fn] = 'ab'
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   229
    return open(fn, mode)
2882
cf98cd70d2c4 move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2874
diff changeset
   230
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   231
def openrevlog(repo, cmd, file_, opts):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   232
    """opens the changelog, manifest, a filelog or a given revlog"""
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   233
    cl = opts['changelog']
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   234
    mf = opts['manifest']
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   235
    msg = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   236
    if cl and mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   237
        msg = _('cannot specify --changelog and --manifest at the same time')
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   238
    elif cl or mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   239
        if file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   240
            msg = _('cannot specify filename with --changelog or --manifest')
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   241
        elif not repo:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   242
            msg = _('cannot specify --changelog or --manifest '
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   243
                    'without a repository')
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   244
    if msg:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   245
        raise util.Abort(msg)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   246
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   247
    r = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   248
    if repo:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   249
        if cl:
21033
254f55b64e31 debugrevlog: use unfiltered view for changelog
Matt Mackall <mpm@selenic.com>
parents: 21024
diff changeset
   250
            r = repo.unfiltered().changelog
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   251
        elif mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   252
            r = repo.manifest
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   253
        elif file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   254
            filelog = repo.file(file_)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   255
            if len(filelog):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   256
                r = filelog
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   257
    if not r:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   258
        if not file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   259
            raise error.CommandError(cmd, _('invalid arguments'))
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   260
        if not os.path.isfile(file_):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   261
            raise util.Abort(_("revlog '%s' not found") % file_)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   262
        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   263
                          file_[:-2] + ".i")
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   264
    return r
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   265
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
   266
def copy(ui, repo, pats, opts, rename=False):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   267
    # called with the repo lock held
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   268
    #
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   269
    # hgsep => pathname that uses "/" to separate directories
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   270
    # ossep => pathname that uses os.sep to separate directories
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   271
    cwd = repo.getcwd()
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   272
    targets = {}
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   273
    after = opts.get("after")
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   274
    dryrun = opts.get("dry_run")
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11290
diff changeset
   275
    wctx = repo[None]
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   276
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   277
    def walkpat(pat):
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   278
        srcs = []
11223
0d09f2244805 rename: make --after work if source is already in R state
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 11177
diff changeset
   279
        badstates = after and '?' or '?r'
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14638
diff changeset
   280
        m = scmutil.match(repo[None], [pat], opts, globbed=True)
6586
d3463007d368 walk: return a single value
Matt Mackall <mpm@selenic.com>
parents: 6585
diff changeset
   281
        for abs in repo.walk(m):
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   282
            state = repo.dirstate[abs]
6584
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
   283
            rel = m.rel(abs)
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
   284
            exact = m.exact(abs)
11223
0d09f2244805 rename: make --after work if source is already in R state
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 11177
diff changeset
   285
            if state in badstates:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   286
                if exact and state == '?':
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   287
                    ui.warn(_('%s: not copying - file is not managed\n') % rel)
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   288
                if exact and state == 'r':
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   289
                    ui.warn(_('%s: not copying - file has been marked for'
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   290
                              ' remove\n') % rel)
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   291
                continue
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   292
            # abs: hgsep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   293
            # rel: ossep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   294
            srcs.append((abs, rel, exact))
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   295
        return srcs
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   296
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   297
    # abssrc: hgsep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   298
    # relsrc: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   299
    # otarget: ossep
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   300
    def copyfile(abssrc, relsrc, otarget, exact):
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents: 19944
diff changeset
   301
        abstarget = pathutil.canonpath(repo.root, cwd, otarget)
16542
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   302
        if '/' in abstarget:
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   303
            # We cannot normalize abstarget itself, this would prevent
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   304
            # case only renames, like a => A.
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   305
            abspath, absname = abstarget.rsplit('/', 1)
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   306
            abstarget = repo.dirstate.normalize(abspath) + '/' + absname
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   307
        reltarget = repo.pathto(abstarget, cwd)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   308
        target = repo.wjoin(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   309
        src = repo.wjoin(abssrc)
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   310
        state = repo.dirstate[abstarget]
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   311
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13945
diff changeset
   312
        scmutil.checkportable(ui, abstarget)
13945
03f3ce7ca2a8 copy: do not copy file if name is disallowed anyway
Adrian Buehlmann <adrian@cadifra.com>
parents: 13878
diff changeset
   313
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   314
        # check for collisions
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   315
        prevsrc = targets.get(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   316
        if prevsrc is not None:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   317
            ui.warn(_('%s: not overwriting - %s collides with %s\n') %
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   318
                    (reltarget, repo.pathto(abssrc, cwd),
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   319
                     repo.pathto(prevsrc, cwd)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   320
            return
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   321
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   322
        # check for overwrites
12342
70236d6fd844 rename: do not overwrite existing broken symlinks
Patrick Mezard <pmezard@gmail.com>
parents: 11950
diff changeset
   323
        exists = os.path.lexists(target)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   324
        samefile = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   325
        if exists and abssrc != abstarget:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   326
            if (repo.dirstate.normalize(abssrc) ==
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   327
                repo.dirstate.normalize(abstarget)):
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   328
                if not rename:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   329
                    ui.warn(_("%s: can't copy - same file\n") % reltarget)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   330
                    return
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   331
                exists = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   332
                samefile = True
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   333
8117
2b30d8488819 remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents: 8013
diff changeset
   334
        if not after and exists or after and state in 'mn':
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   335
            if not opts['force']:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   336
                ui.warn(_('%s: not overwriting - file exists\n') %
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   337
                        reltarget)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   338
                return
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   339
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   340
        if after:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   341
            if not exists:
11152
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   342
                if rename:
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   343
                    ui.warn(_('%s: not recording move - %s does not exist\n') %
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   344
                            (relsrc, reltarget))
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   345
                else:
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   346
                    ui.warn(_('%s: not recording copy - %s does not exist\n') %
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   347
                            (relsrc, reltarget))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   348
                return
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   349
        elif not dryrun:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   350
            try:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   351
                if exists:
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   352
                    os.unlink(target)
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   353
                targetdir = os.path.dirname(target) or '.'
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   354
                if not os.path.isdir(targetdir):
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   355
                    os.makedirs(targetdir)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   356
                if samefile:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   357
                    tmp = target + "~hgrename"
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   358
                    os.rename(src, tmp)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   359
                    os.rename(tmp, target)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   360
                else:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   361
                    util.copyfile(src, target)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   362
                srcexists = True
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   363
            except IOError, inst:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   364
                if inst.errno == errno.ENOENT:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   365
                    ui.warn(_('%s: deleted in working copy\n') % relsrc)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   366
                    srcexists = False
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   367
                else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   368
                    ui.warn(_('%s: cannot copy - %s\n') %
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   369
                            (relsrc, inst.strerror))
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   370
                    return True # report a failure
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   371
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   372
        if ui.verbose or not exact:
7894
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   373
            if rename:
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   374
                ui.status(_('moving %s to %s\n') % (relsrc, reltarget))
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   375
            else:
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   376
                ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   377
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   378
        targets[abstarget] = abssrc
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   379
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   380
        # fix up dirstate
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   381
        scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   382
                             dryrun=dryrun, cwd=cwd)
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
   383
        if rename and not dryrun:
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   384
            if not after and srcexists and not samefile:
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   385
                util.unlinkpath(repo.wjoin(abssrc))
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   386
            wctx.forget([abssrc])
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   387
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   388
    # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   389
    # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   390
    # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   391
    # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   392
    def targetpathfn(pat, dest, srcs):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   393
        if os.path.isdir(pat):
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents: 19944
diff changeset
   394
            abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   395
            abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   396
            if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   397
                striplen = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   398
            else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   399
                striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   400
            if striplen:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   401
                striplen += len(os.sep)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   402
            res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   403
        elif destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   404
            res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   405
                                         os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   406
        else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   407
            res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   408
        return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   409
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   410
    # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   411
    # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   412
    # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   413
    # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   414
    def targetpathafterfn(pat, dest, srcs):
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 12032
diff changeset
   415
        if matchmod.patkind(pat):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   416
            # a mercurial pattern
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   417
            res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   418
                                         os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   419
        else:
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents: 19944
diff changeset
   420
            abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   421
            if len(abspfx) < len(srcs[0][0]):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   422
                # A directory. Either the target path contains the last
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   423
                # component of the source path or it does not.
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   424
                def evalpath(striplen):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   425
                    score = 0
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   426
                    for s in srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   427
                        t = os.path.join(dest, util.localpath(s[0])[striplen:])
12357
cb59654c2c7a Restore lexists() changes lost in e0ee3e822a9a merge
Patrick Mezard <pmezard@gmail.com>
parents: 12345
diff changeset
   428
                        if os.path.lexists(t):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   429
                            score += 1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   430
                    return score
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   431
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   432
                abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   433
                striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   434
                if striplen:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   435
                    striplen += len(os.sep)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   436
                if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   437
                    score = evalpath(striplen)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   438
                    striplen1 = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   439
                    if striplen1:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   440
                        striplen1 += len(os.sep)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   441
                    if evalpath(striplen1) > score:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   442
                        striplen = striplen1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   443
                res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   444
                                             util.localpath(p)[striplen:])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   445
            else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   446
                # a file
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   447
                if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   448
                    res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   449
                                        os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   450
                else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   451
                    res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   452
        return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   453
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   454
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   455
    pats = scmutil.expandpats(pats)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   456
    if not pats:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   457
        raise util.Abort(_('no source or destination specified'))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   458
    if len(pats) == 1:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   459
        raise util.Abort(_('no destination specified'))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   460
    dest = pats.pop()
6258
c24f4b3f156b Fix issue995 (copy --after and symlinks pointing to a directory)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6211
diff changeset
   461
    destdirexists = os.path.isdir(dest) and not os.path.islink(dest)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   462
    if not destdirexists:
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 12032
diff changeset
   463
        if len(pats) > 1 or matchmod.patkind(pats[0]):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   464
            raise util.Abort(_('with multiple sources, destination must be an '
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   465
                               'existing directory'))
5843
83c354c4d529 Add endswithsep() and use it instead of using os.sep and os.altsep directly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 5836
diff changeset
   466
        if util.endswithsep(dest):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   467
            raise util.Abort(_('destination %s is not a directory') % dest)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   468
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   469
    tfn = targetpathfn
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   470
    if after:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   471
        tfn = targetpathafterfn
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   472
    copylist = []
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   473
    for pat in pats:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   474
        srcs = walkpat(pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   475
        if not srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   476
            continue
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   477
        copylist.append((tfn(pat, dest, srcs), srcs))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   478
    if not copylist:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   479
        raise util.Abort(_('no files to copy'))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   480
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   481
    errors = 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   482
    for targetpath, srcs in copylist:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   483
        for abssrc, relsrc, exact in srcs:
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   484
            if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   485
                errors += 1
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   486
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   487
    if errors:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   488
        ui.warn(_('(consider using --after)\n'))
5609
a783d3627144 copy: move rename logic
Matt Mackall <mpm@selenic.com>
parents: 5608
diff changeset
   489
11177
6a64813276ed commands: initial audit of exit codes
Matt Mackall <mpm@selenic.com>
parents: 11152
diff changeset
   490
    return errors != 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   491
9513
ae88c721f916 cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9367
diff changeset
   492
def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
10012
2bfe1a23dafa cmdutil: service: add appendpid parameter to append pids to pid file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9975
diff changeset
   493
    runargs=None, appendpid=False):
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   494
    '''Run a command as a service.'''
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   495
19867
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   496
    def writepid(pid):
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   497
        if opts['pid_file']:
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   498
            mode = appendpid and 'a' or 'w'
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   499
            fp = open(opts['pid_file'], mode)
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   500
            fp.write(str(pid) + '\n')
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   501
            fp.close()
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   502
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   503
    if opts['daemon'] and not opts['daemon_pipefds']:
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   504
        # Signal child process startup with file removal
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   505
        lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   506
        os.close(lockfd)
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   507
        try:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   508
            if not runargs:
10239
8e4be44a676f Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents: 10238
diff changeset
   509
                runargs = util.hgcmd() + sys.argv[1:]
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   510
            runargs.append('--daemon-pipefds=%s' % lockpath)
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   511
            # Don't pass --cwd to the child process, because we've already
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   512
            # changed directory.
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   513
            for i in xrange(1, len(runargs)):
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   514
                if runargs[i].startswith('--cwd='):
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   515
                    del runargs[i]
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   516
                    break
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   517
                elif runargs[i].startswith('--cwd'):
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   518
                    del runargs[i:i + 2]
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   519
                    break
10344
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   520
            def condfn():
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   521
                return not os.path.exists(lockpath)
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   522
            pid = util.rundetached(runargs, condfn)
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   523
            if pid < 0:
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   524
                raise util.Abort(_('child process failed to start'))
19868
0532c8f8e911 cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents: 19867
diff changeset
   525
            writepid(pid)
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   526
        finally:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   527
            try:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   528
                os.unlink(lockpath)
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   529
            except OSError, e:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   530
                if e.errno != errno.ENOENT:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   531
                    raise
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   532
        if parentfn:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   533
            return parentfn(pid)
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   534
        else:
9896
2c2f7593ffc4 cmdutil.service: do not _exit(0) in the parent process
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9668
diff changeset
   535
            return
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   536
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   537
    if initfn:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   538
        initfn()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   539
19868
0532c8f8e911 cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents: 19867
diff changeset
   540
    if not opts['daemon']:
0532c8f8e911 cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents: 19867
diff changeset
   541
        writepid(os.getpid())
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   542
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   543
    if opts['daemon_pipefds']:
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   544
        lockpath = opts['daemon_pipefds']
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   545
        try:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   546
            os.setsid()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   547
        except AttributeError:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   548
            pass
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   549
        os.unlink(lockpath)
10240
3af4b39afe2a cmdutil: hide child window created by win32 spawndetached()
Patrick Mezard <pmezard@gmail.com>
parents: 10239
diff changeset
   550
        util.hidewindow()
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   551
        sys.stdout.flush()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   552
        sys.stderr.flush()
8789
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   553
17391
fc24c10424d2 util: replace util.nulldev with os.devnull
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17308
diff changeset
   554
        nullfd = os.open(os.devnull, os.O_RDWR)
8789
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   555
        logfilefd = nullfd
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   556
        if logfile:
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   557
            logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND)
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   558
        os.dup2(nullfd, 0)
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   559
        os.dup2(logfilefd, 1)
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   560
        os.dup2(logfilefd, 2)
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   561
        if nullfd not in (0, 1, 2):
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   562
            os.close(nullfd)
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   563
        if logfile and logfilefd not in (0, 1, 2):
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   564
            os.close(logfilefd)
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   565
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   566
    if runfn:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   567
        return runfn()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   568
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   569
def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   570
    """Utility function used by commands.import to import a single patch
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   571
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   572
    This function is explicitly defined here to help the evolve extension to
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   573
    wrap this part of the import logic.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   574
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   575
    The API is currently a bit ugly because it a simple code translation from
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   576
    the import command. Feel free to make it better.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   577
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   578
    :hunk: a patch (as a binary string)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   579
    :parents: nodes that will be parent of the created commit
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   580
    :opts: the full dict of option passed to the import command
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   581
    :msgs: list to save commit message to.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   582
           (used in case we need to save it when failing)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   583
    :updatefunc: a function that update a repo to a given node
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   584
                 updatefunc(<repo>, <node>)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   585
    """
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   586
    tmpname, message, user, date, branch, nodeid, p1, p2 = \
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   587
        patch.extract(ui, hunk)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   588
21417
308aaeb956e2 import: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21415
diff changeset
   589
    editor = getcommiteditor(**opts)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   590
    update = not opts.get('bypass')
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   591
    strip = opts["strip"]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   592
    sim = float(opts.get('similarity') or 0)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   593
    if not tmpname:
21553
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   594
        return (None, None, False)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   595
    msg = _('applied to working directory')
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   596
21553
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   597
    rejects = False
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   598
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   599
    try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   600
        cmdline_message = logmessage(ui, opts)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   601
        if cmdline_message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   602
            # pickup the cmdline msg
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   603
            message = cmdline_message
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   604
        elif message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   605
            # pickup the patch msg
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   606
            message = message.strip()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   607
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   608
            # launch the editor
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   609
            message = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   610
        ui.debug('message:\n%s\n' % message)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   611
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   612
        if len(parents) == 1:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   613
            parents.append(repo[nullid])
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   614
        if opts.get('exact'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   615
            if not nodeid or not p1:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   616
                raise util.Abort(_('not a Mercurial patch'))
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   617
            p1 = repo[p1]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   618
            p2 = repo[p2 or nullid]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   619
        elif p2:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   620
            try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   621
                p1 = repo[p1]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   622
                p2 = repo[p2]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   623
                # Without any options, consider p2 only if the
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   624
                # patch is being applied on top of the recorded
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   625
                # first parent.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   626
                if p1 != parents[0]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   627
                    p1 = parents[0]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   628
                    p2 = repo[nullid]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   629
            except error.RepoError:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   630
                p1, p2 = parents
22303
0c838e7459a5 import: show the warning message for failure of merging
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22301
diff changeset
   631
            if p2.node() == nullid:
0c838e7459a5 import: show the warning message for failure of merging
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22301
diff changeset
   632
                ui.warn(_("warning: import the patch as a normal revision\n"
0c838e7459a5 import: show the warning message for failure of merging
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22301
diff changeset
   633
                          "(use --exact to import the patch as a merge)\n"))
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   634
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   635
            p1, p2 = parents
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   636
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   637
        n = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   638
        if update:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   639
            if p1 != parents[0]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   640
                updatefunc(repo, p1.node())
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   641
            if p2 != parents[1]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   642
                repo.setparents(p1.node(), p2.node())
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   643
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   644
            if opts.get('exact') or opts.get('import_branch'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   645
                repo.dirstate.setbranch(branch or 'default')
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   646
21553
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   647
            partial = opts.get('partial', False)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   648
            files = set()
21553
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   649
            try:
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   650
                patch.patch(ui, repo, tmpname, strip=strip, files=files,
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   651
                            eolmode=None, similarity=sim / 100.0)
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   652
            except patch.PatchError, e:
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   653
                if not partial:
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   654
                    raise util.Abort(str(e))
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   655
                if partial:
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   656
                    rejects = True
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   657
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   658
            files = list(files)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   659
            if opts.get('no_commit'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   660
                if message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   661
                    msgs.append(message)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   662
            else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   663
                if opts.get('exact') or p2:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   664
                    # If you got here, you either use --force and know what
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   665
                    # you are doing or used --exact or a merge patch while
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   666
                    # being updated to its first parent.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   667
                    m = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   668
                else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   669
                    m = scmutil.matchfiles(repo, files or [])
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   670
                n = repo.commit(message, opts.get('user') or user,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   671
                                opts.get('date') or date, match=m,
21553
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   672
                                editor=editor, force=partial)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   673
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   674
            if opts.get('exact') or opts.get('import_branch'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   675
                branch = branch or 'default'
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   676
            else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   677
                branch = p1.branch()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   678
            store = patch.filestore()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   679
            try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   680
                files = set()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   681
                try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   682
                    patch.patchrepo(ui, repo, p1, store, tmpname, strip,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   683
                                    files, eolmode=None)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   684
                except patch.PatchError, e:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   685
                    raise util.Abort(str(e))
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   686
                memctx = context.makememctx(repo, (p1.node(), p2.node()),
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   687
                                            message,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   688
                                            opts.get('user') or user,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   689
                                            opts.get('date') or date,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   690
                                            branch, files, store,
21417
308aaeb956e2 import: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21415
diff changeset
   691
                                            editor=getcommiteditor())
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   692
                n = memctx.commit()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   693
            finally:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   694
                store.close()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   695
        if opts.get('exact') and hex(n) != nodeid:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   696
            raise util.Abort(_('patch is damaged or loses information'))
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   697
        if n:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   698
            # i18n: refers to a short changeset id
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   699
            msg = _('created %s') % short(n)
21553
bee0e1cffdd3 import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21419
diff changeset
   700
        return (msg, n, rejects)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   701
    finally:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   702
        os.unlink(tmpname)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   703
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   704
def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   705
           opts=None):
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   706
    '''export changesets as hg patches.'''
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   707
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   708
    total = len(revs)
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   709
    revwidth = max([len(str(rev)) for rev in revs])
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   710
    filemode = {}
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   711
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   712
    def single(rev, seqno, fp):
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   713
        ctx = repo[rev]
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   714
        node = ctx.node()
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   715
        parents = [p.node() for p in ctx.parents() if p]
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   716
        branch = ctx.branch()
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   717
        if switch_parent:
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   718
            parents.reverse()
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   719
        prev = (parents and parents[0]) or nullid
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   720
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13386
diff changeset
   721
        shouldclose = False
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   722
        if not fp and len(template) > 0:
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   723
            desc_lines = ctx.description().rstrip().split('\n')
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   724
            desc = desc_lines[0]    #Commit always has a first line.
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   725
            fp = makefileobj(repo, template, node, desc=desc, total=total,
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   726
                             seqno=seqno, revwidth=revwidth, mode='wb',
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   727
                             modemap=filemode)
13467
31aa2e5b0750 export: only close files which export itself has opened
Waqas Hussain <waqas20@gmail.com>
parents: 13400
diff changeset
   728
            if fp != template:
31aa2e5b0750 export: only close files which export itself has opened
Waqas Hussain <waqas20@gmail.com>
parents: 13400
diff changeset
   729
                shouldclose = True
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   730
        if fp and fp != sys.stdout and util.safehasattr(fp, 'name'):
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   731
            repo.ui.note("%s\n" % fp.name)
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   732
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   733
        if not fp:
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   734
            write = repo.ui.write
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   735
        else:
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   736
            def write(s, **kw):
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   737
                fp.write(s)
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   738
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   739
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   740
        write("# HG changeset patch\n")
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   741
        write("# User %s\n" % ctx.user())
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   742
        write("# Date %d %d\n" % ctx.date())
18648
76b69cccb07a export: show 'Date' header in a format that also is readable for humans
Mads Kiilerich <mads@kiilerich.com>
parents: 18613
diff changeset
   743
        write("#      %s\n" % util.datestr(ctx.date()))
11821
15aa42aaae4c cmdutil: remove unnecessary parenthesis
Martin Geisler <mg@aragost.com>
parents: 11635
diff changeset
   744
        if branch and branch != 'default':
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   745
            write("# Branch %s\n" % branch)
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   746
        write("# Node ID %s\n" % hex(node))
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   747
        write("# Parent  %s\n" % hex(prev))
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   748
        if len(parents) > 1:
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   749
            write("# Parent  %s\n" % hex(parents[1]))
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   750
        write(ctx.description().rstrip())
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   751
        write("\n\n")
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   752
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   753
        for chunk, label in patch.diffui(repo, prev, node, opts=opts):
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   754
            write(chunk, label=label)
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   755
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13386
diff changeset
   756
        if shouldclose:
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13386
diff changeset
   757
            fp.close()
13081
79184986658c export: flush the file pointer between patches
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13047
diff changeset
   758
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   759
    for seqno, rev in enumerate(revs):
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   760
        single(rev, seqno + 1, fp)
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   761
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   762
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
   763
                   changes=None, stat=False, fp=None, prefix='',
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   764
                   listsubrepos=False):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   765
    '''show diff or diffstat.'''
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   766
    if fp is None:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   767
        write = ui.write
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   768
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   769
        def write(s, **kw):
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   770
            fp.write(s)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   771
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   772
    if stat:
11950
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   773
        diffopts = diffopts.copy(context=0)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   774
        width = 80
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   775
        if not ui.plain():
12689
c52c629ce19e termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents: 12619
diff changeset
   776
            width = ui.termwidth()
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   777
        chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   778
                            prefix=prefix)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   779
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   780
                                             width=width,
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   781
                                             git=diffopts.git):
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   782
            write(chunk, label=label)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   783
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   784
        for chunk, label in patch.diffui(repo, node1, node2, match,
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   785
                                         changes, diffopts, prefix=prefix):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   786
            write(chunk, label=label)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   787
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   788
    if listsubrepos:
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   789
        ctx1 = repo[node1]
12175
c0a8f9dea0f6 subrepos: handle modified but uncommitted .hgsub
Martin Geisler <mg@lazybytes.net>
parents: 12167
diff changeset
   790
        ctx2 = repo[node2]
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
   791
        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
   792
            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
   793
            try:
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   794
                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
   795
                    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
   796
            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
   797
                # 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
   798
                # 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
   799
                # 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
   800
                tempnode2 = None
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   801
            submatch = matchmod.narrowmatcher(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
   802
            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
   803
                     stat=stat, fp=fp, prefix=prefix)
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   804
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   805
class changeset_printer(object):
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   806
    '''show changeset information when templating not requested.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   807
7762
fece056bf240 add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents: 7667
diff changeset
   808
    def __init__(self, ui, repo, patch, diffopts, buffered):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   809
        self.ui = ui
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   810
        self.repo = repo
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   811
        self.buffered = buffered
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   812
        self.patch = patch
7762
fece056bf240 add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents: 7667
diff changeset
   813
        self.diffopts = diffopts
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   814
        self.header = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   815
        self.hunk = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   816
        self.lastheader = None
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   817
        self.footer = None
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   818
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   819
    def flush(self, rev):
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   820
        if rev in self.header:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   821
            h = self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   822
            if h != self.lastheader:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   823
                self.lastheader = h
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   824
                self.ui.write(h)
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   825
            del self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   826
        if rev in self.hunk:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   827
            self.ui.write(self.hunk[rev])
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   828
            del self.hunk[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   829
            return 1
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   830
        return 0
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   831
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   832
    def close(self):
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   833
        if self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   834
            self.ui.write(self.footer)
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   835
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   836
    def show(self, ctx, copies=None, matchfn=None, **props):
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   837
        if self.buffered:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   838
            self.ui.pushbuffer()
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   839
            self._show(ctx, copies, matchfn, props)
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   840
            self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True)
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   841
        else:
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   842
            self._show(ctx, copies, matchfn, props)
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   843
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   844
    def _show(self, ctx, copies, matchfn, props):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   845
        '''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
   846
        changenode = ctx.node()
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   847
        rev = ctx.rev()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   848
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   849
        if self.ui.quiet:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   850
            self.ui.write("%d:%s\n" % (rev, short(changenode)),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   851
                          label='log.node')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   852
            return
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   853
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   854
        log = self.repo.changelog
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   855
        date = util.datestr(ctx.date())
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   856
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   857
        hexfunc = self.ui.debugflag and hex or short
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   858
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
   859
        parents = [(p, hexfunc(log.node(p)))
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
   860
                   for p in self._meaningful_parentrevs(log, rev)]
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   861
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   862
        # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   863
        self.ui.write(_("changeset:   %d:%s\n") % (rev, hexfunc(changenode)),
17788
9912baaae7df color: add additional changeset.phase label to log.changeset and log.parent
Sean Farley <sean.michael.farley@gmail.com>
parents: 17746
diff changeset
   864
                      label='log.changeset changeset.%s' % ctx.phasestr())
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   865
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   866
        branch = ctx.branch()
4176
f9bbcebcacea "default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4055
diff changeset
   867
        # 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
   868
        if branch != 'default':
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   869
            # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   870
            self.ui.write(_("branch:      %s\n") % branch,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   871
                          label='log.branch')
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13121
diff changeset
   872
        for bookmark in self.repo.nodebookmarks(changenode):
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   873
            # i18n: column positioning for "hg log"
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13121
diff changeset
   874
            self.ui.write(_("bookmark:    %s\n") % bookmark,
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13121
diff changeset
   875
                    label='log.bookmark')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   876
        for tag in self.repo.nodetags(changenode):
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   877
            # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   878
            self.ui.write(_("tag:         %s\n") % tag,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   879
                          label='log.tag')
15907
51fc43253a52 changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15777
diff changeset
   880
        if self.ui.debugflag and ctx.phase():
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   881
            # i18n: column positioning for "hg log"
15907
51fc43253a52 changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15777
diff changeset
   882
            self.ui.write(_("phase:       %s\n") % _(ctx.phasestr()),
51fc43253a52 changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15777
diff changeset
   883
                          label='log.phase')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   884
        for parent in parents:
22301
f6371cc62d2a log: use correct phase info for parent field (issue4347)
Sean Farley <sean.michael.farley@gmail.com>
parents: 22167
diff changeset
   885
            label = 'log.parent changeset.%s' % self.repo[parent[0]].phasestr()
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   886
            # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   887
            self.ui.write(_("parent:      %d:%s\n") % parent,
22301
f6371cc62d2a log: use correct phase info for parent field (issue4347)
Sean Farley <sean.michael.farley@gmail.com>
parents: 22167
diff changeset
   888
                          label=label)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   889
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   890
        if self.ui.debugflag:
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   891
            mnode = ctx.manifestnode()
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   892
            # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   893
            self.ui.write(_("manifest:    %d:%s\n") %
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   894
                          (self.repo.manifest.rev(mnode), hex(mnode)),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   895
                          label='ui.debug log.manifest')
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   896
        # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   897
        self.ui.write(_("user:        %s\n") % ctx.user(),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   898
                      label='log.user')
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   899
        # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   900
        self.ui.write(_("date:        %s\n") % date,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   901
                      label='log.date')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   902
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   903
        if self.ui.debugflag:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   904
            files = self.repo.status(log.parents(changenode)[0], changenode)[:3]
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   905
            for key, value in zip([# i18n: column positioning for "hg log"
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   906
                                   _("files:"),
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   907
                                   # i18n: column positioning for "hg log"
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   908
                                   _("files+:"),
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   909
                                   # i18n: column positioning for "hg log"
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   910
                                   _("files-:")], files):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   911
                if value:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   912
                    self.ui.write("%-12s %s\n" % (key, " ".join(value)),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   913
                                  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
   914
        elif ctx.files() and self.ui.verbose:
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   915
            # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   916
            self.ui.write(_("files:       %s\n") % " ".join(ctx.files()),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   917
                          label='ui.note log.files')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   918
        if copies and self.ui.verbose:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   919
            copies = ['%s (%s)' % c for c in copies]
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   920
            # i18n: column positioning for "hg log"
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   921
            self.ui.write(_("copies:      %s\n") % ' '.join(copies),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   922
                          label='ui.note log.copies')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   923
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   924
        extra = ctx.extra()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   925
        if extra and self.ui.debugflag:
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
   926
            for key, value in sorted(extra.items()):
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   927
                # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   928
                self.ui.write(_("extra:       %s=%s\n")
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   929
                              % (key, value.encode('string_escape')),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   930
                              label='ui.debug log.extra')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   931
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   932
        description = ctx.description().strip()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   933
        if description:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   934
            if self.ui.verbose:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   935
                self.ui.write(_("description:\n"),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   936
                              label='ui.note log.description')
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   937
                self.ui.write(description,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   938
                              label='ui.note log.description')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   939
                self.ui.write("\n\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   940
            else:
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   941
                # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   942
                self.ui.write(_("summary:     %s\n") %
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   943
                              description.splitlines()[0],
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   944
                              label='log.summary')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   945
        self.ui.write("\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   946
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   947
        self.showpatch(changenode, matchfn)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   948
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   949
    def showpatch(self, node, matchfn):
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   950
        if not matchfn:
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   951
            matchfn = self.patch
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   952
        if matchfn:
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
   953
            stat = self.diffopts.get('stat')
11950
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   954
            diff = self.diffopts.get('patch')
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
   955
            diffopts = patch.diffopts(self.ui, self.diffopts)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   956
            prev = self.repo.changelog.parents(node)[0]
11950
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   957
            if stat:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   958
                diffordiffstat(self.ui, self.repo, diffopts, prev, node,
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   959
                               match=matchfn, stat=True)
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   960
            if diff:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   961
                if stat:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   962
                    self.ui.write("\n")
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   963
                diffordiffstat(self.ui, self.repo, diffopts, prev, node,
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   964
                               match=matchfn, stat=False)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   965
            self.ui.write("\n")
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   966
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
   967
    def _meaningful_parentrevs(self, log, rev):
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
   968
        """Return list of meaningful (or all if debug) parentrevs for rev.
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
   969
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
   970
        For merges (two non-nullrev revisions) both parents are meaningful.
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
   971
        Otherwise the first parent revision is considered meaningful if it
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
   972
        is not the preceding revision.
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
   973
        """
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
   974
        parents = log.parentrevs(rev)
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
   975
        if not self.ui.debugflag and parents[1] == nullrev:
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
   976
            if parents[0] >= rev - 1:
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
   977
                parents = []
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
   978
            else:
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
   979
                parents = [parents[0]]
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
   980
        return parents
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
   981
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
   982
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   983
class changeset_templater(changeset_printer):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   984
    '''format changeset information.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   985
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
   986
    def __init__(self, ui, repo, patch, diffopts, tmpl, mapfile, buffered):
7762
fece056bf240 add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents: 7667
diff changeset
   987
        changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered)
8360
acc202b71619 templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8312
diff changeset
   988
        formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
10061
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   989
        defaulttempl = {
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   990
            'parent': '{rev}:{node|formatnode} ',
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   991
            'manifest': '{rev}:{node|formatnode}',
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   992
            'file_copy': '{name} ({source})',
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   993
            'extra': '{key}={value|stringescape}'
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   994
            }
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   995
        # filecopy is preserved for compatibility reasons
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   996
        defaulttempl['filecopy'] = defaulttempl['file_copy']
8360
acc202b71619 templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8312
diff changeset
   997
        self.t = templater.templater(mapfile, {'formatnode': formatnode},
10061
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   998
                                     cache=defaulttempl)
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
   999
        if tmpl:
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1000
            self.t.cache['changeset'] = tmpl
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1001
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1002
        self.cache = {}
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1003
7878
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1004
    def _meaningful_parentrevs(self, ctx):
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1005
        """Return list of meaningful (or all if debug) parentrevs for rev.
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1006
        """
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1007
        parents = ctx.parents()
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1008
        if len(parents) > 1:
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1009
            return parents
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1010
        if self.ui.debugflag:
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1011
            return [parents[0], self.repo['null']]
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1012
        if parents[0].rev() >= ctx.rev() - 1:
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1013
            return []
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1014
        return parents
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1015
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1016
    def _show(self, ctx, copies, matchfn, props):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1017
        '''show a single changeset or file revision'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1018
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents: 10026
diff changeset
  1019
        showlist = templatekw.showlist
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1020
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1021
        # showparents() behaviour depends on ui trace level which
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1022
        # causes unexpected behaviours at templating level and makes
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1023
        # it harder to extract it in a standalone function. Its
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1024
        # behaviour cannot be changed so leave it here for now.
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1025
        def showparents(**args):
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10250
diff changeset
  1026
            ctx = args['ctx']
7878
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1027
            parents = [[('rev', p.rev()), ('node', p.hex())]
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1028
                       for p in self._meaningful_parentrevs(ctx)]
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1029
            return showlist('parent', parents, **args)
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1030
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1031
        props = props.copy()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
  1032
        props.update(templatekw.keywords)
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1033
        props['parents'] = showparents
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents: 10026
diff changeset
  1034
        props['templ'] = self.t
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
  1035
        props['ctx'] = ctx
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
  1036
        props['repo'] = self.repo
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1037
        props['revcache'] = {'copies': copies}
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
  1038
        props['cache'] = self.cache
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1039
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1040
        # find correct templates for current mode
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1041
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1042
        tmplmodes = [
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1043
            (True, None),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1044
            (self.ui.verbose, 'verbose'),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1045
            (self.ui.quiet, 'quiet'),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1046
            (self.ui.debugflag, 'debug'),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1047
        ]
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1048
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1049
        types = {'header': '', 'footer':'', 'changeset': 'changeset'}
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1050
        for mode, postfix  in tmplmodes:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1051
            for type in types:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1052
                cur = postfix and ('%s_%s' % (type, postfix)) or type
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1053
                if mode and cur in self.t:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1054
                    types[type] = cur
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1055
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1056
        try:
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1057
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1058
            # write header
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1059
            if types['header']:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1060
                h = templater.stringify(self.t(types['header'], **props))
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1061
                if self.buffered:
7878
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1062
                    self.header[ctx.rev()] = h
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1063
                else:
11465
ace5bd98bee3 heads: fix templating of headers again (issue2130)
Simon Howkins <simonh@symbian.org>
parents: 11441
diff changeset
  1064
                    if self.lastheader != h:
ace5bd98bee3 heads: fix templating of headers again (issue2130)
Simon Howkins <simonh@symbian.org>
parents: 11441
diff changeset
  1065
                        self.lastheader = h
11441
d74fe370ab04 cmdutil: only output style header once in non-buffered mode (issue2130)
Simon Howkins <simonh@symbian.org>
parents: 11410
diff changeset
  1066
                        self.ui.write(h)
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1067
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1068
            # write changeset metadata, then patch if requested
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1069
            key = types['changeset']
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1070
            self.ui.write(templater.stringify(self.t(key, **props)))
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1071
            self.showpatch(ctx.node(), matchfn)
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1072
10160
48653dea23dd Bugfix and test for hg log XML output
Robert Bachmann <rbachm@gmail.com>
parents: 10152
diff changeset
  1073
            if types['footer']:
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1074
                if not self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1075
                    self.footer = templater.stringify(self.t(types['footer'],
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1076
                                                      **props))
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1077
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1078
        except KeyError, inst:
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1079
            msg = _("%s: no key named '%s'")
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1080
            raise util.Abort(msg % (self.t.mapfile, inst.args[0]))
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1081
        except SyntaxError, inst:
10829
56fffc9c8928 cmdutil: do not translate trivial string
Martin Geisler <mg@lazybytes.net>
parents: 10819
diff changeset
  1082
            raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1083
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1084
def gettemplate(ui, tmpl, style):
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1085
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1086
    Find the template matching the given template spec or style.
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1087
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1088
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1089
    # ui settings
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
  1090
    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
  1091
        tmpl = ui.config('ui', 'logtemplate')
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1092
        if tmpl:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1093
            try:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1094
                tmpl = templater.parsestring(tmpl)
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1095
            except SyntaxError:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1096
                tmpl = templater.parsestring(tmpl, quoted=False)
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1097
            return tmpl, None
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1098
        else:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1099
            style = util.expandpath(ui.config('ui', 'style', ''))
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1100
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
  1101
    if not tmpl and style:
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1102
        mapfile = style
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1103
        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
  1104
            mapname = (templater.templatepath('map-cmdline.' + mapfile)
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1105
                       or templater.templatepath(mapfile))
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1106
            if mapname:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1107
                mapfile = mapname
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1108
        return None, mapfile
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1109
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1110
    if not tmpl:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1111
        return None, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1112
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1113
    # looks like a literal template?
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1114
    if '{' in tmpl:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1115
        return tmpl, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1116
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1117
    # perhaps a stock style?
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1118
    if not os.path.split(tmpl)[0]:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1119
        mapname = (templater.templatepath('map-cmdline.' + tmpl)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1120
                   or templater.templatepath(tmpl))
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1121
        if mapname and os.path.isfile(mapname):
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1122
            return None, mapname
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1123
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1124
    # perhaps it's a reference to [templates]
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1125
    t = ui.config('templates', tmpl)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1126
    if t:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1127
        try:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1128
            tmpl = templater.parsestring(t)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1129
        except SyntaxError:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1130
            tmpl = templater.parsestring(t, quoted=False)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1131
        return tmpl, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1132
21944
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1133
    if tmpl == 'list':
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1134
        ui.write(_("available styles: %s\n") % templater.stylelist())
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1135
        raise util.Abort(_("specify a template"))
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1136
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1137
    # perhaps it's a path to a map or a template
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1138
    if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1139
        # is it a mapfile for a style?
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1140
        if os.path.basename(tmpl).startswith("map-"):
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1141
            return None, os.path.realpath(tmpl)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1142
        tmpl = open(tmpl).read()
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1143
        return tmpl, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1144
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1145
    # constant string?
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1146
    return tmpl, None
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1147
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1148
def show_changeset(ui, repo, opts, buffered=False):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1149
    """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
  1150
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1151
    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
  1152
    1. option 'template'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1153
    2. option 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1154
    3. [ui] setting 'logtemplate'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1155
    4. [ui] setting 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1156
    If all of these values are either the unset or the empty string,
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1157
    regular display via changeset_printer() is done.
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1158
    """
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1159
    # options
19894
df91e2df6ba3 cmdutil: use None as default value for "function pointer" instead of False
Mads Kiilerich <madski@unity3d.com>
parents: 19868
diff changeset
  1160
    patch = None
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
  1161
    if opts.get('patch') or opts.get('stat'):
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14321
diff changeset
  1162
        patch = 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
  1163
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1164
    tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style'))
7967
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1165
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1166
    if not tmpl and not mapfile:
7967
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1167
        return changeset_printer(ui, repo, patch, opts, buffered)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1168
7967
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1169
    try:
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1170
        t = changeset_templater(ui, repo, patch, opts, tmpl, mapfile, buffered)
7967
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1171
    except SyntaxError, inst:
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1172
        raise util.Abort(inst.args[0])
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1173
    return t
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1174
20470
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1175
def showmarker(ui, marker):
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1176
    """utility function to display obsolescence marker in a readable way
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1177
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1178
    To be used by debug function."""
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1179
    ui.write(hex(marker.precnode()))
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1180
    for repl in marker.succnodes():
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1181
        ui.write(' ')
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1182
        ui.write(hex(repl))
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1183
    ui.write(' %X ' % marker._data[2])
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1184
    ui.write('{%s}' % (', '.join('%r: %r' % t for t in
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1185
                                 sorted(marker.metadata().items()))))
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1186
    ui.write('\n')
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1187
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1188
def finddate(ui, repo, date):
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1189
    """Find the tipmost changeset that matches the given date spec"""
9667
8743f2e1bc54 merge changes from mpm
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9666 9665
diff changeset
  1190
5836
c5c9a022bd9a Tweak finddate to pass date directly.
mark.williamson@cl.cam.ac.uk
parents: 5829
diff changeset
  1191
    df = util.matchdate(date)
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14321
diff changeset
  1192
    m = scmutil.matchall(repo)
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1193
    results = {}
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1194
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1195
    def prep(ctx, fns):
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1196
        d = ctx.date()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1197
        if df(d[0]):
9668
2c24471d478c cmdutil: fix bug in finddate() implementation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9667
diff changeset
  1198
            results[ctx.rev()] = d
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1199
9667
8743f2e1bc54 merge changes from mpm
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9666 9665
diff changeset
  1200
    for ctx in walkchangerevs(repo, m, {'rev': None}, prep):
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1201
        rev = ctx.rev()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1202
        if rev in results:
16937
5487088f0d43 cmdutil: lowercase finddate status message
Martin Geisler <mg@aragost.com>
parents: 16776
diff changeset
  1203
            ui.status(_("found revision %s from %s\n") %
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1204
                      (rev, util.datestr(results[rev])))
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1205
            return str(rev)
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1206
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1207
    raise util.Abort(_("revision matching date not found"))
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1208
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1209
def increasingwindows(windowsize=8, sizelimit=512):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1210
    while True:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1211
        yield windowsize
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1212
        if windowsize < sizelimit:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1213
            windowsize *= 2
16776
5088d0b9a9a1 cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents: 16701
diff changeset
  1214
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1215
class FileWalkError(Exception):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1216
    pass
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1217
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1218
def walkfilerevs(repo, match, follow, revs, fncache):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1219
    '''Walks the file history for the matched files.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1220
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1221
    Returns the changeset revs that are involved in the file history.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1222
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1223
    Throws FileWalkError if the file history can't be walked using
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1224
    filelogs alone.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1225
    '''
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1226
    wanted = set()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1227
    copies = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1228
    minrev, maxrev = min(revs), max(revs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1229
    def filerevgen(filelog, last):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1230
        """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1231
        Only files, no patterns.  Check the history of each file.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1232
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1233
        Examines filelog entries within minrev, maxrev linkrev range
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1234
        Returns an iterator yielding (linkrev, parentlinkrevs, copied)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1235
        tuples in backwards order
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1236
        """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1237
        cl_count = len(repo)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1238
        revs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1239
        for j in xrange(0, last + 1):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1240
            linkrev = filelog.linkrev(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1241
            if linkrev < minrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1242
                continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1243
            # only yield rev for which we have the changelog, it can
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1244
            # happen while doing "hg log" during a pull or commit
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1245
            if linkrev >= cl_count:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1246
                break
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1247
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1248
            parentlinkrevs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1249
            for p in filelog.parentrevs(j):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1250
                if p != nullrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1251
                    parentlinkrevs.append(filelog.linkrev(p))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1252
            n = filelog.node(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1253
            revs.append((linkrev, parentlinkrevs,
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1254
                         follow and filelog.renamed(n)))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1255
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1256
        return reversed(revs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1257
    def iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1258
        pctx = repo['.']
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1259
        for filename in match.files():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1260
            if follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1261
                if filename not in pctx:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1262
                    raise util.Abort(_('cannot follow file not in parent '
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1263
                                       'revision: "%s"') % filename)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1264
                yield filename, pctx[filename].filenode()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1265
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1266
                yield filename, None
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1267
        for filename_node in copies:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1268
            yield filename_node
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1269
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1270
    for file_, node in iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1271
        filelog = repo.file(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1272
        if not len(filelog):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1273
            if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1274
                # A zero count may be a directory or deleted file, so
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1275
                # try to find matching entries on the slow path.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1276
                if follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1277
                    raise util.Abort(
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1278
                        _('cannot follow nonexistent file: "%s"') % file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1279
                raise FileWalkError("Cannot walk via filelog")
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1280
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1281
                continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1282
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1283
        if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1284
            last = len(filelog) - 1
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1285
        else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1286
            last = filelog.rev(node)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1287
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1288
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1289
        # keep track of all ancestors of the file
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1290
        ancestors = set([filelog.linkrev(last)])
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1291
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1292
        # iterate from latest to oldest revision
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1293
        for rev, flparentlinkrevs, copied in filerevgen(filelog, last):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1294
            if not follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1295
                if rev > maxrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1296
                    continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1297
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1298
                # Note that last might not be the first interesting
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1299
                # rev to us:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1300
                # if the file has been changed after maxrev, we'll
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1301
                # have linkrev(last) > maxrev, and we still need
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1302
                # to explore the file graph
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1303
                if rev not in ancestors:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1304
                    continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1305
                # XXX insert 1327 fix here
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1306
                if flparentlinkrevs:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1307
                    ancestors.update(flparentlinkrevs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1308
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1309
            fncache.setdefault(rev, []).append(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1310
            wanted.add(rev)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1311
            if copied:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1312
                copies.append(copied)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1313
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1314
    return wanted
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1315
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9664
diff changeset
  1316
def walkchangerevs(repo, match, opts, prepare):
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
  1317
    '''Iterate over files and the revs in which they changed.
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1318
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1319
    Callers most commonly need to iterate backwards over the history
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
  1320
    in which they are interested. Doing so has awful (quadratic-looking)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1321
    performance, so we use iterators in a "windowed" way.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1322
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1323
    We walk a window of revisions in the desired order.  Within the
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1324
    window, we first walk forwards to gather data, then in the desired
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1325
    order (usually backwards) to display it.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1326
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1327
    This function returns an iterator yielding contexts. Before
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1328
    yielding each context, the iterator will first call the prepare
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1329
    function on each context in the window in forward order.'''
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1330
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1331
    follow = opts.get('follow') or opts.get('follow_first')
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1332
17676
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1333
    if opts.get('rev'):
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1334
        revs = scmutil.revrange(repo, opts.get('rev'))
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1335
    elif follow:
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1336
        revs = repo.revs('reverse(:.)')
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1337
    else:
20704
623ed0ed793e cmdutil: changed walkchangerevs to use spanset instead of baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20668
diff changeset
  1338
        revs = revset.spanset(repo)
17676
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1339
        revs.reverse()
11281
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
  1340
    if not revs:
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
  1341
        return []
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8119
diff changeset
  1342
    wanted = set()
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1343
    slowpath = match.anypats() or (match.files() and opts.get('removed'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1344
    fncache = {}
16108
f7e0d95d0a0b log: remove caching of all visited revisions (issue3253)
Matt Mackall <mpm@selenic.com>
parents: 16070
diff changeset
  1345
    change = repo.changectx
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1346
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1347
    # First step is to fill wanted, the set of revisions that we want to yield.
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1348
    # When it does not induce extra cost, we also fill fncache for revisions in
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1349
    # wanted: a cache of filenames that were changed (ctx.files()) and that
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1350
    # match the file filtering conditions.
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1351
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1352
    if not slowpath and not match.files():
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1353
        # No files, no patterns.  Display all revs.
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1354
        wanted = revs
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9664
diff changeset
  1355
16381
64c8ae09162e log: bypass file scan part of fastpath when no files
Matt Mackall <mpm@selenic.com>
parents: 16380
diff changeset
  1356
    if not slowpath and match.files():
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1357
        # We only have to read through the filelog to find wanted revisions
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1358
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1359
        try:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1360
            wanted = walkfilerevs(repo, match, follow, revs, fncache)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1361
        except FileWalkError:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1362
            slowpath = True
11608
183e63112698 log: remove increasing windows usage in fastpath
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11607
diff changeset
  1363
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1364
            # We decided to fall back to the slowpath because at least one
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1365
            # of the paths was not a file. Check to see if at least one of them
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1366
            # existed in history, otherwise simply return
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1367
            for path in match.files():
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1368
                if path == '.' or path in repo.store:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1369
                    break
18340
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
  1370
            else:
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
  1371
                return []
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1372
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1373
    if slowpath:
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1374
        # We have to read the changelog to match filenames against
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1375
        # changed files
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1376
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1377
        if follow:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1378
            raise util.Abort(_('can only follow copies/renames for explicit '
8761
0289f384e1e5 Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents: 8731
diff changeset
  1379
                               'filenames'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1380
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1381
        # The slow path checks files modified in every changeset.
19730
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1382
        # This is really slow on large repos, so compute the set lazily.
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1383
        class lazywantedset(object):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1384
            def __init__(self):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1385
                self.set = set()
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1386
                self.revs = set(revs)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1387
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1388
            # No need to worry about locality here because it will be accessed
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1389
            # in the same order as the increasing window below.
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1390
            def __contains__(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1391
                if value in self.set:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1392
                    return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1393
                elif not value in self.revs:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1394
                    return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1395
                else:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1396
                    self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1397
                    ctx = change(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1398
                    matches = filter(match, ctx.files())
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1399
                    if matches:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1400
                        fncache[value] = matches
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1401
                        self.set.add(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1402
                        return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1403
                    return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1404
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1405
            def discard(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1406
                self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1407
                self.set.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1408
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1409
        wanted = lazywantedset()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1410
8778
c5f36402daad use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8761
diff changeset
  1411
    class followfilter(object):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1412
        def __init__(self, onlyfirst=False):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1413
            self.startrev = nullrev
10024
2b630e4c8f2f log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10012
diff changeset
  1414
            self.roots = set()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1415
            self.onlyfirst = onlyfirst
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1416
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1417
        def match(self, rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1418
            def realparents(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1419
                if self.onlyfirst:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1420
                    return repo.changelog.parentrevs(rev)[0:1]
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1421
                else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1422
                    return filter(lambda x: x != nullrev,
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1423
                                  repo.changelog.parentrevs(rev))
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1424
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1425
            if self.startrev == nullrev:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1426
                self.startrev = rev
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1427
                return True
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1428
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1429
            if rev > self.startrev:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1430
                # forward: all descendants
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1431
                if not self.roots:
10024
2b630e4c8f2f log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10012
diff changeset
  1432
                    self.roots.add(self.startrev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1433
                for parent in realparents(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1434
                    if parent in self.roots:
10024
2b630e4c8f2f log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10012
diff changeset
  1435
                        self.roots.add(rev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1436
                        return True
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1437
            else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1438
                # backwards: all parents
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1439
                if not self.roots:
10024
2b630e4c8f2f log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10012
diff changeset
  1440
                    self.roots.update(realparents(self.startrev))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1441
                if rev in self.roots:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1442
                    self.roots.remove(rev)
10024
2b630e4c8f2f log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10012
diff changeset
  1443
                    self.roots.update(realparents(rev))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1444
                    return True
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1445
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1446
            return False
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1447
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1448
    # it might be worthwhile to do this in the iterator if the rev range
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1449
    # is descending and the prune args are all within that range
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1450
    for rev in opts.get('prune', ()):
16380
84ba30e8c790 cmdutil: use context instead of lookup
Matt Mackall <mpm@selenic.com>
parents: 16304
diff changeset
  1451
        rev = repo[rev].rev()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1452
        ff = followfilter()
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1453
        stop = min(revs[0], revs[-1])
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1454
        for x in xrange(rev, stop - 1, -1):
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8119
diff changeset
  1455
            if ff.match(x):
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1456
                wanted = wanted - [x]
18710
49ef9d0ca815 cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents: 18688
diff changeset
  1457
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1458
    # Now that wanted is correctly initialized, we can iterate over the
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1459
    # revision range, yielding only revisions in wanted.
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1460
    def iterate():
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1461
        if follow and not match.files():
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1462
            ff = followfilter(onlyfirst=opts.get('follow_first'))
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1463
            def want(rev):
8119
af44d0b953c6 cmdutil: return boolean result directly in want function
Martin Geisler <mg@lazybytes.net>
parents: 8117
diff changeset
  1464
                return ff.match(rev) and rev in wanted
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1465
        else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1466
            def want(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1467
                return rev in wanted
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1468
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1469
        it = iter(revs)
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1470
        stopiteration = False
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1471
        for windowsize in increasingwindows():
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1472
            nrevs = []
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1473
            for i in xrange(windowsize):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1474
                try:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1475
                    rev = it.next()
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1476
                    if want(rev):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1477
                        nrevs.append(rev)
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1478
                except (StopIteration):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1479
                    stopiteration = True
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1480
                    break
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
  1481
            for rev in sorted(nrevs):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1482
                fns = fncache.get(rev)
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
  1483
                ctx = change(rev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1484
                if not fns:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1485
                    def fns_generator():
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
  1486
                        for f in ctx.files():
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1487
                            if match(f):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1488
                                yield f
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1489
                    fns = fns_generator()
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1490
                prepare(ctx, fns)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1491
            for rev in nrevs:
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1492
                yield change(rev)
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1493
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1494
            if stopiteration:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1495
                break
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1496
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1497
    return iterate()
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  1498
22166
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  1499
def _makefollowlogfilematcher(repo, files, followfirst):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1500
    # 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
  1501
    # 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
  1502
    # --follow, we want the names of the ancestors of FILE in the
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1503
    # revision, stored in "fcache". "fcache" is populated by
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1504
    # reproducing the graph traversal already done by --follow revset
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1505
    # and relating linkrevs to file names (which is not "correct" but
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1506
    # good enough).
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1507
    fcache = {}
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1508
    fcacheready = [False]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1509
    pctx = repo['.']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1510
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1511
    def populate():
21876
584bbfd1b50d log: make --patch --follow work inside a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 21825
diff changeset
  1512
        for fn in files:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1513
            for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1514
                for c in i:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1515
                    fcache.setdefault(c.linkrev(), set()).add(c.path())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1516
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1517
    def filematcher(rev):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1518
        if not fcacheready[0]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1519
            # Lazy initialization
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1520
            fcacheready[0] = True
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1521
            populate()
21878
e2530d4a47c1 log: use an exact matcher for --patch --follow
Siddharth Agarwal <sid0@fb.com>
parents: 21877
diff changeset
  1522
        return scmutil.matchfiles(repo, fcache.get(rev, []))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1523
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1524
    return filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1525
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1526
def _makenofollowlogfilematcher(repo, pats, opts):
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1527
    '''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
  1528
    return None
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1529
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  1530
def _makelogrevset(repo, pats, opts, revs):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1531
    """Return (expr, filematcher) where expr is a revset string built
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1532
    from log options and file patterns or None. If --stat or --patch
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1533
    are not passed filematcher is None. Otherwise it is a callable
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1534
    taking a revision number and returning a match objects filtering
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1535
    the files to be detailed when displaying the revision.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1536
    """
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1537
    opt2revset = {
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1538
        'no_merges':        ('not merge()', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1539
        'only_merges':      ('merge()', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1540
        '_ancestors':       ('ancestors(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1541
        '_fancestors':      ('_firstancestors(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1542
        '_descendants':     ('descendants(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1543
        '_fdescendants':    ('_firstdescendants(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1544
        '_matchfiles':      ('_matchfiles(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1545
        'date':             ('date(%(val)r)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1546
        'branch':           ('branch(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1547
        '_patslog':         ('filelog(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1548
        '_patsfollow':      ('follow(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1549
        '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1550
        'keyword':          ('keyword(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1551
        'prune':            ('not (%(val)r or ancestors(%(val)r))', ' and '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1552
        'user':             ('user(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1553
        }
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1554
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1555
    opts = dict(opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1556
    # follow or not follow?
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1557
    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
  1558
    followfirst = opts.get('follow_first') and 1 or 0
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1559
    # --follow with FILE behaviour depends on revs...
20756
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1560
    it = iter(revs)
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1561
    startrev = it.next()
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1562
    try:
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1563
        followdescendants = startrev < it.next()
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1564
    except (StopIteration):
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1565
        followdescendants = False
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1566
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1567
    # 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
  1568
    # the same time
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1569
    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
  1570
    opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1571
    # pats/include/exclude are passed to match.match() directly in
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17391
diff changeset
  1572
    # _matchfiles() revset but walkchangerevs() builds its matcher with
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1573
    # scmutil.match(). The difference is input pats are globbed on
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1574
    # platforms without shell expansion (windows).
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1575
    pctx = repo[None]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1576
    match, pats = scmutil.matchandpats(pctx, pats, opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1577
    slowpath = match.anypats() or (match.files() and opts.get('removed'))
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1578
    if not slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1579
        for f in match.files():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1580
            if follow and f not in pctx:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1581
                raise util.Abort(_('cannot follow file not in parent '
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1582
                                   'revision: "%s"') % f)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1583
            filelog = repo.file(f)
19293
446ab88d3f1c filelog: switch 'not len(filerevlog)' to 'not filerevlog'
Durham Goode <durham@fb.com>
parents: 19290
diff changeset
  1584
            if not filelog:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1585
                # A zero count may be a directory or deleted file, so
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1586
                # try to find matching entries on the slow path.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1587
                if follow:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1588
                    raise util.Abort(
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1589
                        _('cannot follow nonexistent file: "%s"') % f)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1590
                slowpath = True
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1591
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1592
        # We decided to fall back to the slowpath because at least one
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1593
        # of the paths was not a file. Check to see if at least one of them
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1594
        # existed in history - in that case, we'll continue down the
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1595
        # slowpath; otherwise, we can turn off the slowpath
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1596
        if slowpath:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1597
            for path in match.files():
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1598
                if path == '.' or path in repo.store:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1599
                    break
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1600
            else:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1601
                slowpath = False
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1602
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1603
    if slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1604
        # See walkchangerevs() slow path.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1605
        #
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1606
        if follow:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1607
            raise util.Abort(_('can only follow copies/renames for explicit '
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1608
                               'filenames'))
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1609
        # 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
  1610
        # revset expressions as their filtering logic applies at file
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1611
        # level. For instance "-I a -X a" matches a revision touching
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1612
        # "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
  1613
        # 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
  1614
        # directory.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1615
        matchargs = ['r:', 'd:relpath']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1616
        for p in pats:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1617
            matchargs.append('p:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1618
        for p in opts.get('include', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1619
            matchargs.append('i:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1620
        for p in opts.get('exclude', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1621
            matchargs.append('x:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1622
        matchargs = ','.join(('%r' % p) for p in matchargs)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1623
        opts['_matchfiles'] = matchargs
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1624
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1625
        if follow:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1626
            fpats = ('_patsfollow', '_patsfollowfirst')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1627
            fnopats = (('_ancestors', '_fancestors'),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1628
                       ('_descendants', '_fdescendants'))
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1629
            if pats:
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17391
diff changeset
  1630
                # follow() revset interprets its file argument as a
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1631
                # manifest entry, so use match.files(), not pats.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1632
                opts[fpats[followfirst]] = list(match.files())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1633
            else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1634
                opts[fnopats[followdescendants][followfirst]] = str(startrev)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1635
        else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1636
            opts['_patslog'] = list(pats)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1637
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1638
    filematcher = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1639
    if opts.get('patch') or opts.get('stat'):
21966
be94ed4baa5d log: do not use exact matcher for --patch --follow without file (issue4319)
Yuya Nishihara <yuya@tcha.org>
parents: 21944
diff changeset
  1640
        if follow and not match.always():
21876
584bbfd1b50d log: make --patch --follow work inside a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 21825
diff changeset
  1641
            # _makelogfilematcher expects its files argument to be relative to
584bbfd1b50d log: make --patch --follow work inside a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 21825
diff changeset
  1642
            # the repo root, so use match.files(), not pats.
22166
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  1643
            filematcher = _makefollowlogfilematcher(repo, match.files(),
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  1644
                                                    followfirst)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1645
        else:
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1646
            filematcher = _makenofollowlogfilematcher(repo, pats, opts)
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1647
            if filematcher is None:
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1648
                filematcher = lambda rev: match
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1649
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1650
    expr = []
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1651
    for op, val in opts.iteritems():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1652
        if not val:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1653
            continue
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1654
        if op not in opt2revset:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1655
            continue
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1656
        revop, andor = opt2revset[op]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1657
        if '%(val)' not in revop:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1658
            expr.append(revop)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1659
        else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1660
            if not isinstance(val, list):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1661
                e = revop % {'val': val}
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1662
            else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1663
                e = '(' + andor.join((revop % {'val': v}) for v in val) + ')'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1664
            expr.append(e)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1665
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1666
    if expr:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1667
        expr = '(' + ' and '.join(expr) + ')'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1668
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1669
        expr = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1670
    return expr, filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1671
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1672
def getgraphlogrevs(repo, pats, opts):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1673
    """Return (revs, expr, filematcher) where revs is an iterable of
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1674
    revision numbers, expr is a revset string built from log options
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1675
    and file patterns or None, and used to filter 'revs'. If --stat or
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1676
    --patch are not passed filematcher is None. Otherwise it is a
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1677
    callable taking a revision number and returning a match objects
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1678
    filtering the files to be detailed when displaying the revision.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1679
    """
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1680
    if not len(repo):
18171
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1681
        return [], None, None
18172
e6c5e0092469 cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents: 18171
diff changeset
  1682
    limit = loglimit(opts)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1683
    # Default --rev value depends on --follow but --follow behaviour
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1684
    # depends on revisions resolved from --rev...
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1685
    follow = opts.get('follow') or opts.get('follow_first')
18169
ae663cba9a8d cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents: 18031
diff changeset
  1686
    possiblyunsorted = False # whether revs might need sorting
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1687
    if opts.get('rev'):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1688
        revs = scmutil.revrange(repo, opts['rev'])
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  1689
        # Don't sort here because _makelogrevset might depend on the
18169
ae663cba9a8d cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents: 18031
diff changeset
  1690
        # order of revs
ae663cba9a8d cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents: 18031
diff changeset
  1691
        possiblyunsorted = True
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1692
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1693
        if follow and len(repo) > 0:
17676
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1694
            revs = repo.revs('reverse(:.)')
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1695
        else:
20757
3813a1dd9eb9 cmdutil: changed revset for spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20756
diff changeset
  1696
            revs = revset.spanset(repo)
17675
8575f4a2126e clfilter: remove usage of `range` in favor of iteration over changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17475
diff changeset
  1697
            revs.reverse()
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1698
    if not revs:
20759
74139960c302 getgraphlogrevs: return an empty baseset instead of a empty list
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20758
diff changeset
  1699
        return revset.baseset(), None, None
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  1700
    expr, filematcher = _makelogrevset(repo, pats, opts, revs)
18169
ae663cba9a8d cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents: 18031
diff changeset
  1701
    if possiblyunsorted:
ae663cba9a8d cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents: 18031
diff changeset
  1702
        revs.sort(reverse=True)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1703
    if expr:
18171
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1704
        # Revset matchers often operate faster on revisions in changelog
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1705
        # order, because most filters deal with the changelog.
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1706
        revs.reverse()
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1707
        matcher = revset.match(repo.ui, expr)
18171
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1708
        # Revset matches can reorder revisions. "A or B" typically returns
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1709
        # returns the revision matching A then the revision matching B. Sort
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1710
        # again to fix that.
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1711
        revs = matcher(repo, revs)
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1712
        revs.sort(reverse=True)
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
  1713
    if limit is not None:
20755
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1714
        limitedrevs = revset.baseset()
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1715
        for idx, rev in enumerate(revs):
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1716
            if idx >= limit:
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1717
                break
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1718
            limitedrevs.append(rev)
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1719
        revs = limitedrevs
18172
e6c5e0092469 cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents: 18171
diff changeset
  1720
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1721
    return revs, expr, filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1722
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1723
def getlogrevs(repo, pats, opts):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1724
    """Return (revs, expr, filematcher) where revs is an iterable of
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1725
    revision numbers, expr is a revset string built from log options
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1726
    and file patterns or None, and used to filter 'revs'. If --stat or
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1727
    --patch are not passed filematcher is None. Otherwise it is a
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1728
    callable taking a revision number and returning a match objects
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1729
    filtering the files to be detailed when displaying the revision.
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1730
    """
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1731
    limit = loglimit(opts)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1732
    # Default --rev value depends on --follow but --follow behaviour
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1733
    # depends on revisions resolved from --rev...
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1734
    follow = opts.get('follow') or opts.get('follow_first')
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1735
    if opts.get('rev'):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1736
        revs = scmutil.revrange(repo, opts['rev'])
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1737
    elif follow:
21872
abae1eb695c0 log: allow revset for --follow to be lazily evaluated
Siddharth Agarwal <sid0@fb.com>
parents: 21869
diff changeset
  1738
        revs = repo.revs('reverse(:.)')
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1739
    else:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1740
        revs = revset.spanset(repo)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1741
        revs.reverse()
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1742
    if not revs:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1743
        return revset.baseset([]), None, None
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1744
    expr, filematcher = _makelogrevset(repo, pats, opts, revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1745
    if expr:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1746
        # Revset matchers often operate faster on revisions in changelog
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1747
        # order, because most filters deal with the changelog.
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1748
        if not opts.get('rev'):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1749
            revs.reverse()
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1750
        matcher = revset.match(repo.ui, expr)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1751
        # Revset matches can reorder revisions. "A or B" typically returns
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1752
        # returns the revision matching A then the revision matching B. Sort
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1753
        # again to fix that.
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1754
        revs = matcher(repo, revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1755
        if not opts.get('rev'):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1756
            revs.sort(reverse=True)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1757
    if limit is not None:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1758
        count = 0
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1759
        limitedrevs = revset.baseset([])
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1760
        it = iter(revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1761
        while count < limit:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1762
            try:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1763
                limitedrevs.append(it.next())
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1764
            except (StopIteration):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1765
                break
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1766
            count += 1
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1767
        revs = limitedrevs
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1768
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1769
    return revs, expr, filematcher
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1770
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1771
def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None,
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1772
                 filematcher=None):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1773
    seen, state = [], graphmod.asciistate()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1774
    for rev, type, ctx, parents in dag:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1775
        char = 'o'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1776
        if ctx.node() in showparents:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1777
            char = '@'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1778
        elif ctx.obsolete():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1779
            char = 'x'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1780
        copies = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1781
        if getrenamed and ctx.rev():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1782
            copies = []
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1783
            for fn in ctx.files():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1784
                rename = getrenamed(fn, ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1785
                if rename:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1786
                    copies.append((fn, rename[0]))
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1787
        revmatchfn = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1788
        if filematcher is not None:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1789
            revmatchfn = filematcher(ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1790
        displayer.show(ctx, copies=copies, matchfn=revmatchfn)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1791
        lines = displayer.hunk.pop(rev).split('\n')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1792
        if not lines[-1]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1793
            del lines[-1]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1794
        displayer.flush(rev)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1795
        edges = edgefn(type, char, lines, seen, rev, parents)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1796
        for type, char, lines, coldata in edges:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1797
            graphmod.ascii(ui, state, type, char, lines, coldata)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1798
    displayer.close()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1799
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1800
def graphlog(ui, repo, *pats, **opts):
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1801
    # Parameters are identical to log command ones
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1802
    revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1803
    revdag = graphmod.dagwalker(repo, revs)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1804
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1805
    getrenamed = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1806
    if opts.get('copies'):
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1807
        endrev = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1808
        if opts.get('rev'):
20760
d5fa413346e7 cmdutil: changed max method for lazy call
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20759
diff changeset
  1809
            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
  1810
        getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1811
    displayer = show_changeset(ui, repo, opts, buffered=True)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1812
    showparents = [ctx.node() for ctx in repo[None].parents()]
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1813
    displaygraph(ui, revdag, displayer, showparents,
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1814
                 graphmod.asciiedges, getrenamed, filematcher)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1815
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1816
def checkunsupportedgraphflags(pats, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1817
    for op in ["newest_first"]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1818
        if op in opts and opts[op]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1819
            raise util.Abort(_("-G/--graph option is incompatible with --%s")
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1820
                             % op.replace("_", "-"))
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1821
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1822
def graphrevs(repo, nodes, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1823
    limit = loglimit(opts)
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1824
    nodes.reverse()
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1825
    if limit is not None:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1826
        nodes = nodes[:limit]
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1827
    return graphmod.nodes(repo, nodes)
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1828
15911
c654eac03452 add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15907
diff changeset
  1829
def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1830
    join = lambda f: os.path.join(prefix, f)
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1831
    bad = []
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1832
    oldbad = match.bad
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1833
    match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1834
    names = []
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1835
    wctx = repo[None]
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1836
    cca = None
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1837
    abort, warn = scmutil.checkportabilityalert(ui)
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1838
    if abort or warn:
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17182
diff changeset
  1839
        cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate)
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1840
    for f in repo.walk(match):
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1841
        exact = match.exact(f)
15911
c654eac03452 add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15907
diff changeset
  1842
        if exact or not explicitonly and f not in repo.dirstate:
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1843
            if cca:
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1844
                cca(f)
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1845
            names.append(f)
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1846
            if ui.verbose or not exact:
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1847
                ui.status(_('adding %s\n') % match.rel(join(f)))
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1848
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  1849
    for subpath in sorted(wctx.substate):
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1850
        sub = wctx.sub(subpath)
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1851
        try:
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1852
            submatch = matchmod.narrowmatcher(subpath, match)
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1853
            if listsubrepos:
15911
c654eac03452 add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15907
diff changeset
  1854
                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
c654eac03452 add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15907
diff changeset
  1855
                                   False))
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1856
            else:
15911
c654eac03452 add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15907
diff changeset
  1857
                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
c654eac03452 add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15907
diff changeset
  1858
                                   True))
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1859
        except error.LookupError:
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1860
            ui.status(_("skipping missing subrepository: %s\n")
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1861
                           % join(subpath))
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1862
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1863
    if not dryrun:
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1864
        rejected = wctx.add(names, prefix)
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1865
        bad.extend(f for f in rejected if f in match.files())
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1866
    return bad
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1867
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1868
def forget(ui, repo, match, prefix, explicitonly):
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1869
    join = lambda f: os.path.join(prefix, f)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1870
    bad = []
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1871
    oldbad = match.bad
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1872
    match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1873
    wctx = repo[None]
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1874
    forgot = []
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1875
    s = repo.status(match=match, clean=True)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1876
    forget = sorted(s[0] + s[1] + s[3] + s[6])
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1877
    if explicitonly:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1878
        forget = [f for f in forget if match.exact(f)]
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1879
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  1880
    for subpath in sorted(wctx.substate):
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1881
        sub = wctx.sub(subpath)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1882
        try:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1883
            submatch = matchmod.narrowmatcher(subpath, match)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1884
            subbad, subforgot = sub.forget(ui, submatch, prefix)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1885
            bad.extend([subpath + '/' + f for f in subbad])
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1886
            forgot.extend([subpath + '/' + f for f in subforgot])
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1887
        except error.LookupError:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1888
            ui.status(_("skipping missing subrepository: %s\n")
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1889
                           % join(subpath))
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1890
16070
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
  1891
    if not explicitonly:
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
  1892
        for f in match.files():
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1893
            if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))):
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1894
                if f not in forgot:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1895
                    if os.path.exists(match.rel(join(f))):
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1896
                        ui.warn(_('not removing %s: '
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1897
                                  'file is already untracked\n')
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1898
                                % match.rel(join(f)))
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1899
                    bad.append(f)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1900
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1901
    for f in forget:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1902
        if ui.verbose or not match.exact(f):
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1903
            ui.status(_('removing %s\n') % match.rel(join(f)))
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1904
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1905
    rejected = wctx.forget(forget, prefix)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1906
    bad.extend(f for f in rejected if f in match.files())
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1907
    forgot.extend(forget)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1908
    return bad, forgot
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  1909
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1910
def cat(ui, repo, ctx, matcher, prefix, **opts):
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1911
    err = 1
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1912
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1913
    def write(path):
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1914
        fp = makefileobj(repo, opts.get('output'), ctx.node(),
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1915
                         pathname=os.path.join(prefix, path))
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1916
        data = ctx[path].data()
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1917
        if opts.get('decode'):
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1918
            data = repo.wwritedata(path, data)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1919
        fp.write(data)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1920
        fp.close()
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1921
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1922
    # Automation often uses hg cat on single files, so special case it
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1923
    # for performance to avoid the cost of parsing the manifest.
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1924
    if len(matcher.files()) == 1 and not matcher.anypats():
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1925
        file = matcher.files()[0]
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1926
        mf = repo.manifest
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1927
        mfnode = ctx._changeset[0]
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1928
        if mf.find(mfnode, file)[0]:
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1929
            write(file)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1930
            return 0
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1931
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1932
    # Don't warn about "missing" files that are really in subrepos
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1933
    bad = matcher.bad
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1934
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1935
    def badfn(path, msg):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1936
        for subpath in ctx.substate:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1937
            if path.startswith(subpath):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1938
                return
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1939
        bad(path, msg)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1940
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1941
    matcher.bad = badfn
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1942
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1943
    for abs in ctx.walk(matcher):
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1944
        write(abs)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1945
        err = 0
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1946
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1947
    matcher.bad = bad
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1948
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1949
    for subpath in sorted(ctx.substate):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1950
        sub = ctx.sub(subpath)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1951
        try:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1952
            submatch = matchmod.narrowmatcher(subpath, matcher)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1953
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1954
            if not sub.cat(ui, submatch, os.path.join(prefix, sub._path),
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1955
                           **opts):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1956
                err = 0
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1957
        except error.RepoLookupError:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1958
            ui.status(_("skipping missing subrepository: %s\n")
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1959
                           % os.path.join(prefix, subpath))
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  1960
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1961
    return err
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  1962
21825
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1963
def duplicatecopies(repo, rev, fromrev, skiprev=None):
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1964
    '''reproduce copies from fromrev to rev in the dirstate
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1965
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1966
    If skiprev is specified, it's a revision that should be used to
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1967
    filter copy records. Any copies that occur between fromrev and
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1968
    skiprev will not be duplicated, even if they appear in the set of
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1969
    copies between fromrev and rev.
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1970
    '''
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1971
    exclude = {}
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1972
    if skiprev is not None:
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1973
        exclude = copies.pathcopies(repo[fromrev], repo[skiprev])
18852
300844cb1a56 duplicatecopies: fix arg name and docstring
Siddharth Agarwal <sid0@fb.com>
parents: 18710
diff changeset
  1974
    for dst, src in copies.pathcopies(repo[fromrev], repo[rev]).iteritems():
18853
78d760aa3607 duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents: 18852
diff changeset
  1975
        # copies.pathcopies returns backward renames, so dst might not
78d760aa3607 duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents: 18852
diff changeset
  1976
        # actually be in the dirstate
21825
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1977
        if dst in exclude:
3666331164bb cmdutil: add copy-filtering support to duplicatecopies
Augie Fackler <raf@durin42.com>
parents: 21127
diff changeset
  1978
            continue
18853
78d760aa3607 duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents: 18852
diff changeset
  1979
        if repo.dirstate[dst] in "nma":
78d760aa3607 duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents: 18852
diff changeset
  1980
            repo.dirstate.copy(src, dst)
15214
231aac5280ba rebase: move updatedirstate into cmdutil so it can be shared
Matt Mackall <mpm@selenic.com>
parents: 14986
diff changeset
  1981
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  1982
def commit(ui, repo, commitfunc, pats, opts):
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  1983
    '''commit the specified files or all outstanding changes'''
6139
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  1984
    date = opts.get('date')
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  1985
    if date:
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  1986
        opts['date'] = util.parsedate(date)
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
  1987
    message = logmessage(ui, opts)
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  1988
5829
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  1989
    # extract addremove carefully -- this function can be called from a command
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  1990
    # that doesn't support addremove
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  1991
    if opts.get('addremove'):
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
  1992
        scmutil.addremove(repo, pats, opts)
5829
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  1993
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14638
diff changeset
  1994
    return commitfunc(ui, repo, message,
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14638
diff changeset
  1995
                      scmutil.match(repo[None], pats, opts), opts)
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  1996
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  1997
def amend(ui, repo, commitfunc, old, extra, pats, opts):
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  1998
    ui.note(_('amending changeset %s\n') % old)
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  1999
    base = old.p1()
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2000
18197
153659e86a5f amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18006
diff changeset
  2001
    wlock = lock = newid = None
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2002
    try:
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2003
        wlock = repo.wlock()
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2004
        lock = repo.lock()
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2005
        tr = repo.transaction('amend')
17049
2440822446ce amend: disable hooks when creating intermediate commit (issue3501)
Idan Kamara <idankk86@gmail.com>
parents: 16678
diff changeset
  2006
        try:
17473
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2007
            # See if we got a message from -m or -l, if not, open the editor
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2008
            # with the message of the changeset to amend
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2009
            message = logmessage(ui, opts)
17863
034e55bbf7c0 amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17812
diff changeset
  2010
            # ensure logfile does not conflict with later enforcement of the
034e55bbf7c0 amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17812
diff changeset
  2011
            # message. potential logfile content has been processed by
034e55bbf7c0 amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17812
diff changeset
  2012
            # `logmessage` anyway.
034e55bbf7c0 amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17812
diff changeset
  2013
            opts.pop('logfile')
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2014
            # First, do a regular commit to record all changes in the working
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2015
            # directory (if there are any)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2016
            ui.callhooks = False
18198
9b4adaef0db9 amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18197
diff changeset
  2017
            currentbookmark = repo._bookmarkcurrent
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2018
            try:
18198
9b4adaef0db9 amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18197
diff changeset
  2019
                repo._bookmarkcurrent = None
17473
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2020
                opts['message'] = 'temporary amend commit for %s' % old
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2021
                node = commit(ui, repo, commitfunc, pats, opts)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2022
            finally:
18198
9b4adaef0db9 amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18197
diff changeset
  2023
                repo._bookmarkcurrent = currentbookmark
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2024
                ui.callhooks = True
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2025
            ctx = repo[node]
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2026
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2027
            # Participating changesets:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2028
            #
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2029
            # node/ctx o - new (intermediate) commit that contains changes
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2030
            #          |   from working dir to go into amending commit
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2031
            #          |   (or a workingctx if there were no changes)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2032
            #          |
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2033
            # old      o - changeset to amend
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2034
            #          |
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2035
            # base     o - parent of amending changeset
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2036
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2037
            # Update extra dict from amended commit (e.g. to preserve graft
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2038
            # source)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2039
            extra.update(old.extra())
16630
f30226b1a46a amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents: 16553
diff changeset
  2040
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2041
            # Also update it from the intermediate commit or from the wctx
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2042
            extra.update(ctx.extra())
16630
f30226b1a46a amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents: 16553
diff changeset
  2043
18909
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2044
            if len(old.parents()) > 1:
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2045
                # ctx.files() isn't reliable for merges, so fall back to the
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2046
                # slower repo.status() method
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2047
                files = set([fn for st in repo.status(base, old)[:3]
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2048
                             for fn in st])
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2049
            else:
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2050
                files = set(old.files())
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2051
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2052
            # Second, we use either the commit we just did, or if there were no
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2053
            # changes the parent of the working directory as the version of the
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2054
            # files in the final amend commit
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2055
            if node:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2056
                ui.note(_('copying changeset %s to %s\n') % (ctx, base))
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2057
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2058
                user = ctx.user()
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2059
                date = ctx.date()
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2060
                # Recompute copies (avoid recording a -> b -> a)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2061
                copied = copies.pathcopies(base, ctx)
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2062
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2063
                # Prune files which were reverted by the updates: if old
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2064
                # introduced file X and our intermediate commit, node,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2065
                # renamed that file, then those two files are the same and
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2066
                # we can discard X from our list of files. Likewise if X
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2067
                # was deleted, it's no longer relevant
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2068
                files.update(ctx.files())
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2069
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2070
                def samefile(f):
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2071
                    if f in ctx.manifest():
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2072
                        a = ctx.filectx(f)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2073
                        if f in base.manifest():
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2074
                            b = base.filectx(f)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2075
                            return (not a.cmp(b)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2076
                                    and a.flags() == b.flags())
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2077
                        else:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2078
                            return False
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2079
                    else:
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2080
                        return f not in base.manifest()
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2081
                files = [f for f in files if not samefile(f)]
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2082
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2083
                def filectxfn(repo, ctx_, path):
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2084
                    try:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2085
                        fctx = ctx[path]
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2086
                        flags = fctx.flags()
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21579
diff changeset
  2087
                        mctx = context.memfilectx(repo,
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21579
diff changeset
  2088
                                                  fctx.path(), fctx.data(),
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2089
                                                  islink='l' in flags,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2090
                                                  isexec='x' in flags,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2091
                                                  copied=copied.get(path))
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2092
                        return mctx
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2093
                    except KeyError:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2094
                        raise IOError
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2095
            else:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2096
                ui.note(_('copying changeset %s to %s\n') % (old, base))
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2097
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2098
                # Use version of files as in the old cset
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2099
                def filectxfn(repo, ctx_, path):
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2100
                    try:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2101
                        return old.filectx(path)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2102
                    except KeyError:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2103
                        raise IOError
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2104
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2105
                user = opts.get('user') or old.user()
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2106
                date = opts.get('date') or old.date()
21415
0b5d6c062774 amend: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21405
diff changeset
  2107
            editor = getcommiteditor(**opts)
17473
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2108
            if not message:
21415
0b5d6c062774 amend: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21405
diff changeset
  2109
                editor = getcommiteditor(edit=True)
17473
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2110
                message = old.description()
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2111
17811
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2112
            pureextra = extra.copy()
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2113
            extra['amend_source'] = old.hex()
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2114
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2115
            new = context.memctx(repo,
18909
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2116
                                 parents=[base.node(), old.p2().node()],
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2117
                                 text=message,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2118
                                 files=files,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2119
                                 filectxfn=filectxfn,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2120
                                 user=user,
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2121
                                 date=date,
21240
1a833fcf5a14 amend: use "editor" argument for "memctx.__init__" to save commit message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21127
diff changeset
  2122
                                 extra=extra,
1a833fcf5a14 amend: use "editor" argument for "memctx.__init__" to save commit message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21127
diff changeset
  2123
                                 editor=editor)
17811
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2124
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2125
            newdesc =  changelog.stripdesc(new.description())
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2126
            if ((not node)
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2127
                and newdesc == old.description()
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2128
                and user == old.user()
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2129
                and date == old.date()
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2130
                and pureextra == old.extra()):
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2131
                # nothing changed. continuing here would create a new node
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2132
                # anyway because of the amend_source noise.
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2133
                #
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2134
                # This not what we expect from amend.
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2135
                return old.node()
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2136
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2137
            ph = repo.ui.config('phases', 'new-commit', phases.draft)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2138
            try:
20700
b0153cb8b64e commit: create new amend changeset as secret correctly for "--secret" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20072
diff changeset
  2139
                if opts.get('secret'):
b0153cb8b64e commit: create new amend changeset as secret correctly for "--secret" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20072
diff changeset
  2140
                    commitphase = 'secret'
b0153cb8b64e commit: create new amend changeset as secret correctly for "--secret" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20072
diff changeset
  2141
                else:
b0153cb8b64e commit: create new amend changeset as secret correctly for "--secret" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20072
diff changeset
  2142
                    commitphase = old.phase()
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20773
diff changeset
  2143
                repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend')
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2144
                newid = repo.commitctx(new)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2145
            finally:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20773
diff changeset
  2146
                repo.ui.setconfig('phases', 'new-commit', ph, 'amend')
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2147
            if newid != old.node():
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2148
                # Reroute the working copy parent to the new changeset
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2149
                repo.setparents(newid, nullid)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2150
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2151
                # Move bookmarks from old parent to amend commit
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2152
                bms = repo.nodebookmarks(old.node())
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2153
                if bms:
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2154
                    marks = repo._bookmarks
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2155
                    for bm in bms:
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2156
                        marks[bm] = newid
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2157
                    marks.write()
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2158
            #commit the whole amend process
17475
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2159
            if obsolete._enabled and newid != old.node():
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2160
                # mark the new changeset as successor of the rewritten one
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2161
                new = repo[newid]
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2162
                obs = [(old, (new,))]
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2163
                if node:
17812
578fcc22b469 amend: do a bare kill of temporary changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17811
diff changeset
  2164
                    obs.append((ctx, ()))
17475
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2165
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2166
                obsolete.createmarkers(repo, obs)
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2167
            tr.close()
17461
bacde764fba0 amend: preserve phase of amended revision (issue3602)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17391
diff changeset
  2168
        finally:
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2169
            tr.release()
17475
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2170
        if (not obsolete._enabled) and newid != old.node():
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2171
            # Strip the intermediate commit (if there was one) and the amended
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2172
            # commit
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2173
            if node:
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2174
                ui.note(_('stripping intermediate changeset %s\n') % ctx)
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2175
            ui.note(_('stripping amended changeset %s\n') % old)
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2176
            repair.strip(ui, repo, old.node(), topic='amend-backup')
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2177
    finally:
18197
153659e86a5f amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18006
diff changeset
  2178
        if newid is None:
153659e86a5f amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18006
diff changeset
  2179
            repo.dirstate.invalidate()
19024
ab04e87a5f3b amend: fix unlocking order - first lock then wlock
Mads Kiilerich <madski@unity3d.com>
parents: 18991
diff changeset
  2180
        lockmod.release(lock, wlock)
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2181
    return newid
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2182
8994
4a1187d3cb00 commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents: 8990
diff changeset
  2183
def commiteditor(repo, ctx, subs):
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2184
    if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2185
        return ctx.description()
8994
4a1187d3cb00 commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents: 8990
diff changeset
  2186
    return commitforceeditor(repo, ctx, subs)
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2187
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
  2188
def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
21923
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2189
    if not extramsg:
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2190
        extramsg = _("Leave message empty to abort commit.")
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2191
    tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2192
    if tmpl:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2193
        committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2194
    else:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2195
        committext = buildcommittext(repo, ctx, subs, extramsg)
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2196
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2197
    # run editor in the repository root
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2198
    olddir = os.getcwd()
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2199
    os.chdir(repo.root)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2200
    text = repo.ui.edit(committext, ctx.user(), ctx.extra())
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2201
    text = re.sub("(?m)^HG:.*(\n|$)", "", text)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2202
    os.chdir(olddir)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2203
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2204
    if finishdesc:
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2205
        text = finishdesc(text)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2206
    if not text.strip():
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2207
        raise util.Abort(_("empty commit message"))
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2208
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2209
    return text
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2210
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2211
def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2212
    ui = repo.ui
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2213
    tmpl, mapfile = gettemplate(ui, tmpl, None)
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2214
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2215
    try:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2216
        t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False)
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2217
    except SyntaxError, inst:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2218
        raise util.Abort(inst.args[0])
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2219
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2220
    if not extramsg:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2221
        extramsg = '' # ensure that extramsg is string
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2222
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2223
    ui.pushbuffer()
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2224
    t.show(ctx, extramsg=extramsg)
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2225
    return ui.popbuffer()
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2226
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2227
def buildcommittext(repo, ctx, subs, extramsg):
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2228
    edittext = []
8707
0550dfe4fca1 commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents: 8680
diff changeset
  2229
    modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2230
    if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2231
        edittext.append(ctx.description())
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2232
    edittext.append("")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2233
    edittext.append("") # Empty line between message and comments.
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2234
    edittext.append(_("HG: Enter commit message."
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2235
                      "  Lines beginning with 'HG:' are removed."))
21923
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2236
    edittext.append("HG: %s" % extramsg)
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2237
    edittext.append("HG: --")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2238
    edittext.append(_("HG: user: %s") % ctx.user())
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2239
    if ctx.p2():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2240
        edittext.append(_("HG: branch merge"))
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2241
    if ctx.branch():
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12973
diff changeset
  2242
        edittext.append(_("HG: branch '%s'") % ctx.branch())
18538
94317c2d53b8 commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents: 18364
diff changeset
  2243
    if bookmarks.iscurrent(repo):
94317c2d53b8 commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents: 18364
diff changeset
  2244
        edittext.append(_("HG: bookmark '%s'") % repo._bookmarkcurrent)
8994
4a1187d3cb00 commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents: 8990
diff changeset
  2245
    edittext.extend([_("HG: subrepo %s") % s for s in subs])
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2246
    edittext.extend([_("HG: added %s") % f for f in added])
8707
0550dfe4fca1 commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents: 8680
diff changeset
  2247
    edittext.extend([_("HG: changed %s") % f for f in modified])
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2248
    edittext.extend([_("HG: removed %s") % f for f in removed])
8707
0550dfe4fca1 commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents: 8680
diff changeset
  2249
    if not added and not modified and not removed:
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2250
        edittext.append(_("HG: no files changed"))
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2251
    edittext.append("")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2252
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2253
    return "\n".join(edittext)
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2254
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2255
def commitstatus(repo, node, branch, bheads=None, opts={}):
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2256
    ctx = repo[node]
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2257
    parents = ctx.parents()
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2258
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2259
    if (not opts.get('amend') and bheads and node not in bheads and not
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2260
        [x for x in parents if x.node() in bheads and x.branch() == branch]):
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2261
        repo.ui.status(_('created new head\n'))
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2262
        # The message is not printed for initial roots. For the other
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2263
        # changesets, it is printed in the following situations:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2264
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2265
        # Par column: for the 2 parents with ...
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2266
        #   N: null or no parent
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2267
        #   B: parent is on another named branch
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2268
        #   C: parent is a regular non head changeset
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2269
        #   H: parent was a branch head of the current branch
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2270
        # Msg column: whether we print "created new head" message
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2271
        # In the following, it is assumed that there already exists some
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2272
        # initial branch heads of the current branch, otherwise nothing is
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2273
        # printed anyway.
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2274
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2275
        # Par Msg Comment
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2276
        # N N  y  additional topo root
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2277
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2278
        # B N  y  additional branch root
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2279
        # C N  y  additional topo head
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2280
        # H N  n  usual case
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2281
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2282
        # B B  y  weird additional branch root
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2283
        # C B  y  branch merge
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2284
        # H B  n  merge with named branch
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2285
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2286
        # C C  y  additional head from merge
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2287
        # C H  n  merge with a head
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2288
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2289
        # H H  n  head merge: head count decreases
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2290
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2291
    if not opts.get('close_branch'):
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2292
        for r in parents:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2293
            if r.closesbranch() and r.branch() == branch:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2294
                repo.ui.status(_('reopening closed branch head %d\n') % r)
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2295
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2296
    if repo.ui.debugflag:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2297
        repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex()))
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2298
    elif repo.ui.verbose:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2299
        repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx))
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2300
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2301
def revert(ui, repo, ctx, parents, *pats, **opts):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2302
    parent, p2 = parents
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2303
    node = ctx.node()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2305
    mf = ctx.manifest()
21579
87a972b5c039 revert: use p2 as parent when reverting against it
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21578
diff changeset
  2306
    if node == p2:
87a972b5c039 revert: use p2 as parent when reverting against it
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21578
diff changeset
  2307
        parent = p2
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2308
    if node == parent:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2309
        pmf = mf
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2310
    else:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2311
        pmf = None
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2312
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2313
    # need all matching names in dirstate and manifest of target rev,
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2314
    # so have to walk both. do not print errors if files exist in one
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2315
    # but not other.
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2316
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2317
    # `names` is a mapping for all elements in working copy and target revision
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2318
    # The mapping is in the form:
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2319
    #   <asb path in repo> -> (<path from CWD>, <exactly specified by matcher?>)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2320
    names = {}
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2321
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2322
    wlock = repo.wlock()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2323
    try:
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2324
        ## filling of the `names` mapping
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2325
        # walk dirstate to fill `names`
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2326
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2327
        m = scmutil.match(repo[None], pats, opts)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2328
        m.bad = lambda x, y: False
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2329
        for abs in repo.walk(m):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2330
            names[abs] = m.rel(abs), m.exact(abs)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2331
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2332
        # walk target manifest to fill `names`
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2333
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2334
        def badfn(path, msg):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2335
            if path in names:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2336
                return
16583
146a00c162a0 revert: don't re-create changeset context
Kevin Bullock <kbullock@ringworld.org>
parents: 16553
diff changeset
  2337
            if path in ctx.substate:
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2338
                return
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2339
            path_ = path + '/'
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2340
            for f in names:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2341
                if f.startswith(path_):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2342
                    return
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2343
            ui.warn("%s: %s\n" % (m.rel(path), msg))
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2344
16583
146a00c162a0 revert: don't re-create changeset context
Kevin Bullock <kbullock@ringworld.org>
parents: 16553
diff changeset
  2345
        m = scmutil.match(ctx, pats, opts)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2346
        m.bad = badfn
16583
146a00c162a0 revert: don't re-create changeset context
Kevin Bullock <kbullock@ringworld.org>
parents: 16553
diff changeset
  2347
        for abs in ctx.walk(m):
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2348
            if abs not in names:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2349
                names[abs] = m.rel(abs), m.exact(abs)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2350
16430
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  2351
        # get the list of subrepos that must be reverted
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  2352
        targetsubs = sorted(s for s in ctx.substate if m(s))
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2353
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2354
        # Find status of all file in `names`. (Against working directory parent)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2355
        m = scmutil.matchfiles(repo, names)
21578
7cfe51661e98 revert: explicitly get status against the parent
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21577
diff changeset
  2356
        changes = repo.status(node1=parent, match=m)[:4]
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2357
        modified, added, removed, deleted = map(set, changes)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2358
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2359
        # if f is a rename, update `names` to also revert the source
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2360
        cwd = repo.getcwd()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2361
        for f in added:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2362
            src = repo.dirstate.copied(f)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2363
            if src and src not in names and repo.dirstate[src] == 'r':
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2364
                removed.add(src)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2365
                names[src] = (repo.pathto(src, cwd), True)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2366
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2367
        ## computation of the action to performs on `names` content.
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2368
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2369
        def removeforget(abs):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2370
            if repo.dirstate[abs] == 'a':
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2371
                return _('forgetting %s\n')
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2372
            return _('removing %s\n')
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2373
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2374
        # action to be actually performed by revert
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2375
        # (<list of file>, message>) tuple
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2376
        actions = {'revert': ([], _('reverting %s\n')),
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2377
                   'add': ([], _('adding %s\n')),
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2378
                   'remove': ([], removeforget),
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2379
                   'undelete': ([], _('undeleting %s\n'))}
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2380
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2381
        disptable = (
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2382
            # dispatch table:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2383
            #   file state
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2384
            #   action if in target manifest
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2385
            #   action if not in target manifest
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2386
            #   make backup if in target manifest
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2387
            #   make backup if not in target manifest
21577
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2388
            (modified, (actions['revert'],   True),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2389
                       (actions['remove'],   True)),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2390
            (added,    (actions['revert'],   True),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2391
                       (actions['remove'],   False)),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2392
            (removed,  (actions['undelete'], True),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2393
                       (None,                False)),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2394
            (deleted,  (actions['revert'], False),
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2395
                       (actions['remove'], False)),
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2396
            )
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2397
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2398
        for abs, (rel, exact) in sorted(names.items()):
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2399
            # hash on file in target manifest (or None if missing from target)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2400
            mfentry = mf.get(abs)
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2401
            # target file to be touch on disk (relative to cwd)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2402
            target = repo.wjoin(abs)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2403
            def handle(xlist, dobackup):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2404
                xlist[0].append(abs)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2405
                if (dobackup and not opts.get('no_backup') and
19510
8b190adb7ee3 revert: make backup when unforgetting a file (issue3423)
Matt Mackall <mpm@selenic.com>
parents: 19496
diff changeset
  2406
                    os.path.lexists(target) and
19511
ca2dfc2f63eb revert: fix largefiles breakage
Matt Mackall <mpm@selenic.com>
parents: 19510
diff changeset
  2407
                    abs in ctx and repo[None][abs].cmp(ctx[abs])):
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2408
                    bakname = "%s.orig" % rel
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2409
                    ui.note(_('saving current version of %s as %s\n') %
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2410
                            (rel, bakname))
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2411
                    if not opts.get('dry_run'):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2412
                        util.rename(target, bakname)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2413
                if ui.verbose or not exact:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2414
                    msg = xlist[1]
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2415
                    if not isinstance(msg, basestring):
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2416
                        msg = msg(abs)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2417
                    ui.status(msg % rel)
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2418
            # search the entry in the dispatch table.
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2419
            # if the file is in any of this sets, it was touched in the working
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2420
            # directory parent and we are sure it needs to be reverted.
21577
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2421
            for table, hit, miss in disptable:
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2422
                if abs not in table:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2423
                    continue
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2424
                # file has changed in dirstate
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2425
                if mfentry:
21577
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2426
                    handle(*hit)
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2427
                elif miss[0] is not None:
c62c5ce750ee revert: group related data in tuple in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21576
diff changeset
  2428
                    handle(*miss)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2429
                break
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2430
            else:
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2431
                # Not touched in current dirstate.
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2432
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2433
                # file is unknown in parent, restore older version or ignore.
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2434
                if abs not in repo.dirstate:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2435
                    if mfentry:
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2436
                        handle(actions['add'], True)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2437
                    elif exact:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2438
                        ui.warn(_('file not managed: %s\n') % rel)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2439
                    continue
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2440
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2441
                # parent is target, no changes mean no changes
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2442
                if node == parent:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2443
                    if exact:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2444
                        ui.warn(_('no changes needed to %s\n') % rel)
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2445
                    continue
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2446
                # no change in dirstate but parent and target may differ
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2447
                if pmf is None:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2448
                    # only need parent manifest in this unlikely case,
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2449
                    # so do not read by default
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2450
                    pmf = repo[parent].manifest()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2451
                if abs in pmf and mfentry:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2452
                    # if version of file is same in parent and target
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2453
                    # manifests, do nothing
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2454
                    if (pmf[abs] != mfentry or
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2455
                        pmf.flags(abs) != mf.flags(abs)):
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2456
                        handle(actions['revert'], False)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2457
                else:
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2458
                    handle(actions['remove'], False)
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2459
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2460
        if not opts.get('dry_run'):
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2461
            _performrevert(repo, parents, ctx, actions)
19129
bd19587a3347 revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents: 19024
diff changeset
  2462
16429
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2463
            if targetsubs:
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2464
                # Revert the subrepos on the revert list
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2465
                for sub in targetsubs:
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2466
                    ctx.sub(sub).revert(ui, ctx.substate[sub], *pats, **opts)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2467
    finally:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2468
        wlock.release()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2469
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2470
def _performrevert(repo, parents, ctx, actions):
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2471
    """function that actually perform all the actions computed for revert
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2472
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2473
    This is an independent function to let extension to plug in and react to
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2474
    the imminent revert.
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2475
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20790
diff changeset
  2476
    Make sure you have the working directory locked when calling this function.
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2477
    """
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2478
    parent, p2 = parents
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2479
    node = ctx.node()
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2480
    def checkout(f):
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2481
        fc = ctx[f]
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2482
        repo.wwrite(f, fc.data(), fc.flags())
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2483
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2484
    audit_path = pathutil.pathauditor(repo.root)
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2485
    for f in actions['remove'][0]:
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2486
        if repo.dirstate[f] == 'a':
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2487
            repo.dirstate.drop(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2488
            continue
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2489
        audit_path(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2490
        try:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2491
            util.unlinkpath(repo.wjoin(f))
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2492
        except OSError:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2493
            pass
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2494
        repo.dirstate.remove(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2495
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2496
    normal = None
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2497
    if node == parent:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2498
        # We're reverting to our parent. If possible, we'd like status
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2499
        # to report the file as clean. We have to use normallookup for
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2500
        # merges to avoid losing information about merged/dirty files.
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2501
        if p2 != nullid:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2502
            normal = repo.dirstate.normallookup
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2503
        else:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2504
            normal = repo.dirstate.normal
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2505
    for f in actions['revert'][0]:
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2506
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2507
        if normal:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2508
            normal(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2509
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2510
    for f in actions['add'][0]:
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2511
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2512
        repo.dirstate.add(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2513
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2514
    normal = repo.dirstate.normallookup
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2515
    if node == parent and p2 == nullid:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2516
        normal = repo.dirstate.normal
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2517
    for f in actions['undelete'][0]:
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2518
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2519
        normal(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2520
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2521
    copied = copies.pathcopies(repo[parent], ctx)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2522
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2523
    for f in actions['add'][0] + actions['undelete'][0] + actions['revert'][0]:
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2524
        if f in copied:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2525
            repo.dirstate.copy(copied[f], f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2526
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2527
def command(table):
21766
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2528
    """Returns a function object to be used as a decorator for making commands.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2529
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2530
    This function receives a command table as its argument. The table should
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2531
    be a dict.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2532
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2533
    The returned function can be used as a decorator for adding commands
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2534
    to that command table. This function accepts multiple arguments to define
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2535
    a command.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2536
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2537
    The first argument is the command name.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2538
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2539
    The options argument is an iterable of tuples defining command arguments.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2540
    See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple.
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2541
21766
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2542
    The synopsis argument defines a short, one line summary of how to use the
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2543
    command. This shows up in the help output.
21767
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2544
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2545
    The norepo argument defines whether the command does not require a
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2546
    local repository. Most commands operate against a repository, thus the
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2547
    default is False.
21774
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2548
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2549
    The optionalrepo argument defines whether the command optionally requires
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2550
    a local repository.
21777
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2551
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2552
    The inferrepo argument defines whether to try to find a repository from the
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2553
    command line arguments. If True, arguments will be examined for potential
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2554
    repository locations. See ``findrepo()``. If a repository is found, it
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2555
    will be used.
21766
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2556
    """
21777
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2557
    def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False,
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2558
            inferrepo=False):
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2559
        def decorator(func):
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2560
            if synopsis:
18235
9807e7d596c3 cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18206
diff changeset
  2561
                table[name] = func, list(options), synopsis
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2562
            else:
18235
9807e7d596c3 cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18206
diff changeset
  2563
                table[name] = func, list(options)
21767
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2564
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2565
            if norepo:
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2566
                # Avoid import cycle.
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2567
                import commands
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2568
                commands.norepo += ' %s' % ' '.join(parsealiases(name))
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2569
21774
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2570
            if optionalrepo:
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2571
                import commands
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2572
                commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2573
21777
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2574
            if inferrepo:
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2575
                import commands
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2576
                commands.inferrepo += ' %s' % ' '.join(parsealiases(name))
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2577
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2578
            return func
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2579
        return decorator
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2580
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2581
    return cmd
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  2582
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2583
# a list of (ui, repo, otherpeer, opts, missing) functions called by
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2584
# commands.outgoing.  "missing" is "missing" of the result of
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2585
# "findcommonoutgoing()"
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2586
outgoinghooks = util.hooks()
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2587
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  2588
# a list of (ui, repo) functions called by commands.summary
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  2589
summaryhooks = util.hooks()
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2590
21047
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2591
# a list of (ui, repo, opts, changes) functions called by commands.summary.
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2592
#
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2593
# functions should return tuple of booleans below, if 'changes' is None:
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2594
#  (whether-incomings-are-needed, whether-outgoings-are-needed)
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2595
#
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2596
# otherwise, 'changes' is a tuple of tuples below:
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2597
#  - (sourceurl, sourcebranch, sourcepeer, incoming)
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2598
#  - (desturl,   destbranch,   destpeer,   outgoing)
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2599
summaryremotehooks = util.hooks()
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2600
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2601
# A list of state files kept by multistep operations like graft.
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2602
# Since graft cannot be aborted, it is considered 'clearable' by update.
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2603
# note: bisect is intentionally excluded
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2604
# (state file, clearable, allowcommit, error, hint)
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2605
unfinishedstates = [
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2606
    ('graftstate', True, False, _('graft in progress'),
19482
499fc471296b update: add tracking of interrupted updates (issue3113)
Matt Mackall <mpm@selenic.com>
parents: 19474
diff changeset
  2607
     _("use 'hg graft --continue' or 'hg update' to abort")),
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2608
    ('updatestate', True, False, _('last update was interrupted'),
19482
499fc471296b update: add tracking of interrupted updates (issue3113)
Matt Mackall <mpm@selenic.com>
parents: 19474
diff changeset
  2609
     _("use 'hg update' to get a consistent checkout"))
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2610
    ]
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2611
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2612
def checkunfinished(repo, commit=False):
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2613
    '''Look for an unfinished multistep operation, like graft, and abort
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2614
    if found. It's probably good to check this right before
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2615
    bailifchanged().
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2616
    '''
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2617
    for f, clearable, allowcommit, msg, hint in unfinishedstates:
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2618
        if commit and allowcommit:
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2619
            continue
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2620
        if repo.vfs.exists(f):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2621
            raise util.Abort(msg, hint=hint)
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2622
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2623
def clearunfinished(repo):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2624
    '''Check for unfinished operations (as above), and clear the ones
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2625
    that are clearable.
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2626
    '''
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2627
    for f, clearable, allowcommit, msg, hint in unfinishedstates:
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2628
        if not clearable and repo.vfs.exists(f):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2629
            raise util.Abort(msg, hint=hint)
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2630
    for f, clearable, allowcommit, msg, hint in unfinishedstates:
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2631
        if clearable and repo.vfs.exists(f):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2632
            util.unlink(repo.join(f))