mercurial/cmdutil.py
author Yuya Nishihara <yuya@tcha.org>
Fri, 06 Feb 2015 00:15:35 +0900
changeset 24062 f576addb5b77
parent 24061 4fa72a09c73d
child 24063 c98fa0ca4678
permissions -rw-r--r--
log: extract common part from getgraphlogrevs() and getlogrevs()
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
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
    16
import encoding
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
    17
import lock as lockmod
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    18
10401
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    19
def parsealiases(cmd):
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    20
    return cmd.lstrip("^").split("|")
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
    21
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    22
def findpossible(cmd, table, strict=False):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    23
    """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    24
    Return cmd -> (aliases, command table entry)
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    25
    for each matching command.
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    26
    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
    27
    """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    28
    choice = {}
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    29
    debugchoice = {}
15600
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    30
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    31
    if cmd in table:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    32
        # 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
    33
        keys = [cmd]
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    34
    else:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    35
        keys = table.keys()
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    36
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
    37
    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
    38
        aliases = parsealiases(e)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    39
        found = None
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    40
        if cmd in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    41
            found = cmd
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    42
        elif not strict:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    43
            for a in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    44
                if a.startswith(cmd):
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    45
                    found = a
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    46
                    break
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    47
        if found is not None:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    48
            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
    49
                debugchoice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    50
            else:
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5177
diff changeset
    51
                choice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    52
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    53
    if not choice and debugchoice:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    54
        choice = debugchoice
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    55
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    56
    return choice
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    57
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
    58
def findcmd(cmd, table, strict=True):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    59
    """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
    60
    choice = findpossible(cmd, table, strict)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    61
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5843
diff changeset
    62
    if cmd in choice:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    63
        return choice[cmd]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    64
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    65
    if len(choice) > 1:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    66
        clist = choice.keys()
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    67
        clist.sort()
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7404
diff changeset
    68
        raise error.AmbiguousCommand(cmd, clist)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    69
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    70
    if choice:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    71
        return choice.values()[0]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    72
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7404
diff changeset
    73
    raise error.UnknownCommand(cmd)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    74
10402
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    75
def findrepo(p):
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    76
    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
    77
        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
    78
        if p == oldp:
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    79
            return None
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    80
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    81
    return p
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
    82
14289
d68ddccf276b cmdutil: bail_if_changed to bailifchanged
Matt Mackall <mpm@selenic.com>
parents: 14269
diff changeset
    83
def bailifchanged(repo):
13878
a8d13ee0ce68 misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents: 13769
diff changeset
    84
    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
    85
        raise util.Abort(_('outstanding uncommitted merge'))
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    86
    modified, added, removed, deleted = repo.status()[:4]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    87
    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
    88
        raise util.Abort(_('uncommitted changes'))
15231
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
    89
    ctx = repo[None]
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
    90
    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
    91
        if ctx.sub(s).dirty():
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
    92
            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
    93
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
    94
def logmessage(ui, opts):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    95
    """ 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
    96
    message = opts.get('message')
bd5c37d792e6 cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7643
diff changeset
    97
    logfile = opts.get('logfile')
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    98
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
    99
    if message and logfile:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   100
        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
   101
                           'exclusive'))
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   102
    if not message and logfile:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   103
        try:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   104
            if logfile == '-':
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
   105
                message = ui.fin.read()
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   106
            else:
14249
f4766e1bb0b3 cmdutil: normalize log message eols when reading from file
Patrick Mezard <pmezard@gmail.com>
parents: 14232
diff changeset
   107
                message = '\n'.join(util.readfile(logfile).splitlines())
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   108
        except IOError, inst:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   109
            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
   110
                             (logfile, inst.strerror))
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   111
    return message
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   112
22248
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   113
def mergeeditform(ctxorbool, baseform):
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   114
    """build appropriate editform from ctxorbool and baseform
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   115
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23101
diff changeset
   116
    'ctxorbool' is one of a ctx to be committed, or a bool whether
22248
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   117
    merging is committed.
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   118
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   119
    This returns editform 'baseform' with '.merge' if merging is
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   120
    committed, or one with '.normal' suffix otherwise.
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   121
    """
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   122
    if isinstance(ctxorbool, bool):
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   123
        if ctxorbool:
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   124
            return baseform + ".merge"
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   125
    elif 1 < len(ctxorbool.parents()):
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   126
        return baseform + ".merge"
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   127
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   128
    return baseform + ".normal"
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   129
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   130
def getcommiteditor(edit=False, finishdesc=None, extramsg=None,
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   131
                    editform='', **opts):
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   132
    """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
   133
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   134
    '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
   135
    (= '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
   136
    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
   137
    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
   138
    storing.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   139
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   140
    '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
   141
    '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
   142
    is automatically added.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   143
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   144
    'editform' is a dot-separated list of names, to distinguish
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   145
    the purpose of commit text editing.
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   146
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   147
    '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
   148
    '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
   149
    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
   150
    """
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   151
    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
   152
        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
   153
                                                 finishdesc=finishdesc,
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   154
                                                 extramsg=extramsg,
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   155
                                                 editform=editform)
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   156
    elif editform:
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   157
        return lambda r, c, s: commiteditor(r, c, s, editform=editform)
21405
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   158
    else:
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   159
        return commiteditor
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   160
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   161
def loglimit(opts):
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   162
    """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
   163
    limit = opts.get('limit')
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   164
    if limit:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   165
        try:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   166
            limit = int(limit)
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   167
        except ValueError:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   168
            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
   169
        if limit <= 0:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   170
            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
   171
    else:
10111
27457d31ae3f cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10061
diff changeset
   172
        limit = None
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   173
    return limit
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   174
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   175
def makefilename(repo, pat, node, desc=None,
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   176
                  total=None, seqno=None, revwidth=None, pathname=None):
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   177
    node_expander = {
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   178
        'H': lambda: hex(node),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   179
        'R': lambda: str(repo.changelog.rev(node)),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   180
        '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
   181
        'm': lambda: re.sub('[^\w]', '_', str(desc))
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   182
        }
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   183
    expander = {
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   184
        '%': lambda: '%',
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   185
        'b': lambda: os.path.basename(repo.root),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   186
        }
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   187
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   188
    try:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   189
        if node:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   190
            expander.update(node_expander)
4836
0e2d0a78f81a archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4825
diff changeset
   191
        if node:
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   192
            expander['r'] = (lambda:
4836
0e2d0a78f81a archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4825
diff changeset
   193
                    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
   194
        if total is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   195
            expander['N'] = lambda: str(total)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   196
        if seqno is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   197
            expander['n'] = lambda: str(seqno)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   198
        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
   199
            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
   200
        if pathname is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   201
            expander['s'] = lambda: os.path.basename(pathname)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   202
            expander['d'] = lambda: os.path.dirname(pathname) or '.'
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   203
            expander['p'] = lambda: pathname
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   204
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   205
        newname = []
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   206
        patlen = len(pat)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   207
        i = 0
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   208
        while i < patlen:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   209
            c = pat[i]
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   210
            if c == '%':
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   211
                i += 1
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   212
                c = pat[i]
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   213
                c = expander[c]()
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   214
            newname.append(c)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   215
            i += 1
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   216
        return ''.join(newname)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   217
    except KeyError, inst:
8761
0289f384e1e5 Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents: 8731
diff changeset
   218
        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
   219
                         inst.args[0])
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   220
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   221
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
   222
                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
   223
                pathname=None):
7319
eae1767cc6a8 export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7308
diff changeset
   224
13769
8796fb6af67e cmdutil: fix mode handling in make_file
Adrian Buehlmann <adrian@cadifra.com>
parents: 13534
diff changeset
   225
    writable = mode not in ('r', 'rb')
7319
eae1767cc6a8 export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7308
diff changeset
   226
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   227
    if not pat or pat == '-':
14637
5e9d691229d5 cmdutil: use ui descriptors in makefileobj
Idan Kamara <idankk86@gmail.com>
parents: 14635
diff changeset
   228
        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
   229
        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
   230
            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
   231
        else:
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   232
            # 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
   233
            # 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
   234
            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
   235
                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
   236
                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
   237
                    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
   238
                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
   239
                    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
   240
                        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
   241
                    else:
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   242
                        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
   243
1bdbca0b6604 cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents: 14637
diff changeset
   244
            return wrappedfileobj(fp)
14948
32302480b402 cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14671
diff changeset
   245
    if util.safehasattr(pat, 'write') and writable:
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   246
        return pat
14948
32302480b402 cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14671
diff changeset
   247
    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
   248
        return pat
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   249
    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
   250
    if modemap is not None:
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   251
        mode = modemap.get(fn, mode)
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   252
        if mode == 'wb':
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   253
            modemap[fn] = 'ab'
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   254
    return open(fn, mode)
2882
cf98cd70d2c4 move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2874
diff changeset
   255
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   256
def openrevlog(repo, cmd, file_, opts):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   257
    """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
   258
    cl = opts['changelog']
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   259
    mf = opts['manifest']
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   260
    msg = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   261
    if cl and mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   262
        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
   263
    elif cl or mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   264
        if file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   265
            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
   266
        elif not repo:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   267
            msg = _('cannot specify --changelog or --manifest '
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   268
                    'without a repository')
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   269
    if msg:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   270
        raise util.Abort(msg)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   271
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   272
    r = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   273
    if repo:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   274
        if cl:
21033
254f55b64e31 debugrevlog: use unfiltered view for changelog
Matt Mackall <mpm@selenic.com>
parents: 21024
diff changeset
   275
            r = repo.unfiltered().changelog
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   276
        elif mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   277
            r = repo.manifest
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   278
        elif file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   279
            filelog = repo.file(file_)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   280
            if len(filelog):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   281
                r = filelog
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   282
    if not r:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   283
        if not file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   284
            raise error.CommandError(cmd, _('invalid arguments'))
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   285
        if not os.path.isfile(file_):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   286
            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
   287
        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
   288
                          file_[:-2] + ".i")
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   289
    return r
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   290
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
   291
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
   292
    # called with the repo lock held
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   293
    #
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   294
    # hgsep => pathname that uses "/" to separate directories
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   295
    # 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
   296
    cwd = repo.getcwd()
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   297
    targets = {}
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   298
    after = opts.get("after")
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   299
    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
   300
    wctx = repo[None]
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   301
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   302
    def walkpat(pat):
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   303
        srcs = []
11223
0d09f2244805 rename: make --after work if source is already in R state
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 11177
diff changeset
   304
        badstates = after and '?' or '?r'
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14638
diff changeset
   305
        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
   306
        for abs in repo.walk(m):
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   307
            state = repo.dirstate[abs]
6584
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
   308
            rel = m.rel(abs)
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
   309
            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
   310
            if state in badstates:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   311
                if exact and state == '?':
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   312
                    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
   313
                if exact and state == 'r':
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   314
                    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
   315
                              ' remove\n') % rel)
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   316
                continue
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   317
            # abs: hgsep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   318
            # rel: ossep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   319
            srcs.append((abs, rel, exact))
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   320
        return srcs
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   321
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   322
    # abssrc: hgsep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   323
    # relsrc: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   324
    # otarget: ossep
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   325
    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
   326
        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
   327
        if '/' in abstarget:
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   328
            # 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
   329
            # case only renames, like a => A.
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   330
            abspath, absname = abstarget.rsplit('/', 1)
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   331
            abstarget = repo.dirstate.normalize(abspath) + '/' + absname
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   332
        reltarget = repo.pathto(abstarget, cwd)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   333
        target = repo.wjoin(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   334
        src = repo.wjoin(abssrc)
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   335
        state = repo.dirstate[abstarget]
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   336
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13945
diff changeset
   337
        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
   338
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   339
        # check for collisions
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   340
        prevsrc = targets.get(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   341
        if prevsrc is not None:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   342
            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
   343
                    (reltarget, repo.pathto(abssrc, cwd),
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   344
                     repo.pathto(prevsrc, cwd)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   345
            return
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   346
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   347
        # check for overwrites
12342
70236d6fd844 rename: do not overwrite existing broken symlinks
Patrick Mezard <pmezard@gmail.com>
parents: 11950
diff changeset
   348
        exists = os.path.lexists(target)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   349
        samefile = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   350
        if exists and abssrc != abstarget:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   351
            if (repo.dirstate.normalize(abssrc) ==
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   352
                repo.dirstate.normalize(abstarget)):
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   353
                if not rename:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   354
                    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
   355
                    return
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   356
                exists = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   357
                samefile = True
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   358
8117
2b30d8488819 remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents: 8013
diff changeset
   359
        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
   360
            if not opts['force']:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   361
                ui.warn(_('%s: not overwriting - file exists\n') %
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   362
                        reltarget)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   363
                return
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   364
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   365
        if after:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   366
            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
   367
                if rename:
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   368
                    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
   369
                            (relsrc, reltarget))
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   370
                else:
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   371
                    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
   372
                            (relsrc, reltarget))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   373
                return
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   374
        elif not dryrun:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   375
            try:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   376
                if exists:
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   377
                    os.unlink(target)
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   378
                targetdir = os.path.dirname(target) or '.'
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   379
                if not os.path.isdir(targetdir):
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   380
                    os.makedirs(targetdir)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   381
                if samefile:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   382
                    tmp = target + "~hgrename"
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   383
                    os.rename(src, tmp)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   384
                    os.rename(tmp, target)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   385
                else:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   386
                    util.copyfile(src, target)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   387
                srcexists = True
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   388
            except IOError, inst:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   389
                if inst.errno == errno.ENOENT:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   390
                    ui.warn(_('%s: deleted in working copy\n') % relsrc)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   391
                    srcexists = False
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   392
                else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   393
                    ui.warn(_('%s: cannot copy - %s\n') %
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   394
                            (relsrc, inst.strerror))
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   395
                    return True # report a failure
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   396
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   397
        if ui.verbose or not exact:
7894
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   398
            if rename:
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   399
                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
   400
            else:
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   401
                ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   402
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   403
        targets[abstarget] = abssrc
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   404
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   405
        # fix up dirstate
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   406
        scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   407
                             dryrun=dryrun, cwd=cwd)
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
   408
        if rename and not dryrun:
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   409
            if not after and srcexists and not samefile:
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   410
                util.unlinkpath(repo.wjoin(abssrc))
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   411
            wctx.forget([abssrc])
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   412
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   413
    # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   414
    # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   415
    # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   416
    # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   417
    def targetpathfn(pat, dest, srcs):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   418
        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
   419
            abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   420
            abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   421
            if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   422
                striplen = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   423
            else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   424
                striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   425
            if striplen:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   426
                striplen += len(os.sep)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   427
            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
   428
        elif destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   429
            res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   430
                                         os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   431
        else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   432
            res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   433
        return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   434
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   435
    # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   436
    # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   437
    # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   438
    # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   439
    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
   440
        if matchmod.patkind(pat):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   441
            # a mercurial pattern
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   442
            res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   443
                                         os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   444
        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
   445
            abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   446
            if len(abspfx) < len(srcs[0][0]):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   447
                # 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
   448
                # 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
   449
                def evalpath(striplen):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   450
                    score = 0
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   451
                    for s in srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   452
                        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
   453
                        if os.path.lexists(t):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   454
                            score += 1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   455
                    return score
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   456
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   457
                abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   458
                striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   459
                if striplen:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   460
                    striplen += len(os.sep)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   461
                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
   462
                    score = evalpath(striplen)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   463
                    striplen1 = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   464
                    if striplen1:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   465
                        striplen1 += len(os.sep)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   466
                    if evalpath(striplen1) > score:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   467
                        striplen = striplen1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   468
                res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   469
                                             util.localpath(p)[striplen:])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   470
            else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   471
                # a file
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   472
                if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   473
                    res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   474
                                        os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   475
                else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   476
                    res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   477
        return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   478
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   479
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   480
    pats = scmutil.expandpats(pats)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   481
    if not pats:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   482
        raise util.Abort(_('no source or destination specified'))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   483
    if len(pats) == 1:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   484
        raise util.Abort(_('no destination specified'))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   485
    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
   486
    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
   487
    if not destdirexists:
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 12032
diff changeset
   488
        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
   489
            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
   490
                               '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
   491
        if util.endswithsep(dest):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   492
            raise util.Abort(_('destination %s is not a directory') % dest)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   493
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   494
    tfn = targetpathfn
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   495
    if after:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   496
        tfn = targetpathafterfn
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   497
    copylist = []
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   498
    for pat in pats:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   499
        srcs = walkpat(pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   500
        if not srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   501
            continue
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   502
        copylist.append((tfn(pat, dest, srcs), srcs))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   503
    if not copylist:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   504
        raise util.Abort(_('no files to copy'))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   505
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   506
    errors = 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   507
    for targetpath, srcs in copylist:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   508
        for abssrc, relsrc, exact in srcs:
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   509
            if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   510
                errors += 1
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   511
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   512
    if errors:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   513
        ui.warn(_('(consider using --after)\n'))
5609
a783d3627144 copy: move rename logic
Matt Mackall <mpm@selenic.com>
parents: 5608
diff changeset
   514
11177
6a64813276ed commands: initial audit of exit codes
Matt Mackall <mpm@selenic.com>
parents: 11152
diff changeset
   515
    return errors != 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   516
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
   517
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
   518
    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
   519
    '''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
   520
19867
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   521
    def writepid(pid):
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   522
        if opts['pid_file']:
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   523
            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
   524
            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
   525
            fp.write(str(pid) + '\n')
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   526
            fp.close()
edce20ebe1f3 cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents: 19804
diff changeset
   527
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   528
    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
   529
        # 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
   530
        lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   531
        os.close(lockfd)
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   532
        try:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   533
            if not runargs:
10239
8e4be44a676f Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents: 10238
diff changeset
   534
                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
   535
            runargs.append('--daemon-pipefds=%s' % lockpath)
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   536
            # 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
   537
            # changed directory.
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   538
            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
   539
                if runargs[i].startswith('--cwd='):
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   540
                    del runargs[i]
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   541
                    break
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   542
                elif runargs[i].startswith('--cwd'):
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   543
                    del runargs[i:i + 2]
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   544
                    break
10344
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   545
            def condfn():
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   546
                return not os.path.exists(lockpath)
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   547
            pid = util.rundetached(runargs, condfn)
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   548
            if pid < 0:
9501cde4c034 util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   549
                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
   550
            writepid(pid)
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   551
        finally:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   552
            try:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   553
                os.unlink(lockpath)
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   554
            except OSError, e:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   555
                if e.errno != errno.ENOENT:
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   556
                    raise
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   557
        if parentfn:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   558
            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
   559
        else:
9896
2c2f7593ffc4 cmdutil.service: do not _exit(0) in the parent process
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9668
diff changeset
   560
            return
4380
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   561
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   562
    if initfn:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   563
        initfn()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   564
19868
0532c8f8e911 cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents: 19867
diff changeset
   565
    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
   566
        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
   567
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   568
    if opts['daemon_pipefds']:
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   569
        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
   570
        try:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   571
            os.setsid()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   572
        except AttributeError:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   573
            pass
10238
e22695b4472f cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents: 10237
diff changeset
   574
        os.unlink(lockpath)
10240
3af4b39afe2a cmdutil: hide child window created by win32 spawndetached()
Patrick Mezard <pmezard@gmail.com>
parents: 10239
diff changeset
   575
        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
   576
        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
   577
        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
   578
17391
fc24c10424d2 util: replace util.nulldev with os.devnull
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17308
diff changeset
   579
        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
   580
        logfilefd = nullfd
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   581
        if logfile:
e0ed17984a48 cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   582
            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
   583
        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
   584
        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
   585
        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
   586
        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
   587
            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
   588
        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
   589
            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
   590
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   591
    if runfn:
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   592
        return runfn()
e89f9afc462b Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4355
diff changeset
   593
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   594
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
   595
    """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
   596
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   597
    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
   598
    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
   599
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   600
    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
   601
    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
   602
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   603
    :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
   604
    :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
   605
    :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
   606
    :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
   607
           (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
   608
    :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
   609
                 updatefunc(<repo>, <node>)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   610
    """
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   611
    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
   612
        patch.extract(ui, hunk)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   613
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   614
    update = not opts.get('bypass')
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   615
    strip = opts["strip"]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   616
    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
   617
    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
   618
        return (None, None, False)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   619
    msg = _('applied to working directory')
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   620
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
   621
    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
   622
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   623
    try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   624
        cmdline_message = logmessage(ui, opts)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   625
        if cmdline_message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   626
            # pickup the cmdline msg
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   627
            message = cmdline_message
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   628
        elif message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   629
            # pickup the patch msg
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   630
            message = message.strip()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   631
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   632
            # launch the editor
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   633
            message = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   634
        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
   635
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   636
        if len(parents) == 1:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   637
            parents.append(repo[nullid])
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   638
        if opts.get('exact'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   639
            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
   640
                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
   641
            p1 = repo[p1]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   642
            p2 = repo[p2 or nullid]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   643
        elif p2:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   644
            try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   645
                p1 = repo[p1]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   646
                p2 = repo[p2]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   647
                # 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
   648
                # 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
   649
                # first parent.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   650
                if p1 != parents[0]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   651
                    p1 = parents[0]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   652
                    p2 = repo[nullid]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   653
            except error.RepoError:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   654
                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
   655
            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
   656
                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
   657
                          "(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
   658
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   659
            p1, p2 = parents
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   660
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   661
        n = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   662
        if update:
22405
6f63c47cbb86 dirstate: wrap setparent calls with begin/endparentchange (issue4353)
Durham Goode <durham@fb.com>
parents: 22398
diff changeset
   663
            repo.dirstate.beginparentchange()
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   664
            if p1 != parents[0]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   665
                updatefunc(repo, p1.node())
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   666
            if p2 != parents[1]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   667
                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
   668
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   669
            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
   670
                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
   671
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
            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
   673
            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
   674
            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
   675
                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
   676
                            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
   677
            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
   678
                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
   679
                    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
   680
                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
   681
                    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
   682
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   683
            files = list(files)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   684
            if opts.get('no_commit'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   685
                if message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   686
                    msgs.append(message)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   687
            else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   688
                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
   689
                    # 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
   690
                    # 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
   691
                    # 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
   692
                    m = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   693
                else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   694
                    m = scmutil.matchfiles(repo, files or [])
22250
f3200bf460a8 import: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22249
diff changeset
   695
                editform = mergeeditform(repo[None], 'import.normal')
22278
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   696
                if opts.get('exact'):
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   697
                    editor = None
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   698
                else:
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   699
                    editor = getcommiteditor(editform=editform, **opts)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   700
                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
   701
                                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
   702
                                editor=editor, force=partial)
22405
6f63c47cbb86 dirstate: wrap setparent calls with begin/endparentchange (issue4353)
Durham Goode <durham@fb.com>
parents: 22398
diff changeset
   703
            repo.dirstate.endparentchange()
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   704
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   705
            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
   706
                branch = branch or 'default'
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   707
            else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   708
                branch = p1.branch()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   709
            store = patch.filestore()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   710
            try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   711
                files = set()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   712
                try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   713
                    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
   714
                                    files, eolmode=None)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   715
                except patch.PatchError, e:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   716
                    raise util.Abort(str(e))
22278
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   717
                if opts.get('exact'):
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   718
                    editor = None
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   719
                else:
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
   720
                    editor = getcommiteditor(editform='import.bypass')
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   721
                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
   722
                                            message,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   723
                                            opts.get('user') or user,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   724
                                            opts.get('date') or date,
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   725
                                            branch, files, store,
22011
97acb4504704 import: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22010
diff changeset
   726
                                            editor=editor)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   727
                n = memctx.commit()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   728
            finally:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   729
                store.close()
22485
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
   730
        if opts.get('exact') and opts.get('no_commit'):
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
   731
            # --exact with --no-commit is still useful in that it does merge
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
   732
            # and branch bits
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
   733
            ui.warn(_("warning: can't check exact import with --no-commit\n"))
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
   734
        elif opts.get('exact') and hex(n) != nodeid:
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   735
            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
   736
        if n:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   737
            # 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
   738
            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
   739
        return (msg, n, rejects)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   740
    finally:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   741
        os.unlink(tmpname)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   742
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   743
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
   744
           opts=None):
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   745
    '''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
   746
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   747
    total = len(revs)
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   748
    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
   749
    filemode = {}
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   750
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   751
    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
   752
        ctx = repo[rev]
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   753
        node = ctx.node()
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   754
        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
   755
        branch = ctx.branch()
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   756
        if switch_parent:
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   757
            parents.reverse()
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   758
        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
   759
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13386
diff changeset
   760
        shouldclose = False
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   761
        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
   762
            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
   763
            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
   764
            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
   765
                             seqno=seqno, revwidth=revwidth, mode='wb',
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   766
                             modemap=filemode)
13467
31aa2e5b0750 export: only close files which export itself has opened
Waqas Hussain <waqas20@gmail.com>
parents: 13400
diff changeset
   767
            if fp != template:
31aa2e5b0750 export: only close files which export itself has opened
Waqas Hussain <waqas20@gmail.com>
parents: 13400
diff changeset
   768
                shouldclose = True
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   769
        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
   770
            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
   771
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   772
        if not fp:
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   773
            write = repo.ui.write
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   774
        else:
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   775
            def write(s, **kw):
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   776
                fp.write(s)
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   777
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   778
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   779
        write("# HG changeset patch\n")
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   780
        write("# User %s\n" % ctx.user())
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   781
        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
   782
        write("#      %s\n" % util.datestr(ctx.date()))
11821
15aa42aaae4c cmdutil: remove unnecessary parenthesis
Martin Geisler <mg@aragost.com>
parents: 11635
diff changeset
   783
        if branch and branch != 'default':
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   784
            write("# Branch %s\n" % branch)
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   785
        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
   786
        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
   787
        if len(parents) > 1:
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   788
            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
   789
        write(ctx.description().rstrip())
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   790
        write("\n\n")
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   791
17460
a306837f8c87 color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents: 17424
diff changeset
   792
        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
   793
            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
   794
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13386
diff changeset
   795
        if shouldclose:
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13386
diff changeset
   796
            fp.close()
13081
79184986658c export: flush the file pointer between patches
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13047
diff changeset
   797
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
   798
    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
   799
        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
   800
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   801
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
   802
                   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
   803
                   listsubrepos=False):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   804
    '''show diff or diffstat.'''
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   805
    if fp is None:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   806
        write = ui.write
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   807
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   808
        def write(s, **kw):
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   809
            fp.write(s)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   810
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   811
    if stat:
11950
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
   812
        diffopts = diffopts.copy(context=0)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   813
        width = 80
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   814
        if not ui.plain():
12689
c52c629ce19e termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents: 12619
diff changeset
   815
            width = ui.termwidth()
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   816
        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
   817
                            prefix=prefix)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   818
        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
   819
                                             width=width,
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   820
                                             git=diffopts.git):
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   821
            write(chunk, label=label)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   822
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   823
        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
   824
                                         changes, diffopts, prefix=prefix):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   825
            write(chunk, label=label)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
   826
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   827
    if listsubrepos:
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   828
        ctx1 = repo[node1]
12175
c0a8f9dea0f6 subrepos: handle modified but uncommitted .hgsub
Martin Geisler <mg@lazybytes.net>
parents: 12167
diff changeset
   829
        ctx2 = repo[node2]
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
   830
        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
   831
            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
   832
            try:
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
   833
                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
   834
                    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
   835
            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
   836
                # 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
   837
                # 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
   838
                # 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
   839
                tempnode2 = None
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   840
            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
   841
            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
   842
                     stat=stat, fp=fp, prefix=prefix)
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
   843
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   844
class changeset_printer(object):
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   845
    '''show changeset information when templating not requested.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   846
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
   847
    def __init__(self, ui, repo, matchfn, diffopts, buffered):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   848
        self.ui = ui
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   849
        self.repo = repo
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   850
        self.buffered = buffered
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
   851
        self.matchfn = matchfn
7762
fece056bf240 add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents: 7667
diff changeset
   852
        self.diffopts = diffopts
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   853
        self.header = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   854
        self.hunk = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   855
        self.lastheader = None
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   856
        self.footer = None
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   857
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   858
    def flush(self, rev):
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   859
        if rev in self.header:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   860
            h = self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   861
            if h != self.lastheader:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   862
                self.lastheader = h
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   863
                self.ui.write(h)
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   864
            del self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   865
        if rev in self.hunk:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   866
            self.ui.write(self.hunk[rev])
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   867
            del self.hunk[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   868
            return 1
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   869
        return 0
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   870
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   871
    def close(self):
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   872
        if self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   873
            self.ui.write(self.footer)
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
   874
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   875
    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
   876
        if self.buffered:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   877
            self.ui.pushbuffer()
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   878
            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
   879
            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
   880
        else:
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   881
            self._show(ctx, copies, matchfn, props)
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
   882
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   883
    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
   884
        '''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
   885
        changenode = ctx.node()
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   886
        rev = ctx.rev()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   887
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   888
        if self.ui.quiet:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   889
            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
   890
                          label='log.node')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   891
            return
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   892
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   893
        log = self.repo.changelog
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   894
        date = util.datestr(ctx.date())
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   895
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   896
        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
   897
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
   898
        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
   899
                   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
   900
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   901
        # 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
   902
        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
   903
                      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
   904
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   905
        # branches are shown first before any other names due to backwards
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   906
        # compatibility
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   907
        branch = ctx.branch()
4176
f9bbcebcacea "default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4055
diff changeset
   908
        # 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
   909
        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
   910
            # 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
   911
            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
   912
                          label='log.branch')
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   913
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   914
        for name, ns in self.repo.names.iteritems():
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   915
            # branches has special logic already handled above, so here we just
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   916
            # skip it
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   917
            if name == 'branches':
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   918
                continue
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   919
            # we will use the templatename as the color name since those two
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   920
            # should be the same
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
   921
            for name in ns.names(self.repo, changenode):
23967
448bb32b8ee6 namespace: introduce logfmt to show l10n-ed messages for hg log correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23965
diff changeset
   922
                self.ui.write(ns.logfmt % name,
448bb32b8ee6 namespace: introduce logfmt to show l10n-ed messages for hg log correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23965
diff changeset
   923
                              label='log.%s' % ns.colorname)
22765
55dcc7fb731c log: do not hide the public phase in debug mode (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22764
diff changeset
   924
        if self.ui.debugflag:
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   925
            # 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
   926
            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
   927
                          label='log.phase')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   928
        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
   929
            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
   930
            # 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
   931
            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
   932
                          label=label)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   933
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   934
        if self.ui.debugflag:
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   935
            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
   936
            # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   937
            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
   938
                          (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
   939
                          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
   940
        # 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
   941
        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
   942
                      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
   943
        # 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
   944
        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
   945
                      label='log.date')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   946
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   947
        if self.ui.debugflag:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   948
            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
   949
            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
   950
                                   _("files:"),
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   951
                                   # 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
   952
                                   _("files+:"),
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
   953
                                   # 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
   954
                                   _("files-:")], files):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   955
                if value:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   956
                    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
   957
                                  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
   958
        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
   959
            # 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
   960
            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
   961
                          label='ui.note log.files')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   962
        if copies and self.ui.verbose:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   963
            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
   964
            # 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
   965
            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
   966
                          label='ui.note log.copies')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   967
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
   968
        extra = ctx.extra()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   969
        if extra and self.ui.debugflag:
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
   970
            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
   971
                # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   972
                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
   973
                              % (key, value.encode('string_escape')),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   974
                              label='ui.debug log.extra')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   975
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
   976
        description = ctx.description().strip()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   977
        if description:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   978
            if self.ui.verbose:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   979
                self.ui.write(_("description:\n"),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   980
                              label='ui.note log.description')
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   981
                self.ui.write(description,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   982
                              label='ui.note log.description')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   983
                self.ui.write("\n\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   984
            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
   985
                # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   986
                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
   987
                              description.splitlines()[0],
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
   988
                              label='log.summary')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   989
        self.ui.write("\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
   990
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   991
        self.showpatch(changenode, matchfn)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   992
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   993
    def showpatch(self, node, matchfn):
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   994
        if not matchfn:
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
   995
            matchfn = self.matchfn
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
   996
        if matchfn:
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
   997
            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
   998
            diff = self.diffopts.get('patch')
23691
e41bcb019633 cmdutil.changeset_printer: explicitly honor all diffopts
Siddharth Agarwal <sid0@fb.com>
parents: 23686
diff changeset
   999
            diffopts = patch.diffallopts(self.ui, self.diffopts)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1000
            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
  1001
            if stat:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1002
                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
  1003
                               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
  1004
            if diff:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1005
                if stat:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1006
                    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
  1007
                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
  1008
                               match=matchfn, stat=False)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1009
            self.ui.write("\n")
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1010
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
  1011
    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
  1012
        """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
  1013
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
  1014
        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
  1015
        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
  1016
        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
  1017
        """
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
  1018
        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
  1019
        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
  1020
            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
  1021
                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
  1022
            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
  1023
                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
  1024
        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
  1025
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1026
class jsonchangeset(changeset_printer):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1027
    '''format changeset information.'''
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1028
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1029
    def __init__(self, ui, repo, matchfn, diffopts, buffered):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1030
        changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1031
        self.cache = {}
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1032
        self._first = True
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1033
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1034
    def close(self):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1035
        if not self._first:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1036
            self.ui.write("\n]\n")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1037
        else:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1038
            self.ui.write("[]\n")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1039
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1040
    def _show(self, ctx, copies, matchfn, props):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1041
        '''show a single changeset or file revision'''
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1042
        hexnode = hex(ctx.node())
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1043
        rev = ctx.rev()
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1044
        j = encoding.jsonescape
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1045
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1046
        if self._first:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1047
            self.ui.write("[\n {")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1048
            self._first = False
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1049
        else:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1050
            self.ui.write(",\n {")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1051
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1052
        if self.ui.quiet:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1053
            self.ui.write('\n  "rev": %d' % rev)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1054
            self.ui.write(',\n  "node": "%s"' % hexnode)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1055
            self.ui.write('\n }')
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1056
            return
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1057
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1058
        self.ui.write('\n  "rev": %d' % rev)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1059
        self.ui.write(',\n  "node": "%s"' % hexnode)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1060
        self.ui.write(',\n  "branch": "%s"' % j(ctx.branch()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1061
        self.ui.write(',\n  "phase": "%s"' % ctx.phasestr())
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1062
        self.ui.write(',\n  "user": "%s"' % j(ctx.user()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1063
        self.ui.write(',\n  "date": [%d, %d]' % ctx.date())
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1064
        self.ui.write(',\n  "desc": "%s"' % j(ctx.description()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1065
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1066
        self.ui.write(',\n  "bookmarks": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1067
                      ", ".join('"%s"' % j(b) for b in ctx.bookmarks()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1068
        self.ui.write(',\n  "tags": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1069
                      ", ".join('"%s"' % j(t) for t in ctx.tags()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1070
        self.ui.write(',\n  "parents": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1071
                      ", ".join('"%s"' % c.hex() for c in ctx.parents()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1072
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1073
        if self.ui.debugflag:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1074
            self.ui.write(',\n  "manifest": "%s"' % hex(ctx.manifestnode()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1075
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1076
            self.ui.write(',\n  "extra": {%s}' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1077
                          ", ".join('"%s": "%s"' % (j(k), j(v))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1078
                                    for k, v in ctx.extra().items()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1079
23734
f4e6475950f1 cmdutil.jsonchangeset: properly compute added and removed files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23501
diff changeset
  1080
            files = ctx.p1().status(ctx)
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1081
            self.ui.write(',\n  "modified": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1082
                          ", ".join('"%s"' % j(f) for f in files[0]))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1083
            self.ui.write(',\n  "added": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1084
                          ", ".join('"%s"' % j(f) for f in files[1]))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1085
            self.ui.write(',\n  "removed": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1086
                          ", ".join('"%s"' % j(f) for f in files[2]))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1087
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1088
        elif self.ui.verbose:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1089
            self.ui.write(',\n  "files": [%s]' %
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1090
                          ", ".join('"%s"' % j(f) for f in ctx.files()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1091
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1092
            if copies:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1093
                self.ui.write(',\n  "copies": {%s}' %
24013
942a5a34b2d0 log: fix json-formatted output when file copies are listed (issue4523)
Augie Fackler <augie@google.com>
parents: 23967
diff changeset
  1094
                              ", ".join('"%s": "%s"' % (j(k), j(v))
942a5a34b2d0 log: fix json-formatted output when file copies are listed (issue4523)
Augie Fackler <augie@google.com>
parents: 23967
diff changeset
  1095
                                                        for k, v in copies))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1096
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1097
        matchfn = self.matchfn
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1098
        if matchfn:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1099
            stat = self.diffopts.get('stat')
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1100
            diff = self.diffopts.get('patch')
23453
341e4798c24d jsonchangeset: don't honor whitespace and format-changing diffopts
Siddharth Agarwal <sid0@fb.com>
parents: 23404
diff changeset
  1101
            diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1102
            node, prev = ctx.node(), ctx.p1().node()
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1103
            if stat:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1104
                self.ui.pushbuffer()
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1105
                diffordiffstat(self.ui, self.repo, diffopts, prev, node,
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1106
                               match=matchfn, stat=True)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1107
                self.ui.write(',\n  "diffstat": "%s"' % j(self.ui.popbuffer()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1108
            if diff:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1109
                self.ui.pushbuffer()
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1110
                diffordiffstat(self.ui, self.repo, diffopts, prev, node,
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1111
                               match=matchfn, stat=False)
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1112
                self.ui.write(',\n  "diff": "%s"' % j(self.ui.popbuffer()))
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1113
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1114
        self.ui.write("\n }")
4825
3cf94964c56b hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4824
diff changeset
  1115
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1116
class changeset_templater(changeset_printer):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1117
    '''format changeset information.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1118
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1119
    def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered):
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1120
        changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
8360
acc202b71619 templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8312
diff changeset
  1121
        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
  1122
        defaulttempl = {
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1123
            'parent': '{rev}:{node|formatnode} ',
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1124
            'manifest': '{rev}:{node|formatnode}',
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1125
            'file_copy': '{name} ({source})',
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1126
            'extra': '{key}={value|stringescape}'
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1127
            }
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1128
        # filecopy is preserved for compatibility reasons
9e2ab10728a2 Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
  1129
        defaulttempl['filecopy'] = defaulttempl['file_copy']
8360
acc202b71619 templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8312
diff changeset
  1130
        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
  1131
                                     cache=defaulttempl)
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1132
        if tmpl:
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1133
            self.t.cache['changeset'] = tmpl
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1134
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1135
        self.cache = {}
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1136
7878
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1137
    def _meaningful_parentrevs(self, ctx):
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1138
        """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
  1139
        """
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1140
        parents = ctx.parents()
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1141
        if len(parents) > 1:
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1142
            return parents
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1143
        if self.ui.debugflag:
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1144
            return [parents[0], self.repo['null']]
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1145
        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
  1146
            return []
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1147
        return parents
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1148
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1149
    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
  1150
        '''show a single changeset or file revision'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1151
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents: 10026
diff changeset
  1152
        showlist = templatekw.showlist
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1153
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1154
        # 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
  1155
        # 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
  1156
        # 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
  1157
        # 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
  1158
        def showparents(**args):
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10250
diff changeset
  1159
            ctx = args['ctx']
22764
1e2f54a149e8 templater: set the correct phase for parents
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22611
diff changeset
  1160
            parents = [[('rev', p.rev()),
1e2f54a149e8 templater: set the correct phase for parents
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22611
diff changeset
  1161
                        ('node', p.hex()),
1e2f54a149e8 templater: set the correct phase for parents
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22611
diff changeset
  1162
                        ('phase', p.phasestr())]
7878
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1163
                       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
  1164
            return showlist('parent', parents, **args)
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1165
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1166
        props = props.copy()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
  1167
        props.update(templatekw.keywords)
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1168
        props['parents'] = showparents
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents: 10026
diff changeset
  1169
        props['templ'] = self.t
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
  1170
        props['ctx'] = ctx
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
  1171
        props['repo'] = self.repo
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1172
        props['revcache'] = {'copies': copies}
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
  1173
        props['cache'] = self.cache
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1174
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1175
        # 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
  1176
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1177
        tmplmodes = [
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1178
            (True, None),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1179
            (self.ui.verbose, 'verbose'),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1180
            (self.ui.quiet, 'quiet'),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1181
            (self.ui.debugflag, 'debug'),
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1182
        ]
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1183
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1184
        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
  1185
        for mode, postfix  in tmplmodes:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1186
            for type in types:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1187
                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
  1188
                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
  1189
                    types[type] = cur
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1190
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1191
        try:
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1192
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1193
            # write header
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1194
            if types['header']:
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1195
                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
  1196
                if self.buffered:
7878
8c09952cd39a templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7807
diff changeset
  1197
                    self.header[ctx.rev()] = h
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1198
                else:
11465
ace5bd98bee3 heads: fix templating of headers again (issue2130)
Simon Howkins <simonh@symbian.org>
parents: 11441
diff changeset
  1199
                    if self.lastheader != h:
ace5bd98bee3 heads: fix templating of headers again (issue2130)
Simon Howkins <simonh@symbian.org>
parents: 11441
diff changeset
  1200
                        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
  1201
                        self.ui.write(h)
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1202
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1203
            # 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
  1204
            key = types['changeset']
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1205
            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
  1206
            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
  1207
10160
48653dea23dd Bugfix and test for hg log XML output
Robert Bachmann <rbachm@gmail.com>
parents: 10152
diff changeset
  1208
            if types['footer']:
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1209
                if not self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1210
                    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
  1211
                                                      **props))
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1212
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1213
        except KeyError, inst:
8013
9ec25db32b4e cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7967
diff changeset
  1214
            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
  1215
            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
  1216
        except SyntaxError, inst:
10829
56fffc9c8928 cmdutil: do not translate trivial string
Martin Geisler <mg@lazybytes.net>
parents: 10819
diff changeset
  1217
            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
  1218
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1219
def gettemplate(ui, tmpl, style):
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1220
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1221
    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
  1222
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1223
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1224
    # ui settings
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
  1225
    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
  1226
        tmpl = ui.config('ui', 'logtemplate')
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1227
        if tmpl:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1228
            try:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1229
                tmpl = templater.parsestring(tmpl)
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1230
            except SyntaxError:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1231
                tmpl = templater.parsestring(tmpl, quoted=False)
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1232
            return tmpl, None
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1233
        else:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1234
            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
  1235
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
  1236
    if not tmpl and style:
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1237
        mapfile = style
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1238
        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
  1239
            mapname = (templater.templatepath('map-cmdline.' + mapfile)
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1240
                       or templater.templatepath(mapfile))
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1241
            if mapname:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1242
                mapfile = mapname
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1243
        return None, mapfile
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1244
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1245
    if not tmpl:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1246
        return None, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1247
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1248
    # looks like a literal template?
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1249
    if '{' in tmpl:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1250
        return tmpl, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1251
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1252
    # perhaps a stock style?
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1253
    if not os.path.split(tmpl)[0]:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1254
        mapname = (templater.templatepath('map-cmdline.' + tmpl)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1255
                   or templater.templatepath(tmpl))
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1256
        if mapname and os.path.isfile(mapname):
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1257
            return None, mapname
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1258
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1259
    # perhaps it's a reference to [templates]
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1260
    t = ui.config('templates', tmpl)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1261
    if t:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1262
        try:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1263
            tmpl = templater.parsestring(t)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1264
        except SyntaxError:
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1265
            tmpl = templater.parsestring(t, quoted=False)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1266
        return tmpl, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1267
21944
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1268
    if tmpl == 'list':
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1269
        ui.write(_("available styles: %s\n") % templater.stylelist())
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1270
        raise util.Abort(_("specify a template"))
0483ff40e326 templates: re-add template listing support
Matt Mackall <mpm@selenic.com>
parents: 21924
diff changeset
  1271
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1272
    # 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
  1273
    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
  1274
        # is it a mapfile for a style?
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1275
        if os.path.basename(tmpl).startswith("map-"):
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1276
            return None, os.path.realpath(tmpl)
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1277
        tmpl = open(tmpl).read()
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1278
        return tmpl, None
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1279
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1280
    # constant string?
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1281
    return tmpl, None
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1282
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1283
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
  1284
    """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
  1285
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1286
    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
  1287
    1. option 'template'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1288
    2. option 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1289
    3. [ui] setting 'logtemplate'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1290
    4. [ui] setting 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1291
    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
  1292
    regular display via changeset_printer() is done.
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1293
    """
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1294
    # options
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1295
    matchfn = None
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
  1296
    if opts.get('patch') or opts.get('stat'):
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1297
        matchfn = 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
  1298
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1299
    if opts.get('template') == 'json':
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1300
        return jsonchangeset(ui, repo, matchfn, opts, buffered)
3837
7df171ea50cd Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents: 3827
diff changeset
  1301
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1302
    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
  1303
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1304
    if not tmpl and not mapfile:
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1305
        return changeset_printer(ui, repo, matchfn, opts, buffered)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1306
7967
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1307
    try:
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1308
        t = changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile,
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1309
                                buffered)
7967
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1310
    except SyntaxError, inst:
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1311
        raise util.Abort(inst.args[0])
c03f42159afa cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7948
diff changeset
  1312
    return t
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1313
20470
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1314
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
  1315
    """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
  1316
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1317
    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
  1318
    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
  1319
    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
  1320
        ui.write(' ')
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1321
        ui.write(hex(repl))
22215
525cde5d954d obsmarker: add a `flags` method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22213
diff changeset
  1322
    ui.write(' %X ' % marker.flags())
22260
2229d757802d debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22250
diff changeset
  1323
    parents = marker.parentnodes()
2229d757802d debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22250
diff changeset
  1324
    if parents is not None:
2229d757802d debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22250
diff changeset
  1325
        ui.write('{%s} ' % ', '.join(hex(p) for p in parents))
22220
908c76e84ec5 debugobsolete: explicitly display date in the output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22215
diff changeset
  1326
    ui.write('(%s) ' % util.datestr(marker.date()))
20470
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1327
    ui.write('{%s}' % (', '.join('%r: %r' % t for t in
22220
908c76e84ec5 debugobsolete: explicitly display date in the output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22215
diff changeset
  1328
                                 sorted(marker.metadata().items())
908c76e84ec5 debugobsolete: explicitly display date in the output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22215
diff changeset
  1329
                                 if t[0] != 'date')))
20470
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1330
    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
  1331
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1332
def finddate(ui, repo, date):
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1333
    """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
  1334
5836
c5c9a022bd9a Tweak finddate to pass date directly.
mark.williamson@cl.cam.ac.uk
parents: 5829
diff changeset
  1335
    df = util.matchdate(date)
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14321
diff changeset
  1336
    m = scmutil.matchall(repo)
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1337
    results = {}
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1338
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1339
    def prep(ctx, fns):
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1340
        d = ctx.date()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1341
        if df(d[0]):
9668
2c24471d478c cmdutil: fix bug in finddate() implementation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9667
diff changeset
  1342
            results[ctx.rev()] = d
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1343
9667
8743f2e1bc54 merge changes from mpm
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9666 9665
diff changeset
  1344
    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
  1345
        rev = ctx.rev()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1346
        if rev in results:
16937
5487088f0d43 cmdutil: lowercase finddate status message
Martin Geisler <mg@aragost.com>
parents: 16776
diff changeset
  1347
            ui.status(_("found revision %s from %s\n") %
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1348
                      (rev, util.datestr(results[rev])))
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1349
            return str(rev)
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1350
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1351
    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
  1352
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1353
def increasingwindows(windowsize=8, sizelimit=512):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1354
    while True:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1355
        yield windowsize
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1356
        if windowsize < sizelimit:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1357
            windowsize *= 2
16776
5088d0b9a9a1 cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents: 16701
diff changeset
  1358
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1359
class FileWalkError(Exception):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1360
    pass
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1361
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1362
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
  1363
    '''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
  1364
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1365
    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
  1366
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1367
    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
  1368
    filelogs alone.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1369
    '''
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1370
    wanted = set()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1371
    copies = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1372
    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
  1373
    def filerevgen(filelog, last):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1374
        """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1375
        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
  1376
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1377
        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
  1378
        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
  1379
        tuples in backwards order
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1380
        """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1381
        cl_count = len(repo)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1382
        revs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1383
        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
  1384
            linkrev = filelog.linkrev(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1385
            if linkrev < minrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1386
                continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1387
            # 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
  1388
            # 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
  1389
            if linkrev >= cl_count:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1390
                break
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1391
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1392
            parentlinkrevs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1393
            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
  1394
                if p != nullrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1395
                    parentlinkrevs.append(filelog.linkrev(p))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1396
            n = filelog.node(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1397
            revs.append((linkrev, parentlinkrevs,
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1398
                         follow and filelog.renamed(n)))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1399
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1400
        return reversed(revs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1401
    def iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1402
        pctx = repo['.']
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1403
        for filename in match.files():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1404
            if follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1405
                if filename not in pctx:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1406
                    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
  1407
                                       'revision: "%s"') % filename)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1408
                yield filename, pctx[filename].filenode()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1409
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1410
                yield filename, None
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1411
        for filename_node in copies:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1412
            yield filename_node
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1413
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1414
    for file_, node in iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1415
        filelog = repo.file(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1416
        if not len(filelog):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1417
            if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1418
                # 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
  1419
                # 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
  1420
                if follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1421
                    raise util.Abort(
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1422
                        _('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
  1423
                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
  1424
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1425
                continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1426
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1427
        if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1428
            last = len(filelog) - 1
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1429
        else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1430
            last = filelog.rev(node)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1431
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1432
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1433
        # 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
  1434
        ancestors = set([filelog.linkrev(last)])
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1435
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1436
        # 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
  1437
        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
  1438
            if not follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1439
                if rev > maxrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1440
                    continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1441
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1442
                # 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
  1443
                # rev to us:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1444
                # 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
  1445
                # 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
  1446
                # to explore the file graph
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1447
                if rev not in ancestors:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1448
                    continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1449
                # XXX insert 1327 fix here
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1450
                if flparentlinkrevs:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1451
                    ancestors.update(flparentlinkrevs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1452
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1453
            fncache.setdefault(rev, []).append(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1454
            wanted.add(rev)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1455
            if copied:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1456
                copies.append(copied)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1457
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1458
    return wanted
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1459
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9664
diff changeset
  1460
def walkchangerevs(repo, match, opts, prepare):
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
  1461
    '''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
  1462
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1463
    Callers most commonly need to iterate backwards over the history
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
  1464
    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
  1465
    performance, so we use iterators in a "windowed" way.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1466
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1467
    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
  1468
    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
  1469
    order (usually backwards) to display it.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1470
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1471
    This function returns an iterator yielding contexts. Before
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1472
    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
  1473
    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
  1474
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1475
    follow = opts.get('follow') or opts.get('follow_first')
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1476
17676
f87683a1b02a clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17675
diff changeset
  1477
    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
  1478
        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
  1479
    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
  1480
        revs = repo.revs('reverse(:.)')
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1481
    else:
20704
623ed0ed793e cmdutil: changed walkchangerevs to use spanset instead of baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20668
diff changeset
  1482
        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
  1483
        revs.reverse()
11281
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
  1484
    if not revs:
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
  1485
        return []
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8119
diff changeset
  1486
    wanted = set()
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1487
    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
  1488
    fncache = {}
16108
f7e0d95d0a0b log: remove caching of all visited revisions (issue3253)
Matt Mackall <mpm@selenic.com>
parents: 16070
diff changeset
  1489
    change = repo.changectx
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1490
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1491
    # 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
  1492
    # 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
  1493
    # 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
  1494
    # match the file filtering conditions.
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1495
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1496
    if not slowpath and not match.files():
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1497
        # No files, no patterns.  Display all revs.
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1498
        wanted = revs
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9664
diff changeset
  1499
16381
64c8ae09162e log: bypass file scan part of fastpath when no files
Matt Mackall <mpm@selenic.com>
parents: 16380
diff changeset
  1500
    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
  1501
        # 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
  1502
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1503
        try:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1504
            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
  1505
        except FileWalkError:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1506
            slowpath = True
11608
183e63112698 log: remove increasing windows usage in fastpath
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11607
diff changeset
  1507
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1508
            # 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
  1509
            # 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
  1510
            # existed in history, otherwise simply return
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1511
            for path in match.files():
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1512
                if path == '.' or path in repo.store:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1513
                    break
18340
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
  1514
            else:
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
  1515
                return []
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1516
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1517
    if slowpath:
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1518
        # 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
  1519
        # changed files
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1520
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1521
        if follow:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1522
            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
  1523
                               'filenames'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1524
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1525
        # 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
  1526
        # 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
  1527
        class lazywantedset(object):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1528
            def __init__(self):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1529
                self.set = set()
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1530
                self.revs = set(revs)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1531
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1532
            # 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
  1533
            # 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
  1534
            def __contains__(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1535
                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
  1536
                    return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1537
                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
  1538
                    return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1539
                else:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1540
                    self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1541
                    ctx = change(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1542
                    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
  1543
                    if matches:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1544
                        fncache[value] = matches
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1545
                        self.set.add(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1546
                        return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1547
                    return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1548
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1549
            def discard(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1550
                self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1551
                self.set.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1552
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1553
        wanted = lazywantedset()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1554
8778
c5f36402daad use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8761
diff changeset
  1555
    class followfilter(object):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1556
        def __init__(self, onlyfirst=False):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1557
            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
  1558
            self.roots = set()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1559
            self.onlyfirst = onlyfirst
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1560
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1561
        def match(self, rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1562
            def realparents(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1563
                if self.onlyfirst:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1564
                    return repo.changelog.parentrevs(rev)[0:1]
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1565
                else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1566
                    return filter(lambda x: x != nullrev,
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1567
                                  repo.changelog.parentrevs(rev))
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1568
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1569
            if self.startrev == nullrev:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1570
                self.startrev = rev
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1571
                return True
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1572
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1573
            if rev > self.startrev:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1574
                # forward: all descendants
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1575
                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
  1576
                    self.roots.add(self.startrev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1577
                for parent in realparents(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1578
                    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
  1579
                        self.roots.add(rev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1580
                        return True
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1581
            else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1582
                # backwards: all parents
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1583
                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
  1584
                    self.roots.update(realparents(self.startrev))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1585
                if rev in self.roots:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1586
                    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
  1587
                    self.roots.update(realparents(rev))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1588
                    return True
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1589
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1590
            return False
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1591
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1592
    # 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
  1593
    # 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
  1594
    for rev in opts.get('prune', ()):
16380
84ba30e8c790 cmdutil: use context instead of lookup
Matt Mackall <mpm@selenic.com>
parents: 16304
diff changeset
  1595
        rev = repo[rev].rev()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1596
        ff = followfilter()
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1597
        stop = min(revs[0], revs[-1])
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1598
        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
  1599
            if ff.match(x):
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1600
                wanted = wanted - [x]
18710
49ef9d0ca815 cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents: 18688
diff changeset
  1601
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1602
    # 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
  1603
    # revision range, yielding only revisions in wanted.
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1604
    def iterate():
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1605
        if follow and not match.files():
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1606
            ff = followfilter(onlyfirst=opts.get('follow_first'))
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1607
            def want(rev):
8119
af44d0b953c6 cmdutil: return boolean result directly in want function
Martin Geisler <mg@lazybytes.net>
parents: 8117
diff changeset
  1608
                return ff.match(rev) and rev in wanted
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1609
        else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1610
            def want(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1611
                return rev in wanted
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1612
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1613
        it = iter(revs)
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1614
        stopiteration = False
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1615
        for windowsize in increasingwindows():
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1616
            nrevs = []
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1617
            for i in xrange(windowsize):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1618
                try:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1619
                    rev = it.next()
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1620
                    if want(rev):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1621
                        nrevs.append(rev)
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1622
                except (StopIteration):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1623
                    stopiteration = True
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1624
                    break
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
  1625
            for rev in sorted(nrevs):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1626
                fns = fncache.get(rev)
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
  1627
                ctx = change(rev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1628
                if not fns:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1629
                    def fns_generator():
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
  1630
                        for f in ctx.files():
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1631
                            if match(f):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1632
                                yield f
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1633
                    fns = fns_generator()
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1634
                prepare(ctx, fns)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1635
            for rev in nrevs:
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1636
                yield change(rev)
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1637
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1638
            if stopiteration:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1639
                break
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1640
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  1641
    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
  1642
22166
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  1643
def _makefollowlogfilematcher(repo, files, followfirst):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1644
    # 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
  1645
    # 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
  1646
    # --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
  1647
    # 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
  1648
    # 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
  1649
    # 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
  1650
    # good enough).
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1651
    fcache = {}
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1652
    fcacheready = [False]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1653
    pctx = repo['.']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1654
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1655
    def populate():
21876
584bbfd1b50d log: make --patch --follow work inside a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 21825
diff changeset
  1656
        for fn in files:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1657
            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
  1658
                for c in i:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1659
                    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
  1660
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1661
    def filematcher(rev):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1662
        if not fcacheready[0]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1663
            # Lazy initialization
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1664
            fcacheready[0] = True
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1665
            populate()
21878
e2530d4a47c1 log: use an exact matcher for --patch --follow
Siddharth Agarwal <sid0@fb.com>
parents: 21877
diff changeset
  1666
        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
  1667
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1668
    return filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1669
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1670
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
  1671
    '''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
  1672
    return None
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1673
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  1674
def _makelogrevset(repo, pats, opts, revs):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1675
    """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
  1676
    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
  1677
    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
  1678
    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
  1679
    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
  1680
    """
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1681
    opt2revset = {
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1682
        'no_merges':        ('not merge()', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1683
        'only_merges':      ('merge()', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1684
        '_ancestors':       ('ancestors(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1685
        '_fancestors':      ('_firstancestors(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1686
        '_descendants':     ('descendants(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1687
        '_fdescendants':    ('_firstdescendants(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1688
        '_matchfiles':      ('_matchfiles(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1689
        'date':             ('date(%(val)r)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1690
        'branch':           ('branch(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1691
        '_patslog':         ('filelog(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1692
        '_patsfollow':      ('follow(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1693
        '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1694
        'keyword':          ('keyword(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1695
        '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
  1696
        'user':             ('user(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1697
        }
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1698
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1699
    opts = dict(opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1700
    # follow or not follow?
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1701
    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
  1702
    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
  1703
    # --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
  1704
    it = iter(revs)
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1705
    startrev = it.next()
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1706
    try:
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1707
        followdescendants = startrev < it.next()
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1708
    except (StopIteration):
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  1709
        followdescendants = False
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1710
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1711
    # 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
  1712
    # the same time
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1713
    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
  1714
    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
  1715
    # 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
  1716
    # _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
  1717
    # 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
  1718
    # platforms without shell expansion (windows).
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1719
    pctx = repo[None]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1720
    match, pats = scmutil.matchandpats(pctx, pats, opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1721
    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
  1722
    if not slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1723
        for f in match.files():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1724
            if follow and f not in pctx:
21998
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1725
                # If the file exists, it may be a directory, so let it
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1726
                # take the slow path.
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1727
                if os.path.exists(repo.wjoin(f)):
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1728
                    slowpath = True
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1729
                    continue
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1730
                else:
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1731
                    raise util.Abort(_('cannot follow file not in parent '
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1732
                                       'revision: "%s"') % f)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1733
            filelog = repo.file(f)
19293
446ab88d3f1c filelog: switch 'not len(filerevlog)' to 'not filerevlog'
Durham Goode <durham@fb.com>
parents: 19290
diff changeset
  1734
            if not filelog:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1735
                # 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
  1736
                # 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
  1737
                if follow:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1738
                    raise util.Abort(
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1739
                        _('cannot follow nonexistent file: "%s"') % f)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1740
                slowpath = True
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1741
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1742
        # 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
  1743
        # 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
  1744
        # 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
  1745
        # slowpath; otherwise, we can turn off the slowpath
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1746
        if slowpath:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1747
            for path in match.files():
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1748
                if path == '.' or path in repo.store:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1749
                    break
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1750
            else:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1751
                slowpath = False
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1752
23500
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  1753
    fpats = ('_patsfollow', '_patsfollowfirst')
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  1754
    fnopats = (('_ancestors', '_fancestors'),
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  1755
               ('_descendants', '_fdescendants'))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1756
    if slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1757
        # See walkchangerevs() slow path.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1758
        #
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1759
        # 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
  1760
        # 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
  1761
        # 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
  1762
        # "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
  1763
        # 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
  1764
        # directory.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1765
        matchargs = ['r:', 'd:relpath']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1766
        for p in pats:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1767
            matchargs.append('p:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1768
        for p in opts.get('include', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1769
            matchargs.append('i:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1770
        for p in opts.get('exclude', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1771
            matchargs.append('x:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1772
        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
  1773
        opts['_matchfiles'] = matchargs
23500
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  1774
        if follow:
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  1775
            opts[fnopats[0][followfirst]] = '.'
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1776
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1777
        if follow:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1778
            if pats:
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17391
diff changeset
  1779
                # 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
  1780
                # 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
  1781
                opts[fpats[followfirst]] = list(match.files())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1782
            else:
23955
8a29897d42d2 log: use rev() to build revset of --follow option from numeric revision
Yuya Nishihara <yuya@tcha.org>
parents: 23885
diff changeset
  1783
                op = fnopats[followdescendants][followfirst]
8a29897d42d2 log: use rev() to build revset of --follow option from numeric revision
Yuya Nishihara <yuya@tcha.org>
parents: 23885
diff changeset
  1784
                opts[op] = 'rev(%d)' % startrev
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1785
        else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1786
            opts['_patslog'] = list(pats)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1787
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1788
    filematcher = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1789
    if opts.get('patch') or opts.get('stat'):
21998
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1790
        # When following files, track renames via a special matcher.
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1791
        # If we're forced to take the slowpath it means we're following
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1792
        # at least one pattern/directory, so don't bother with rename tracking.
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  1793
        if follow and not match.always() and not slowpath:
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23101
diff changeset
  1794
            # _makefollowlogfilematcher expects its files argument to be
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23101
diff changeset
  1795
            # relative to 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
  1796
            filematcher = _makefollowlogfilematcher(repo, match.files(),
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  1797
                                                    followfirst)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1798
        else:
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  1799
            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
  1800
            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
  1801
                filematcher = lambda rev: match
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1802
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1803
    expr = []
23501
424d669118d3 log: fix log revset instability
Durham Goode <durham@fb.com>
parents: 23500
diff changeset
  1804
    for op, val in sorted(opts.iteritems()):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1805
        if not val:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1806
            continue
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1807
        if op not in opt2revset:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1808
            continue
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1809
        revop, andor = opt2revset[op]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1810
        if '%(val)' not in revop:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1811
            expr.append(revop)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1812
        else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1813
            if not isinstance(val, list):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1814
                e = revop % {'val': val}
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1815
            else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1816
                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
  1817
            expr.append(e)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1818
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1819
    if expr:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1820
        expr = '(' + ' and '.join(expr) + ')'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1821
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1822
        expr = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1823
    return expr, filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1824
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1825
def _logrevs(repo, opts):
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1826
    # Default --rev value depends on --follow but --follow behaviour
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1827
    # depends on revisions resolved from --rev...
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1828
    follow = opts.get('follow') or opts.get('follow_first')
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1829
    if opts.get('rev'):
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1830
        revs = scmutil.revrange(repo, opts['rev'])
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1831
    elif follow:
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1832
        revs = repo.revs('reverse(:.)')
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1833
    else:
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1834
        revs = revset.spanset(repo)
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1835
        revs.reverse()
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1836
    return revs
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1837
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1838
def getgraphlogrevs(repo, pats, opts):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1839
    """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
  1840
    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
  1841
    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
  1842
    --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
  1843
    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
  1844
    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
  1845
    """
18172
e6c5e0092469 cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents: 18171
diff changeset
  1846
    limit = loglimit(opts)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1847
    revs = _logrevs(repo, opts)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1848
    if not revs:
20759
74139960c302 getgraphlogrevs: return an empty baseset instead of a empty list
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20758
diff changeset
  1849
        return revset.baseset(), None, None
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  1850
    expr, filematcher = _makelogrevset(repo, pats, opts, revs)
24060
eb1c9700d19d graphlog: move comment and flag denoting revs might be unsorted
Yuya Nishihara <yuya@tcha.org>
parents: 24059
diff changeset
  1851
    if opts.get('rev'):
eb1c9700d19d graphlog: move comment and flag denoting revs might be unsorted
Yuya Nishihara <yuya@tcha.org>
parents: 24059
diff changeset
  1852
        # User-specified revs might be unsorted, but don't sort before
eb1c9700d19d graphlog: move comment and flag denoting revs might be unsorted
Yuya Nishihara <yuya@tcha.org>
parents: 24059
diff changeset
  1853
        # _makelogrevset because it might depend on the order of revs
18169
ae663cba9a8d cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents: 18031
diff changeset
  1854
        revs.sort(reverse=True)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1855
    if expr:
18171
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1856
        # 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
  1857
        # 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
  1858
        revs.reverse()
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1859
        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
  1860
        # 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
  1861
        # 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
  1862
        # again to fix that.
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1863
        revs = matcher(repo, revs)
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  1864
        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
  1865
    if limit is not None:
22807
cd43195ef876 getgraphlogrevs: remove user of baseset.append
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22806
diff changeset
  1866
        limitedrevs = []
20755
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1867
        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
  1868
            if idx >= limit:
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1869
                break
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  1870
            limitedrevs.append(rev)
22807
cd43195ef876 getgraphlogrevs: remove user of baseset.append
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22806
diff changeset
  1871
        revs = revset.baseset(limitedrevs)
18172
e6c5e0092469 cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents: 18171
diff changeset
  1872
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1873
    return revs, expr, filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1874
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1875
def getlogrevs(repo, pats, opts):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1876
    """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
  1877
    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
  1878
    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
  1879
    --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
  1880
    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
  1881
    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
  1882
    """
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1883
    limit = loglimit(opts)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  1884
    revs = _logrevs(repo, opts)
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1885
    if not revs:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1886
        return revset.baseset([]), None, None
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1887
    expr, filematcher = _makelogrevset(repo, pats, opts, revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1888
    if expr:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1889
        # 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
  1890
        # 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
  1891
        if not opts.get('rev'):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1892
            revs.reverse()
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1893
        matcher = revset.match(repo.ui, expr)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1894
        # 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
  1895
        # 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
  1896
        # again to fix that.
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1897
        revs = matcher(repo, revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1898
        if not opts.get('rev'):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1899
            revs.sort(reverse=True)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1900
    if limit is not None:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1901
        count = 0
22806
65ccc733d58e getlogrevs: remove user of baseset.append
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22765
diff changeset
  1902
        limitedrevs = []
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1903
        it = iter(revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1904
        while count < limit:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1905
            try:
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1906
                limitedrevs.append(it.next())
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1907
            except (StopIteration):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1908
                break
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1909
            count += 1
22806
65ccc733d58e getlogrevs: remove user of baseset.append
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22765
diff changeset
  1910
        revs = revset.baseset(limitedrevs)
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1911
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1912
    return revs, expr, filematcher
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  1913
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1914
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
  1915
                 filematcher=None):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1916
    seen, state = [], graphmod.asciistate()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1917
    for rev, type, ctx, parents in dag:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1918
        char = 'o'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1919
        if ctx.node() in showparents:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1920
            char = '@'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1921
        elif ctx.obsolete():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1922
            char = 'x'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1923
        copies = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1924
        if getrenamed and ctx.rev():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1925
            copies = []
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1926
            for fn in ctx.files():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1927
                rename = getrenamed(fn, ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1928
                if rename:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1929
                    copies.append((fn, rename[0]))
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1930
        revmatchfn = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1931
        if filematcher is not None:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1932
            revmatchfn = filematcher(ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1933
        displayer.show(ctx, copies=copies, matchfn=revmatchfn)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1934
        lines = displayer.hunk.pop(rev).split('\n')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1935
        if not lines[-1]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1936
            del lines[-1]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1937
        displayer.flush(rev)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1938
        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
  1939
        for type, char, lines, coldata in edges:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1940
            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
  1941
    displayer.close()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  1942
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1943
def graphlog(ui, repo, *pats, **opts):
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1944
    # Parameters are identical to log command ones
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1945
    revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1946
    revdag = graphmod.dagwalker(repo, revs)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1947
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1948
    getrenamed = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1949
    if opts.get('copies'):
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1950
        endrev = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1951
        if opts.get('rev'):
20760
d5fa413346e7 cmdutil: changed max method for lazy call
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20759
diff changeset
  1952
            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
  1953
        getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1954
    displayer = show_changeset(ui, repo, opts, buffered=True)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1955
    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
  1956
    displaygraph(ui, revdag, displayer, showparents,
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1957
                 graphmod.asciiedges, getrenamed, filematcher)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  1958
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1959
def checkunsupportedgraphflags(pats, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1960
    for op in ["newest_first"]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1961
        if op in opts and opts[op]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1962
            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
  1963
                             % op.replace("_", "-"))
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1964
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1965
def graphrevs(repo, nodes, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1966
    limit = loglimit(opts)
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1967
    nodes.reverse()
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1968
    if limit is not None:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1969
        nodes = nodes[:limit]
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1970
    return graphmod.nodes(repo, nodes)
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  1971
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  1972
def add(ui, repo, match, prefix, explicitonly, **opts):
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1973
    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
  1974
    bad = []
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1975
    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
  1976
    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
  1977
    names = []
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1978
    wctx = repo[None]
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1979
    cca = None
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1980
    abort, warn = scmutil.checkportabilityalert(ui)
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1981
    if abort or warn:
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17182
diff changeset
  1982
        cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate)
23258
10697f29af2b add: add back forgotten files even when not matching exactly (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23139
diff changeset
  1983
    for f in wctx.walk(match):
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  1984
        exact = match.exact(f)
23462
afa3fbbcabd3 add: use lexists so that broken symbolic links are added
John Coomes <john.coomes@oracle.com>
parents: 23453
diff changeset
  1985
        if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f):
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1986
            if cca:
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  1987
                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
  1988
            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
  1989
            if ui.verbose or not exact:
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  1990
                ui.status(_('adding %s\n') % match.rel(f))
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  1991
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  1992
    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
  1993
        sub = wctx.sub(subpath)
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1994
        try:
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1995
            submatch = matchmod.narrowmatcher(subpath, match)
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  1996
            if opts.get('subrepos'):
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  1997
                bad.extend(sub.add(ui, submatch, prefix, False, **opts))
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  1998
            else:
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  1999
                bad.extend(sub.add(ui, submatch, prefix, True, **opts))
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  2000
        except error.LookupError:
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  2001
            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
  2002
                           % join(subpath))
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  2003
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  2004
    if not opts.get('dry_run'):
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  2005
        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
  2006
        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
  2007
    return bad
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  2008
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2009
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
  2010
    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
  2011
    bad = []
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2012
    oldbad = match.bad
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2013
    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
  2014
    wctx = repo[None]
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2015
    forgot = []
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2016
    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
  2017
    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
  2018
    if explicitonly:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2019
        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
  2020
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  2021
    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
  2022
        sub = wctx.sub(subpath)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2023
        try:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2024
            submatch = matchmod.narrowmatcher(subpath, match)
23577
597b071a0e0d subrepo: drop the 'ui' parameter to forget()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23576
diff changeset
  2025
            subbad, subforgot = sub.forget(submatch, prefix)
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2026
            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
  2027
            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
  2028
        except error.LookupError:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2029
            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
  2030
                           % join(subpath))
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2031
16070
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
  2032
    if not explicitonly:
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
  2033
        for f in match.files():
23673
69cd91d04117 forget: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents: 23579
diff changeset
  2034
            if f not in repo.dirstate and not repo.wvfs.isdir(f):
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2035
                if f not in forgot:
23673
69cd91d04117 forget: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents: 23579
diff changeset
  2036
                    if repo.wvfs.exists(f):
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2037
                        ui.warn(_('not removing %s: '
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2038
                                  'file is already untracked\n')
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2039
                                % match.rel(f))
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2040
                    bad.append(f)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2041
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2042
    for f in forget:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2043
        if ui.verbose or not match.exact(f):
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2044
            ui.status(_('removing %s\n') % match.rel(f))
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2045
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2046
    rejected = wctx.forget(forget, prefix)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2047
    bad.extend(f for f in rejected if f in match.files())
23838
b95b9fd7ba29 forget: don't report rejected files as forgotten as well
Matt Harbison <matt_harbison@yahoo.com>
parents: 23772
diff changeset
  2048
    forgot.extend(f for f in forget if f not in rejected)
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2049
    return bad, forgot
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2050
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2051
def remove(ui, repo, m, prefix, after, force, subrepos):
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2052
    join = lambda f: os.path.join(prefix, f)
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2053
    ret = 0
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2054
    s = repo.status(match=m, clean=True)
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2055
    modified, added, deleted, clean = s[0], s[1], s[3], s[6]
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2056
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2057
    wctx = repo[None]
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2058
23326
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2059
    for subpath in sorted(wctx.substate):
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2060
        def matchessubrepo(matcher, subpath):
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2061
            if matcher.exact(subpath):
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2062
                return True
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2063
            for f in matcher.files():
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2064
                if f.startswith(subpath):
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2065
                    return True
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2066
            return False
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2067
f6b8d23492e5 remove: support remove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23325
diff changeset
  2068
        if subrepos or matchessubrepo(m, subpath):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2069
            sub = wctx.sub(subpath)
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2070
            try:
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2071
                submatch = matchmod.narrowmatcher(subpath, m)
23578
d0546e8e1def subrepo: drop the 'ui' parameter to removefiles()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23577
diff changeset
  2072
                if sub.removefiles(submatch, prefix, after, force, subrepos):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2073
                    ret = 1
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2074
            except error.LookupError:
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2075
                ui.status(_("skipping missing subrepository: %s\n")
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2076
                               % join(subpath))
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2077
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2078
    # warn about failure to delete explicit files/dirs
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2079
    for f in m.files():
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2080
        def insubrepo():
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2081
            for subpath in wctx.substate:
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2082
                if f.startswith(subpath):
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2083
                    return True
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2084
            return False
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2085
23327
bd296bb4b5c8 remove: avoid a bogus warning about no tracked files when removing '.'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23326
diff changeset
  2086
        if f in repo.dirstate or f in wctx.dirs() or f == '.' or insubrepo():
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2087
            continue
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2088
23674
6e36b9fc7869 remove: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents: 23673
diff changeset
  2089
        if repo.wvfs.exists(f):
6e36b9fc7869 remove: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents: 23673
diff changeset
  2090
            if repo.wvfs.isdir(f):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2091
                ui.warn(_('not removing %s: no tracked files\n')
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2092
                        % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2093
            else:
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2094
                ui.warn(_('not removing %s: file is untracked\n')
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2095
                        % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2096
        # missing files will generate a warning elsewhere
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2097
        ret = 1
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2098
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2099
    if force:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2100
        list = modified + deleted + clean + added
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2101
    elif after:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2102
        list = deleted
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2103
        for f in modified + added + clean:
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2104
            ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2105
            ret = 1
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2106
    else:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2107
        list = deleted + clean
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2108
        for f in modified:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2109
            ui.warn(_('not removing %s: file is modified (use -f'
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2110
                      ' to force removal)\n') % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2111
            ret = 1
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2112
        for f in added:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2113
            ui.warn(_('not removing %s: file has been marked for add'
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2114
                      ' (use forget to undo)\n') % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2115
            ret = 1
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2116
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2117
    for f in sorted(list):
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2118
        if ui.verbose or not m.exact(f):
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2119
            ui.status(_('removing %s\n') % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2120
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2121
    wlock = repo.wlock()
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2122
    try:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2123
        if not after:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2124
            for f in list:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2125
                if f in added:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2126
                    continue # we never unlink added files on remove
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2127
                util.unlinkpath(repo.wjoin(f), ignoremissing=True)
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2128
        repo[None].forget(list)
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2129
    finally:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2130
        wlock.release()
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2131
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2132
    return ret
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2133
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2134
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
  2135
    err = 1
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2136
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2137
    def write(path):
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2138
        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
  2139
                         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
  2140
        data = ctx[path].data()
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2141
        if opts.get('decode'):
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2142
            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
  2143
        fp.write(data)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2144
        fp.close()
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2145
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2146
    # 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
  2147
    # 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
  2148
    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
  2149
        file = matcher.files()[0]
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2150
        mf = repo.manifest
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2151
        mfnode = ctx._changeset[0]
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2152
        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
  2153
            write(file)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2154
            return 0
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2155
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2156
    # 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
  2157
    bad = matcher.bad
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2158
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2159
    def badfn(path, msg):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2160
        for subpath in ctx.substate:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2161
            if path.startswith(subpath):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2162
                return
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2163
        bad(path, msg)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2164
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2165
    matcher.bad = badfn
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2166
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2167
    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
  2168
        write(abs)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2169
        err = 0
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2170
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2171
    matcher.bad = bad
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2172
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2173
    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
  2174
        sub = ctx.sub(subpath)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2175
        try:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2176
            submatch = matchmod.narrowmatcher(subpath, matcher)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2177
23576
70a7478c33de subrepo: drop the 'ui' parameter to cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23537
diff changeset
  2178
            if not sub.cat(submatch, os.path.join(prefix, sub._path),
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2179
                           **opts):
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2180
                err = 0
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2181
        except error.RepoLookupError:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2182
            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
  2183
                           % os.path.join(prefix, subpath))
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2184
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2185
    return err
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2186
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  2187
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
  2188
    '''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
  2189
    date = opts.get('date')
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  2190
    if date:
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  2191
        opts['date'] = util.parsedate(date)
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
  2192
    message = logmessage(ui, opts)
23533
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23509
diff changeset
  2193
    matcher = scmutil.match(repo[None], pats, opts)
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  2194
5829
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  2195
    # 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
  2196
    # that doesn't support addremove
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  2197
    if opts.get('addremove'):
23537
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23535
diff changeset
  2198
        if scmutil.addremove(repo, matcher, "", opts) != 0:
23535
72c23fa4f52f commit: abort if --addremove is specified, but fails
Matt Harbison <matt_harbison@yahoo.com>
parents: 23533
diff changeset
  2199
            raise util.Abort(
72c23fa4f52f commit: abort if --addremove is specified, but fails
Matt Harbison <matt_harbison@yahoo.com>
parents: 23533
diff changeset
  2200
                _("failed to mark all new/missing files as added/removed"))
23533
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23509
diff changeset
  2201
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23509
diff changeset
  2202
    return commitfunc(ui, repo, message, matcher, opts)
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2203
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2204
def amend(ui, repo, commitfunc, old, extra, pats, opts):
23101
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2205
    # amend will reuse the existing user if not specified, but the obsolete
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2206
    # marker creation requires that the current user's name is specified.
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2207
    if obsolete._enabled:
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2208
        ui.username() # raise exception if username not set
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2209
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2210
    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
  2211
    base = old.p1()
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2212
18197
153659e86a5f amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18006
diff changeset
  2213
    wlock = lock = newid = None
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2214
    try:
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2215
        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
  2216
        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
  2217
        tr = repo.transaction('amend')
17049
2440822446ce amend: disable hooks when creating intermediate commit (issue3501)
Idan Kamara <idankk86@gmail.com>
parents: 16678
diff changeset
  2218
        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
  2219
            # 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
  2220
            # 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
  2221
            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
  2222
            # 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
  2223
            # 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
  2224
            # `logmessage` anyway.
034e55bbf7c0 amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17812
diff changeset
  2225
            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
  2226
            # 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
  2227
            # 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
  2228
            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
  2229
            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
  2230
            try:
18198
9b4adaef0db9 amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18197
diff changeset
  2231
                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
  2232
                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
  2233
                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
  2234
            finally:
18198
9b4adaef0db9 amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18197
diff changeset
  2235
                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
  2236
                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
  2237
            ctx = repo[node]
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2238
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2239
            # 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
  2240
            #
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2241
            # 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
  2242
            #          |   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
  2243
            #          |   (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
  2244
            #          |
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2245
            # 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
  2246
            #          |
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2247
            # 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
  2248
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2249
            # 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
  2250
            # source)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2251
            extra.update(old.extra())
16630
f30226b1a46a amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents: 16553
diff changeset
  2252
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2253
            # 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
  2254
            extra.update(ctx.extra())
16630
f30226b1a46a amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents: 16553
diff changeset
  2255
18909
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2256
            if len(old.parents()) > 1:
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2257
                # 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
  2258
                # slower repo.status() method
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2259
                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
  2260
                             for fn in st])
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2261
            else:
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2262
                files = set(old.files())
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2263
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2264
            # 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
  2265
            # 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
  2266
            # 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
  2267
            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
  2268
                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
  2269
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2270
                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
  2271
                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
  2272
                # 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
  2273
                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
  2274
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2275
                # 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
  2276
                # 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
  2277
                # 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
  2278
                # 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
  2279
                # 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
  2280
                files.update(ctx.files())
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2281
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2282
                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
  2283
                    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
  2284
                        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
  2285
                        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
  2286
                            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
  2287
                            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
  2288
                                    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
  2289
                        else:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2290
                            return False
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2291
                    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
  2292
                        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
  2293
                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
  2294
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2295
                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
  2296
                    try:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2297
                        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
  2298
                        flags = fctx.flags()
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21579
diff changeset
  2299
                        mctx = context.memfilectx(repo,
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21579
diff changeset
  2300
                                                  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
  2301
                                                  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
  2302
                                                  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
  2303
                                                  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
  2304
                        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
  2305
                    except KeyError:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22278
diff changeset
  2306
                        return None
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2307
            else:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2308
                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
  2309
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2310
                # 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
  2311
                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
  2312
                    try:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2313
                        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
  2314
                    except KeyError:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22278
diff changeset
  2315
                        return None
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2316
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2317
                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
  2318
                date = opts.get('date') or old.date()
22249
f5ff18f65b73 commit: change "editform" to distinguish merge commits from other (--amend)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22248
diff changeset
  2319
            editform = mergeeditform(old, 'commit.amend')
22010
41e969cb9468 commit: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21999
diff changeset
  2320
            editor = getcommiteditor(editform=editform, **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
  2321
            if not message:
22010
41e969cb9468 commit: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21999
diff changeset
  2322
                editor = getcommiteditor(edit=True, editform=editform)
17473
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2323
                message = old.description()
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2324
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
  2325
            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
  2326
            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
  2327
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2328
            new = context.memctx(repo,
18909
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2329
                                 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
  2330
                                 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
  2331
                                 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
  2332
                                 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
  2333
                                 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
  2334
                                 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
  2335
                                 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
  2336
                                 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
  2337
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2338
            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
  2339
            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
  2340
                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
  2341
                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
  2342
                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
  2343
                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
  2344
                # 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
  2345
                # 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
  2346
                #
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2347
                # 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
  2348
                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
  2349
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2350
            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
  2351
            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
  2352
                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
  2353
                    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
  2354
                else:
b0153cb8b64e commit: create new amend changeset as secret correctly for "--secret" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20072
diff changeset
  2355
                    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
  2356
                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
  2357
                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
  2358
            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
  2359
                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
  2360
            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
  2361
                # 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
  2362
                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
  2363
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2364
                # 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
  2365
                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
  2366
                if bms:
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2367
                    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
  2368
                    for bm in bms:
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2369
                        marks[bm] = newid
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2370
                    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
  2371
            #commit the whole amend process
22951
6c86c673dde6 obsolete: add createmarkers option
Durham Goode <durham@fb.com>
parents: 22901
diff changeset
  2372
            createmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt)
6c86c673dde6 obsolete: add createmarkers option
Durham Goode <durham@fb.com>
parents: 22901
diff changeset
  2373
            if createmarkers and newid != old.node():
17475
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2374
                # 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
  2375
                new = repo[newid]
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2376
                obs = [(old, (new,))]
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2377
                if node:
17812
578fcc22b469 amend: do a bare kill of temporary changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17811
diff changeset
  2378
                    obs.append((ctx, ()))
17475
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2379
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2380
                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
  2381
            tr.close()
17461
bacde764fba0 amend: preserve phase of amended revision (issue3602)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17391
diff changeset
  2382
        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
  2383
            tr.release()
22951
6c86c673dde6 obsolete: add createmarkers option
Durham Goode <durham@fb.com>
parents: 22901
diff changeset
  2384
        if not createmarkers and newid != old.node():
17475
63e45aee46d4 amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17473
diff changeset
  2385
            # 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
  2386
            # commit
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2387
            if node:
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2388
                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
  2389
            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
  2390
            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
  2391
    finally:
18197
153659e86a5f amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18006
diff changeset
  2392
        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
  2393
            repo.dirstate.invalidate()
19024
ab04e87a5f3b amend: fix unlocking order - first lock then wlock
Mads Kiilerich <madski@unity3d.com>
parents: 18991
diff changeset
  2394
        lockmod.release(lock, wlock)
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2395
    return newid
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2396
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
  2397
def commiteditor(repo, ctx, subs, editform=''):
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2398
    if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2399
        return ctx.description()
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
  2400
    return commitforceeditor(repo, ctx, subs, editform=editform)
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2401
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
  2402
def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
  2403
                      editform=''):
21923
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2404
    if not extramsg:
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2405
        extramsg = _("Leave message empty to abort commit.")
22012
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2406
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2407
    forms = [e for e in editform.split('.') if e]
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2408
    forms.insert(0, 'changeset')
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2409
    while forms:
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2410
        tmpl = repo.ui.config('committemplate', '.'.join(forms))
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2411
        if tmpl:
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2412
            committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2413
            break
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2414
        forms.pop()
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2415
    else:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2416
        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
  2417
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2418
    # 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
  2419
    olddir = os.getcwd()
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2420
    os.chdir(repo.root)
22205
9fa429723f26 ui: invoke editor for committing with HGEDITFORM environment variable
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22190
diff changeset
  2421
    text = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform)
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2422
    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
  2423
    os.chdir(olddir)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2424
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2425
    if finishdesc:
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2426
        text = finishdesc(text)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2427
    if not text.strip():
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2428
        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
  2429
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2430
    return text
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2431
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2432
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
  2433
    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
  2434
    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
  2435
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2436
    try:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2437
        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
  2438
    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
  2439
        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
  2440
22013
de5cee8ba088 cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22012
diff changeset
  2441
    for k, v in repo.ui.configitems('committemplate'):
de5cee8ba088 cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22012
diff changeset
  2442
        if k != 'changeset':
de5cee8ba088 cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22012
diff changeset
  2443
            t.t.cache[k] = v
de5cee8ba088 cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22012
diff changeset
  2444
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2445
    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
  2446
        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
  2447
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2448
    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
  2449
    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
  2450
    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
  2451
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2452
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
  2453
    edittext = []
8707
0550dfe4fca1 commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents: 8680
diff changeset
  2454
    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
  2455
    if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2456
        edittext.append(ctx.description())
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2457
    edittext.append("")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2458
    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
  2459
    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
  2460
                      "  Lines beginning with 'HG:' are removed."))
21923
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2461
    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
  2462
    edittext.append("HG: --")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2463
    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
  2464
    if ctx.p2():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2465
        edittext.append(_("HG: branch merge"))
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2466
    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
  2467
        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
  2468
    if bookmarks.iscurrent(repo):
94317c2d53b8 commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents: 18364
diff changeset
  2469
        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
  2470
    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
  2471
    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
  2472
    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
  2473
    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
  2474
    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
  2475
        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
  2476
    edittext.append("")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2477
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2478
    return "\n".join(edittext)
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2479
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2480
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
  2481
    ctx = repo[node]
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2482
    parents = ctx.parents()
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2483
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2484
    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
  2485
        [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
  2486
        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
  2487
        # 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
  2488
        # 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
  2489
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2490
        # 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
  2491
        #   N: null or no parent
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2492
        #   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
  2493
        #   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
  2494
        #   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
  2495
        # 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
  2496
        # 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
  2497
        # 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
  2498
        # printed anyway.
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2499
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2500
        # Par Msg Comment
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2501
        # 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
  2502
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2503
        # 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
  2504
        # 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
  2505
        # H N  n  usual case
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2506
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2507
        # 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
  2508
        # C B  y  branch merge
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2509
        # 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
  2510
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2511
        # 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
  2512
        # 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
  2513
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2514
        # 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
  2515
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2516
    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
  2517
        for r in parents:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2518
            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
  2519
                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
  2520
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2521
    if repo.ui.debugflag:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2522
        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
  2523
    elif repo.ui.verbose:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  2524
        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
  2525
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2526
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
  2527
    parent, p2 = parents
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2528
    node = ctx.node()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2529
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2530
    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
  2531
    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
  2532
        parent = p2
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2533
    if node == parent:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2534
        pmf = mf
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2535
    else:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2536
        pmf = None
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2537
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2538
    # 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
  2539
    # 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
  2540
    # but not other.
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2541
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2542
    # `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
  2543
    # The mapping is in the form:
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2544
    #   <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
  2545
    names = {}
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2546
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2547
    wlock = repo.wlock()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2548
    try:
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2549
        ## filling of the `names` mapping
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2550
        # 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
  2551
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2552
        m = scmutil.match(repo[None], pats, opts)
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2553
        if not m.always() or node != parent:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2554
            m.bad = lambda x, y: False
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2555
            for abs in repo.walk(m):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2556
                names[abs] = m.rel(abs), m.exact(abs)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2557
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2558
            # walk target manifest to fill `names`
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2559
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2560
            def badfn(path, msg):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2561
                if path in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2562
                    return
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2563
                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
  2564
                    return
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2565
                path_ = path + '/'
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2566
                for f in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2567
                    if f.startswith(path_):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2568
                        return
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2569
                ui.warn("%s: %s\n" % (m.rel(path), msg))
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2570
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2571
            m = scmutil.match(ctx, pats, opts)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2572
            m.bad = badfn
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2573
            for abs in ctx.walk(m):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2574
                if abs not in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2575
                    names[abs] = m.rel(abs), m.exact(abs)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2576
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2577
            # Find status of all file in `names`.
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2578
            m = scmutil.matchfiles(repo, names)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2579
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2580
            changes = repo.status(node1=node, match=m,
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2581
                                  unknown=True, ignored=True, clean=True)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2582
        else:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2583
            changes = repo.status(match=m)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2584
            for kind in changes:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2585
                for abs in kind:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2586
                    names[abs] = m.rel(abs), m.exact(abs)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2587
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2588
            m = scmutil.matchfiles(repo, names)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  2589
23374
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2590
        modified = set(changes.modified)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2591
        added    = set(changes.added)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2592
        removed  = set(changes.removed)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2593
        _deleted = set(changes.deleted)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2594
        unknown  = set(changes.unknown)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2595
        unknown.update(changes.ignored)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2596
        clean    = set(changes.clean)
22610
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  2597
        modadded = set()
22185
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
  2598
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
  2599
        # split between files known in target manifest and the others
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
  2600
        smf = set(mf)
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
  2601
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
  2602
        # determine the exact nature of the deleted changesets
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2603
        deladded = _deleted - smf
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2604
        deleted = _deleted - deladded
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2605
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23101
diff changeset
  2606
        # We need to account for the state of file in the dirstate.
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2607
        #
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23101
diff changeset
  2608
        # Even, when we revert against something else than parent. This will
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2609
        # slightly alter the behavior of revert (doing back up or not, delete
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23101
diff changeset
  2610
        # or just forget etc).
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2611
        if parent == node:
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2612
            dsmodified = modified
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2613
            dsadded = added
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2614
            dsremoved = removed
23403
edf29f9c15f0 revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23101
diff changeset
  2615
            # store all local modifications, useful later for rename detection
edf29f9c15f0 revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23101
diff changeset
  2616
            localchanges = dsmodified | dsadded
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2617
            modified, added, removed = set(), set(), set()
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2618
        else:
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  2619
            changes = repo.status(node1=parent, match=m)
23374
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2620
            dsmodified = set(changes.modified)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2621
            dsadded    = set(changes.added)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  2622
            dsremoved  = set(changes.removed)
23403
edf29f9c15f0 revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23101
diff changeset
  2623
            # store all local modifications, useful later for rename detection
edf29f9c15f0 revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23101
diff changeset
  2624
            localchanges = dsmodified | dsadded
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2625
22188
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  2626
            # only take into account for removes between wc and target
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  2627
            clean |= dsremoved - removed
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  2628
            dsremoved &= removed
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  2629
            # distinct between dirstate remove and other
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  2630
            removed -= dsremoved
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  2631
22610
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  2632
            modadded = added & dsmodified
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  2633
            added -= modadded
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  2634
22190
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  2635
            # tell newly modified apart.
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  2636
            dsmodified &= modified
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  2637
            dsmodified |= modified & dsadded # dirstate added may needs backup
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  2638
            modified -= dsmodified
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  2639
22488
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2640
            # We need to wait for some post-processing to update this set
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2641
            # before making the distinction. The dirstate will be used for
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2642
            # that purpose.
22208
d3659b3795e9 revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22205
diff changeset
  2643
            dsadded = added
d3659b3795e9 revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22205
diff changeset
  2644
22209
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2645
        # in case of merge, files that are actually added can be reported as
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2646
        # modified, we need to post process the result
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2647
        if p2 != nullid:
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2648
            if pmf is None:
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2649
                # only need parent manifest in the merge case,
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2650
                # so do not read by default
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2651
                pmf = repo[parent].manifest()
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2652
            mergeadd = dsmodified - set(pmf)
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2653
            dsadded |= mergeadd
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  2654
            dsmodified -= mergeadd
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2655
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2656
        # 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
  2657
        cwd = repo.getcwd()
23403
edf29f9c15f0 revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23101
diff changeset
  2658
        for f in localchanges:
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2659
            src = repo.dirstate.copied(f)
22213
f1debbcd71cd revert: add an XXX about rename tracking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22212
diff changeset
  2660
            # XXX should we check for rename down to target node?
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2661
            if src and src not in names and repo.dirstate[src] == 'r':
22154
fc422de25773 revert: prefix variable names for dirstate status with "ds"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22153
diff changeset
  2662
                dsremoved.add(src)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2663
                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
  2664
22488
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2665
        # distinguish between file to forget and the other
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2666
        added = set()
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2667
        for abs in dsadded:
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2668
            if repo.dirstate[abs] != 'a':
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2669
                added.add(abs)
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2670
        dsadded -= added
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2671
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2672
        for abs in deladded:
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2673
            if repo.dirstate[abs] == 'a':
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2674
                dsadded.add(abs)
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2675
        deladded -= dsadded
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2676
22396
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2677
        # For files marked as removed, we check if an unknown file is present at
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2678
        # the same path. If a such file exists it may need to be backed up.
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2679
        # Making the distinction at this stage helps have simpler backup
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2680
        # logic.
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2681
        removunk = set()
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2682
        for abs in removed:
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2683
            target = repo.wjoin(abs)
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2684
            if os.path.lexists(target):
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2685
                removunk.add(abs)
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2686
        removed -= removunk
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2687
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2688
        dsremovunk = set()
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2689
        for abs in dsremoved:
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2690
            target = repo.wjoin(abs)
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2691
            if os.path.lexists(target):
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2692
                dsremovunk.add(abs)
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2693
        dsremoved -= dsremovunk
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2694
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2695
        # 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
  2696
        # (<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
  2697
        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
  2698
                   'add': ([], _('adding %s\n')),
22489
0d57bf80c7cb revert: have an explicit action for "forget"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22488
diff changeset
  2699
                   'remove': ([], _('removing %s\n')),
22491
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  2700
                   'drop': ([], _('removing %s\n')),
22489
0d57bf80c7cb revert: have an explicit action for "forget"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22488
diff changeset
  2701
                   'forget': ([], _('forgetting %s\n')),
22231
10d9e7908a3c revert: use actions[...] in all disptable cases
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22230
diff changeset
  2702
                   'undelete': ([], _('undeleting %s\n')),
22234
fe9fc29ac2d0 revert: add a message to noop action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22233
diff changeset
  2703
                   'noop': (None, _('no changes needed to %s\n')),
22236
3c24fb96900f revert: handle unknown files through status
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22235
diff changeset
  2704
                   'unknown': (None, _('file not managed: %s\n')),
22231
10d9e7908a3c revert: use actions[...] in all disptable cases
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22230
diff changeset
  2705
                  }
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2706
22608
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  2707
        # "constant" that convey the backup strategy.
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  2708
        # All set to `discard` if `no-backup` is set do avoid checking
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  2709
        # no_backup lower in the code.
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2710
        # These values are ordered for comparison purposes
22608
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  2711
        backup = 2  # unconditionally do backup
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2712
        check = 1   # check if the existing file differs from target
22608
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  2713
        discard = 0 # never do backup
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  2714
        if opts.get('no_backup'):
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2715
            backup = check = discard
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2716
22611
2ff28e07d7d6 revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22610
diff changeset
  2717
        backupanddel = actions['remove']
2ff28e07d7d6 revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22610
diff changeset
  2718
        if not opts.get('no_backup'):
2ff28e07d7d6 revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22610
diff changeset
  2719
            backupanddel = actions['drop']
2ff28e07d7d6 revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22610
diff changeset
  2720
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2721
        disptable = (
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2722
            # dispatch table:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2723
            #   file state
22153
fc8bc2787528 revert: move manifest membership condition outside of the loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22013
diff changeset
  2724
            #   action
fc8bc2787528 revert: move manifest membership condition outside of the loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22013
diff changeset
  2725
            #   make backup
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2726
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2727
            ## Sets that results that will change file on disk
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2728
            # Modified compared to target, no local change
22372
8da5864dcfda revert: add more padding in the dispatch list
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22371
diff changeset
  2729
            (modified,      actions['revert'],   discard),
22397
1db04829bdc1 revert: distinguish between deleted file and locally modified
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22396
diff changeset
  2730
            # Modified compared to target, but local file is deleted
1db04829bdc1 revert: distinguish between deleted file and locally modified
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22396
diff changeset
  2731
            (deleted,       actions['revert'],   discard),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2732
            # Modified compared to target, local change
22372
8da5864dcfda revert: add more padding in the dispatch list
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22371
diff changeset
  2733
            (dsmodified,    actions['revert'],   backup),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2734
            # Added since target
22488
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2735
            (added,         actions['remove'],   discard),
6c52ed3f888e revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22485
diff changeset
  2736
            # Added in working directory
22489
0d57bf80c7cb revert: have an explicit action for "forget"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22488
diff changeset
  2737
            (dsadded,       actions['forget'],   discard),
22610
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  2738
            # Added since target, have local modification
22611
2ff28e07d7d6 revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22610
diff changeset
  2739
            (modadded,      backupanddel,        backup),
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  2740
            # Added since target but file is missing in working directory
22491
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  2741
            (deladded,      actions['drop'],   discard),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2742
            # Removed since  target, before working copy parent
22396
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2743
            (removed,       actions['add'],      discard),
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2744
            # Same as `removed` but an unknown file exists at the same path
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2745
            (removunk,      actions['add'],      check),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2746
            # Removed since targe, marked as such in working copy parent
22396
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2747
            (dsremoved,     actions['undelete'], discard),
c0213f2cb942 revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22395
diff changeset
  2748
            # Same as `dsremoved` but an unknown file exists at the same path
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2749
            (dsremovunk,    actions['undelete'], check),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2750
            ## the following sets does not result in any file changes
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2751
            # File with no modification
22372
8da5864dcfda revert: add more padding in the dispatch list
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22371
diff changeset
  2752
            (clean,         actions['noop'],     discard),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  2753
            # Existing file, not tracked anywhere
22372
8da5864dcfda revert: add more padding in the dispatch list
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22371
diff changeset
  2754
            (unknown,       actions['unknown'],  discard),
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2755
            )
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2756
22395
67588e47522a revert: cache working context in a variable
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22386
diff changeset
  2757
        wctx = repo[None]
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2758
        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
  2759
            # 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
  2760
            target = repo.wjoin(abs)
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2761
            # search the entry in the dispatch table.
22212
f18aca03ddd9 revert: inline a now useless closure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22211
diff changeset
  2762
            # if the file is in any of these sets, it was touched in the working
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2763
            # directory parent and we are sure it needs to be reverted.
22232
91df98701e9e revert: explode the action tuple in the for loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22231
diff changeset
  2764
            for table, (xlist, msg), dobackup in disptable:
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2765
                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
  2766
                    continue
22233
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2767
                if xlist is not None:
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2768
                    xlist.append(abs)
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2769
                    if dobackup and (backup <= dobackup
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2770
                                     or wctx[abs].cmp(ctx[abs])):
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2771
                            bakname = "%s.orig" % rel
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2772
                            ui.note(_('saving current version of %s as %s\n') %
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2773
                                    (rel, bakname))
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2774
                            if not opts.get('dry_run'):
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  2775
                                util.rename(target, bakname)
22233
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2776
                    if ui.verbose or not exact:
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2777
                        if not isinstance(msg, basestring):
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2778
                            msg = msg(abs)
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2779
                        ui.status(msg % rel)
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  2780
                elif exact:
22234
fe9fc29ac2d0 revert: add a message to noop action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22233
diff changeset
  2781
                    ui.warn(msg % rel)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2782
                break
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  2783
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2784
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2785
        if not opts.get('dry_run'):
23965
6156edaa82aa revert: move prefetch to after the actions logic
Durham Goode <durham@fb.com>
parents: 23955
diff changeset
  2786
            needdata = ('revert', 'add', 'undelete')
6156edaa82aa revert: move prefetch to after the actions logic
Durham Goode <durham@fb.com>
parents: 23955
diff changeset
  2787
            _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata])
6156edaa82aa revert: move prefetch to after the actions logic
Durham Goode <durham@fb.com>
parents: 23955
diff changeset
  2788
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2789
            _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
  2790
22551
8d707da26f9b revert: move targetsubs calculation down to its use
Durham Goode <durham@fb.com>
parents: 22491
diff changeset
  2791
            # get the list of subrepos that must be reverted
8d707da26f9b revert: move targetsubs calculation down to its use
Durham Goode <durham@fb.com>
parents: 22491
diff changeset
  2792
            subrepomatch = scmutil.match(ctx, pats, opts)
8d707da26f9b revert: move targetsubs calculation down to its use
Durham Goode <durham@fb.com>
parents: 22491
diff changeset
  2793
            targetsubs = sorted(s for s in ctx.substate if subrepomatch(s))
8d707da26f9b revert: move targetsubs calculation down to its use
Durham Goode <durham@fb.com>
parents: 22491
diff changeset
  2794
16429
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2795
            if targetsubs:
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2796
                # Revert the subrepos on the revert list
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16381
diff changeset
  2797
                for sub in targetsubs:
23579
e1c39f207719 subrepo: drop the 'ui' parameter to revert()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23578
diff changeset
  2798
                    ctx.sub(sub).revert(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
  2799
    finally:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2800
        wlock.release()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  2801
22370
45e02cfad4bd revert: add a way for external extensions to prefetch file data
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22305
diff changeset
  2802
def _revertprefetch(repo, ctx, *files):
45e02cfad4bd revert: add a way for external extensions to prefetch file data
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22305
diff changeset
  2803
    """Let extension changing the storage layer prefetch content"""
45e02cfad4bd revert: add a way for external extensions to prefetch file data
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22305
diff changeset
  2804
    pass
45e02cfad4bd revert: add a way for external extensions to prefetch file data
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22305
diff changeset
  2805
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2806
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
  2807
    """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
  2808
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2809
    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
  2810
    the imminent revert.
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2811
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20790
diff changeset
  2812
    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
  2813
    """
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2814
    parent, p2 = parents
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2815
    node = ctx.node()
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2816
    def checkout(f):
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2817
        fc = ctx[f]
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2818
        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
  2819
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2820
    audit_path = pathutil.pathauditor(repo.root)
22489
0d57bf80c7cb revert: have an explicit action for "forget"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22488
diff changeset
  2821
    for f in actions['forget'][0]:
0d57bf80c7cb revert: have an explicit action for "forget"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22488
diff changeset
  2822
        repo.dirstate.drop(f)
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2823
    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
  2824
        audit_path(f)
22491
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  2825
        util.unlinkpath(repo.wjoin(f))
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  2826
        repo.dirstate.remove(f)
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  2827
    for f in actions['drop'][0]:
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  2828
        audit_path(f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2829
        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
  2830
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2831
    normal = None
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2832
    if node == parent:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2833
        # 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
  2834
        # 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
  2835
        # 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
  2836
        if p2 != nullid:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2837
            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
  2838
        else:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2839
            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
  2840
    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
  2841
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2842
        if normal:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2843
            normal(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2844
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2845
    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
  2846
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2847
        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
  2848
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2849
    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
  2850
    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
  2851
        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
  2852
    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
  2853
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2854
        normal(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2855
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  2856
    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
  2857
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  2858
    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
  2859
        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
  2860
            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
  2861
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2862
def command(table):
21766
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2863
    """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
  2864
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2865
    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
  2866
    be a dict.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2867
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2868
    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
  2869
    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
  2870
    a command.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2871
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2872
    The first argument is the command name.
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2873
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2874
    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
  2875
    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
  2876
21766
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2877
    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
  2878
    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
  2879
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2880
    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
  2881
    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
  2882
    default is False.
21774
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2883
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2884
    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
  2885
    a local repository.
21777
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2886
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2887
    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
  2888
    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
  2889
    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
  2890
    will be used.
21766
a039e1f2326f cmdutil: better document command()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
  2891
    """
21777
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2892
    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
  2893
            inferrepo=False):
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2894
        def decorator(func):
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2895
            if synopsis:
18235
9807e7d596c3 cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18206
diff changeset
  2896
                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
  2897
            else:
18235
9807e7d596c3 cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18206
diff changeset
  2898
                table[name] = func, list(options)
21767
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2899
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2900
            if norepo:
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2901
                # Avoid import cycle.
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2902
                import commands
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2903
                commands.norepo += ' %s' % ' '.join(parsealiases(name))
75a96326cecb commands: add norepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21766
diff changeset
  2904
21774
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2905
            if optionalrepo:
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2906
                import commands
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2907
                commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
b280d0b60bc3 cmdutil: add optionalrepo argument to command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21767
diff changeset
  2908
21777
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2909
            if inferrepo:
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2910
                import commands
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2911
                commands.inferrepo += ' %s' % ' '.join(parsealiases(name))
17d1ac452127 cmdutil: support inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21774
diff changeset
  2912
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2913
            return func
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2914
        return decorator
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2915
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  2916
    return cmd
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  2917
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2918
# 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
  2919
# 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
  2920
# "findcommonoutgoing()"
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2921
outgoinghooks = util.hooks()
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  2922
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  2923
# 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
  2924
summaryhooks = util.hooks()
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2925
21047
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2926
# 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
  2927
#
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2928
# 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
  2929
#  (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
  2930
#
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2931
# 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
  2932
#  - (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
  2933
#  - (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
  2934
summaryremotehooks = util.hooks()
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  2935
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2936
# 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
  2937
# 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
  2938
# note: bisect is intentionally excluded
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2939
# (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
  2940
unfinishedstates = [
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2941
    ('graftstate', True, False, _('graft in progress'),
19482
499fc471296b update: add tracking of interrupted updates (issue3113)
Matt Mackall <mpm@selenic.com>
parents: 19474
diff changeset
  2942
     _("use 'hg graft --continue' or 'hg update' to abort")),
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2943
    ('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
  2944
     _("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
  2945
    ]
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2946
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2947
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
  2948
    '''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
  2949
    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
  2950
    bailifchanged().
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2951
    '''
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2952
    for f, clearable, allowcommit, msg, hint in unfinishedstates:
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2953
        if commit and allowcommit:
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2954
            continue
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2955
        if repo.vfs.exists(f):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2956
            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
  2957
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2958
def clearunfinished(repo):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2959
    '''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
  2960
    that are clearable.
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  2961
    '''
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2962
    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
  2963
        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
  2964
            raise util.Abort(msg, hint=hint)
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  2965
    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
  2966
        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
  2967
            util.unlink(repo.join(f))