mercurial/cmdutil.py
author Yuya Nishihara <yuya@tcha.org>
Sat, 17 Jun 2017 16:32:20 +0900
changeset 32951 050efe9a1644
parent 32947 3f07f12c6e10
child 32953 6d79e9109908
permissions -rw-r--r--
changeset_templater: backport separator template from formatter As commented, this should be used with docheader and docfooter, not with header nor footer. That's one reason why no props are passed to templater when rendering a separator. (See map-cmdline.changelog to understand what the "header" is.)
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
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
     8
from __future__ import absolute_import
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
     9
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    10
import errno
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31698
diff changeset
    11
import itertools
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    12
import os
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    13
import re
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    14
import tempfile
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    15
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    16
from .i18n import _
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    17
from .node import (
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    18
    hex,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    19
    nullid,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    20
    nullrev,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    21
    short,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    22
)
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    23
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    24
from . import (
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    25
    bookmarks,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    26
    changelog,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    27
    copies,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    28
    crecord as crecordmod,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    29
    encoding,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    30
    error,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    31
    formatter,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    32
    graphmod,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    33
    match as matchmod,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    34
    obsolete,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    35
    patch,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    36
    pathutil,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    37
    phases,
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30506
diff changeset
    38
    pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32327
diff changeset
    39
    registrar,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    40
    repair,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    41
    revlog,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    42
    revset,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    43
    scmutil,
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
    44
    smartset,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    45
    templatekw,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    46
    templater,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    47
    util,
31237
1b08aca7870a vfs: use 'vfs' module directly in 'mercurial.cmdutil'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    48
    vfs as vfsmod,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
    49
)
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28837
diff changeset
    50
stringio = util.stringio
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    51
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    52
# templates of common command options
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    53
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    54
dryrunopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    55
    ('n', 'dry-run', None,
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    56
     _('do not perform actions, just print output')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    57
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    58
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    59
remoteopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    60
    ('e', 'ssh', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    61
     _('specify ssh command to use'), _('CMD')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    62
    ('', 'remotecmd', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    63
     _('specify hg command to run on the remote side'), _('CMD')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    64
    ('', 'insecure', None,
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    65
     _('do not verify server certificate (ignoring web.cacerts config)')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    66
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    67
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    68
walkopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    69
    ('I', 'include', [],
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    70
     _('include names matching the given patterns'), _('PATTERN')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    71
    ('X', 'exclude', [],
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    72
     _('exclude names matching the given patterns'), _('PATTERN')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    73
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    74
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    75
commitopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    76
    ('m', 'message', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    77
     _('use text as commit message'), _('TEXT')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    78
    ('l', 'logfile', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    79
     _('read commit message from file'), _('FILE')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    80
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    81
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    82
commitopts2 = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    83
    ('d', 'date', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    84
     _('record the specified date as commit date'), _('DATE')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    85
    ('u', 'user', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    86
     _('record the specified user as committer'), _('USER')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    87
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    88
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    89
# hidden for now
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    90
formatteropts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    91
    ('T', 'template', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    92
     _('display with template (EXPERIMENTAL)'), _('TEMPLATE')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    93
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    94
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    95
templateopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    96
    ('', 'style', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    97
     _('display using template map file (DEPRECATED)'), _('STYLE')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    98
    ('T', 'template', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
    99
     _('display with template'), _('TEMPLATE')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   100
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   101
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   102
logopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   103
    ('p', 'patch', None, _('show patch')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   104
    ('g', 'git', None, _('use git extended diff format')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   105
    ('l', 'limit', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   106
     _('limit number of changes displayed'), _('NUM')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   107
    ('M', 'no-merges', None, _('do not show merges')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   108
    ('', 'stat', None, _('output diffstat-style summary of changes')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   109
    ('G', 'graph', None, _("show the revision DAG")),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   110
] + templateopts
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   111
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   112
diffopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   113
    ('a', 'text', None, _('treat all files as text')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   114
    ('g', 'git', None, _('use git extended diff format')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   115
    ('', 'binary', None, _('generate binary diffs in git mode (default)')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   116
    ('', 'nodates', None, _('omit dates from diff headers'))
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   117
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   118
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   119
diffwsopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   120
    ('w', 'ignore-all-space', None,
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   121
     _('ignore white space when comparing lines')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   122
    ('b', 'ignore-space-change', None,
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   123
     _('ignore changes in the amount of white space')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   124
    ('B', 'ignore-blank-lines', None,
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   125
     _('ignore changes whose lines are all blank')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   126
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   127
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   128
diffopts2 = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   129
    ('', 'noprefix', None, _('omit a/ and b/ prefixes from filenames')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   130
    ('p', 'show-function', None, _('show which function each change is in')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   131
    ('', 'reverse', None, _('produce a diff that undoes the changes')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   132
] + diffwsopts + [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   133
    ('U', 'unified', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   134
     _('number of lines of context to show'), _('NUM')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   135
    ('', 'stat', None, _('output diffstat-style summary of changes')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   136
    ('', 'root', '', _('produce diffs relative to subdirectory'), _('DIR')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   137
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   138
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   139
mergetoolopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   140
    ('t', 'tool', '', _('specify merge tool')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   141
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   142
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   143
similarityopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   144
    ('s', 'similarity', '',
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   145
     _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY'))
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   146
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   147
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   148
subrepoopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   149
    ('S', 'subrepos', None,
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   150
     _('recurse into subrepositories'))
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   151
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   152
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   153
debugrevlogopts = [
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   154
    ('c', 'changelog', False, _('open changelog')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   155
    ('m', 'manifest', False, _('open manifest')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   156
    ('', 'dir', '', _('open directory manifest')),
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   157
]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32362
diff changeset
   158
30703
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
   159
# special string such that everything below this line will be ingored in the
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
   160
# editor text
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
   161
_linebelow = "^HG: ------------------------ >8 ------------------------$"
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
   162
25256
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
   163
def ishunk(x):
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
   164
    hunkclasses = (crecordmod.uihunk, patch.recordhunk)
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
   165
    return isinstance(x, hunkclasses)
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
   166
25257
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   167
def newandmodified(chunks, originalchunks):
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   168
    newlyaddedandmodifiedfiles = set()
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   169
    for chunk in chunks:
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   170
        if ishunk(chunk) and chunk.header.isnewfile() and chunk not in \
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   171
            originalchunks:
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   172
            newlyaddedandmodifiedfiles.add(chunk.header.filename())
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   173
    return newlyaddedandmodifiedfiles
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   174
10401
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
   175
def parsealiases(cmd):
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
   176
    return cmd.lstrip("^").split("|")
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
   177
24356
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   178
def setupwrapcolorwrite(ui):
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   179
    # wrap ui.write so diff output can be labeled/colorized
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   180
    def wrapwrite(orig, *args, **kw):
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   181
        label = kw.pop('label', '')
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   182
        for chunk, l in patch.difflabel(lambda: args):
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   183
            orig(chunk, label=label + l)
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   184
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   185
    oldwrite = ui.write
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   186
    def wrap(*args, **kwargs):
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   187
        return wrapwrite(oldwrite, *args, **kwargs)
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   188
    setattr(ui, 'write', wrap)
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   189
    return oldwrite
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
   190
25310
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   191
def filterchunks(ui, originalhunks, usecurses, testfile, operation=None):
24343
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   192
    if usecurses:
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   193
        if testfile:
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   194
            recordfn = crecordmod.testdecorator(testfile,
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   195
                                                crecordmod.testchunkselector)
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   196
        else:
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   197
            recordfn = crecordmod.chunkselector
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   198
30534
c01033fb9864 revert: pass operation to crecord
Jun Wu <quark@fb.com>
parents: 30532
diff changeset
   199
        return crecordmod.filterpatch(ui, originalhunks, recordfn, operation)
24343
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   200
69538481ea9f record: enable curses recording logic with experimental flag
Laurent Charignon <lcharignon@fb.com>
parents: 24341
diff changeset
   201
    else:
25310
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   202
        return patch.filterpatch(ui, originalhunks, operation)
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   203
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   204
def recordfilter(ui, originalhunks, operation=None):
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   205
    """ Prompts the user to filter the originalhunks and return a list of
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   206
    selected hunks.
29326
d48fc6f318a3 patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 29283
diff changeset
   207
    *operation* is used for to build ui messages to indicate the user what
d48fc6f318a3 patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 29283
diff changeset
   208
    kind of filtering they are doing: reverting, committing, shelving, etc.
d48fc6f318a3 patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 29283
diff changeset
   209
    (see patch.filterpatch).
25310
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
   210
    """
27531
84d686cb62c4 cmdutil: use crecordmod.checkcurses
Sean Farley <sean@farley.io>
parents: 27370
diff changeset
   211
    usecurses = crecordmod.checkcurses(ui)
24357
2da601ab3125 record: refactor the filtering code
Laurent Charignon <lcharignon@fb.com>
parents: 24356
diff changeset
   212
    testfile = ui.config('experimental', 'crecordtest', None)
24358
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
   213
    oldwrite = setupwrapcolorwrite(ui)
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
   214
    try:
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 27148
diff changeset
   215
        newchunks, newopts = filterchunks(ui, originalhunks, usecurses,
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 27148
diff changeset
   216
                                          testfile, operation)
24358
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
   217
    finally:
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
   218
        ui.write = oldwrite
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 27148
diff changeset
   219
    return newchunks, newopts
24357
2da601ab3125 record: refactor the filtering code
Laurent Charignon <lcharignon@fb.com>
parents: 24356
diff changeset
   220
24309
fefcafda10b8 record: change interface of dorecord to accept new filters
Laurent Charignon <lcharignon@fb.com>
parents: 24306
diff changeset
   221
def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
fefcafda10b8 record: change interface of dorecord to accept new filters
Laurent Charignon <lcharignon@fb.com>
parents: 24306
diff changeset
   222
            filterfn, *pats, **opts):
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
   223
    from . import merge as mergemod
32144
93155367a2a6 py3: convert opts to bytes in cmdutil.dorecord()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32046
diff changeset
   224
    opts = pycompat.byteskwargs(opts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   225
    if not ui.interactive():
25795
69145daacdfa cmdutil: allow callers of cmdutil.dorecord to omit suggestion
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25763
diff changeset
   226
        if cmdsuggest:
69145daacdfa cmdutil: allow callers of cmdutil.dorecord to omit suggestion
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25763
diff changeset
   227
            msg = _('running non-interactively, use %s instead') % cmdsuggest
69145daacdfa cmdutil: allow callers of cmdutil.dorecord to omit suggestion
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25763
diff changeset
   228
        else:
69145daacdfa cmdutil: allow callers of cmdutil.dorecord to omit suggestion
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25763
diff changeset
   229
            msg = _('running non-interactively')
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   230
        raise error.Abort(msg)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   231
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   232
    # make sure username is set before going interactive
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   233
    if not opts.get('user'):
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   234
        ui.username() # raise exception, username not provided
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   235
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   236
    def recordfunc(ui, repo, message, match, opts):
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   237
        """This is generic record driver.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   238
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   239
        Its job is to interactively filter local changes, and
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   240
        accordingly prepare working directory into a state in which the
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   241
        job can be delegated to a non-interactive commit command such as
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   242
        'commit' or 'qrefresh'.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   243
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   244
        After the actual job is done by non-interactive command, the
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   245
        working directory is restored to its original state.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   246
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   247
        In the end we'll record interesting changes, and everything else
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   248
        will be left in place, so the user can continue working.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   249
        """
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   250
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   251
        checkunfinished(repo, commit=True)
28815
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   252
        wctx = repo[None]
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   253
        merge = len(wctx.parents()) > 1
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   254
        if merge:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   255
            raise error.Abort(_('cannot partially commit a merge '
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   256
                               '(use "hg commit" instead)'))
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   257
28815
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   258
        def fail(f, msg):
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   259
            raise error.Abort('%s: %s' % (f, msg))
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   260
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   261
        force = opts.get('force')
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   262
        if not force:
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   263
            vdirs = []
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   264
            match.explicitdir = vdirs.append
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   265
            match.bad = fail
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   266
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   267
        status = repo.status(match=match)
28815
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   268
        if not force:
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
   269
            repo.checkcommitpatterns(wctx, vdirs, match, status, fail)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   270
        diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   271
        diffopts.nodates = True
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   272
        diffopts.git = True
27411
c84a07530040 record: turn on showfunc
timeless <timeless@mozdev.org>
parents: 27391
diff changeset
   273
        diffopts.showfunc = True
27637
b502138f5faa cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents: 27625
diff changeset
   274
        originaldiff = patch.diff(repo, changes=status, opts=diffopts)
24341
616c01b69898 record: change interface of the filtering function
Laurent Charignon <lcharignon@fb.com>
parents: 24311
diff changeset
   275
        originalchunks = patch.parsepatch(originaldiff)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   276
28570
5508cf9a52fe crecord: rewrite a comment about filtering patches
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28452
diff changeset
   277
        # 1. filter patch, since we are intending to apply subset of it
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   278
        try:
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 27148
diff changeset
   279
            chunks, newopts = filterfn(ui, originalchunks)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
   280
        except patch.PatchError as err:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   281
            raise error.Abort(_('error parsing patch: %s') % err)
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 27148
diff changeset
   282
        opts.update(newopts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   283
24845
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
   284
        # We need to keep a backup of files that have been newly added and
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
   285
        # modified during the recording process because there is a previous
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
   286
        # version without the edit in the workdir
25257
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
   287
        newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   288
        contenders = set()
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   289
        for h in chunks:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   290
            try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   291
                contenders.update(set(h.files()))
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   292
            except AttributeError:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   293
                pass
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   294
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   295
        changed = status.modified + status.added + status.removed
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   296
        newfiles = [f for f in changed if f in contenders]
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   297
        if not newfiles:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   298
            ui.status(_('no changes to record\n'))
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   299
            return 0
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   300
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   301
        modified = set(status.modified)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   302
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   303
        # 2. backup changed files, so we can restore them in the end
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   304
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   305
        if backupall:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   306
            tobackup = changed
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   307
        else:
24845
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
   308
            tobackup = [f for f in newfiles if f in modified or f in \
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
   309
                    newlyaddedandmodifiedfiles]
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   310
        backups = {}
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   311
        if tobackup:
31320
1b0db28dadf1 cmdutil: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31309
diff changeset
   312
            backupdir = repo.vfs.join('record-backups')
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   313
            try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   314
                os.mkdir(backupdir)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
   315
            except OSError as err:
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   316
                if err.errno != errno.EEXIST:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   317
                    raise
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   318
        try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   319
            # backup continues
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   320
            for f in tobackup:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   321
                fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.',
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   322
                                               dir=backupdir)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   323
                os.close(fd)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   324
                ui.debug('backup %r as %r\n' % (f, tmpname))
27370
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
   325
                util.copyfile(repo.wjoin(f), tmpname, copystat=True)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   326
                backups[f] = tmpname
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   327
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28837
diff changeset
   328
            fp = stringio()
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   329
            for c in chunks:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   330
                fname = c.filename()
24837
edf907bd8144 record: fix record with change on moved file crashes (issue4619)
Laurent Charignon <lcharignon@fb.com>
parents: 24720
diff changeset
   331
                if fname in backups:
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   332
                    c.write(fp)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   333
            dopatch = fp.tell()
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   334
            fp.seek(0)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   335
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   336
            # 2.5 optionally review / modify patch in text editor
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   337
            if opts.get('review', False):
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   338
                patchtext = (crecordmod.diffhelptext
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   339
                             + crecordmod.patchhelptext
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   340
                             + fp.read())
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   341
                reviewedpatch = ui.edit(patchtext, "",
30836
565c07036066 cmdutil: add tmpdir parament to ui.edit calls
Sean Farley <sean@farley.io>
parents: 30833
diff changeset
   342
                                        extra={"suffix": ".diff"},
30848
7080652af6e6 ui: rename tmpdir parameter to more specific repopath
Sean Farley <sean@farley.io>
parents: 30836
diff changeset
   343
                                        repopath=repo.path)
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   344
                fp.truncate(0)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   345
                fp.write(reviewedpatch)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   346
                fp.seek(0)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
   347
24866
e1ec3d075c67 record: fix adding new file with record from within a subdir (issue4626)
Laurent Charignon <lcharignon@fb.com>
parents: 24864
diff changeset
   348
            [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles]
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   349
            # 3a. apply filtered patch to clean repo  (clean)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   350
            if backups:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   351
                # Equivalent to hg.revert
27344
43c00ca887d1 merge: have merge.update use a matcher instead of partial fn
Augie Fackler <augie@google.com>
parents: 27216
diff changeset
   352
                m = scmutil.matchfiles(repo, backups.keys())
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   353
                mergemod.update(repo, repo.dirstate.p1(),
27344
43c00ca887d1 merge: have merge.update use a matcher instead of partial fn
Augie Fackler <augie@google.com>
parents: 27216
diff changeset
   354
                        False, True, matcher=m)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   355
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   356
            # 3b. (apply)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   357
            if dopatch:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   358
                try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   359
                    ui.debug('applying patch\n')
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   360
                    ui.debug(fp.getvalue())
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   361
                    patch.internalpatch(ui, repo, fp, 1, eolmode=None)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
   362
                except patch.PatchError as err:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   363
                    raise error.Abort(str(err))
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   364
            del fp
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   365
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   366
            # 4. We prepared working directory according to filtered
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   367
            #    patch. Now is the time to delegate the job to
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   368
            #    commit/qrefresh or the like!
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   369
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   370
            # Make all of the pathnames absolute.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   371
            newfiles = [repo.wjoin(nf) for nf in newfiles]
24476
1378f20c8564 record: change return value of recording code
Laurent Charignon <lcharignon@fb.com>
parents: 24475
diff changeset
   372
            return commitfunc(ui, repo, *newfiles, **opts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   373
        finally:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   374
            # 5. finally restore backed-up files
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   375
            try:
25759
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   376
                dirstate = repo.dirstate
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   377
                for realname, tmpname in backups.iteritems():
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   378
                    ui.debug('restoring %r to %r\n' % (tmpname, realname))
25759
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   379
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   380
                    if dirstate[realname] == 'n':
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   381
                        # without normallookup, restoring timestamp
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   382
                        # may cause partially committed files
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   383
                        # to be treated as unmodified
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   384
                        dirstate.normallookup(realname)
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
   385
27370
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
   386
                    # copystat=True here and above are a hack to trick any
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
   387
                    # editors that have f open that we haven't modified them.
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   388
                    #
27370
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
   389
                    # Also note that this racy as an editor could notice the
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
   390
                    # file's mtime before we've finished writing it.
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
   391
                    util.copyfile(tmpname, repo.wjoin(realname), copystat=True)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   392
                    os.unlink(tmpname)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   393
                if tobackup:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   394
                    os.rmdir(backupdir)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   395
            except OSError:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   396
                pass
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   397
25758
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
   398
    def recordinwlock(ui, repo, message, match, opts):
27801
7be6371c732e with: use context manager for wlock in recordinwlock
Bryan O'Sullivan <bryano@fb.com>
parents: 27698
diff changeset
   399
        with repo.wlock():
25758
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
   400
            return recordfunc(ui, repo, message, match, opts)
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
   401
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
   402
    return commit(ui, repo, recordinwlock, pats, opts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
   403
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
   404
def findpossible(cmd, table, strict=False):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   405
    """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   406
    Return cmd -> (aliases, command table entry)
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   407
    for each matching command.
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   408
    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
   409
    """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   410
    choice = {}
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   411
    debugchoice = {}
15600
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   412
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   413
    if cmd in table:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   414
        # 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
   415
        keys = [cmd]
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   416
    else:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   417
        keys = table.keys()
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   418
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
   419
    allcmds = []
15600
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
   420
    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
   421
        aliases = parsealiases(e)
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
   422
        allcmds.extend(aliases)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   423
        found = None
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   424
        if cmd in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   425
            found = cmd
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
   426
        elif not strict:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   427
            for a in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   428
                if a.startswith(cmd):
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   429
                    found = a
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   430
                    break
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   431
        if found is not None:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   432
            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
   433
                debugchoice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   434
            else:
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5177
diff changeset
   435
                choice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   436
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   437
    if not choice and debugchoice:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   438
        choice = debugchoice
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   439
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
   440
    return choice, allcmds
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   441
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
   442
def findcmd(cmd, table, strict=True):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   443
    """Return (aliases, command table entry) for command string."""
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
   444
    choice, allcmds = findpossible(cmd, table, strict)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   445
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5843
diff changeset
   446
    if cmd in choice:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   447
        return choice[cmd]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   448
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   449
    if len(choice) > 1:
32528
9f56d462634c cmdutil: use sorted(dict) instead of x = dict.keys(); x.sort()
Augie Fackler <raf@durin42.com>
parents: 32434
diff changeset
   450
        clist = sorted(choice)
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7404
diff changeset
   451
        raise error.AmbiguousCommand(cmd, clist)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   452
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   453
    if choice:
32862
e4a43b810528 py3: explicitly convert dict.values() to a list on py3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32842
diff changeset
   454
        return list(choice.values())[0]
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   455
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
   456
    raise error.UnknownCommand(cmd, allcmds)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   457
10402
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
   458
def findrepo(p):
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
   459
    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
   460
        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
   461
        if p == oldp:
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
   462
            return None
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
   463
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
   464
    return p
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
   465
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   466
def bailifchanged(repo, merge=True, hint=None):
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   467
    """ enforce the precondition that working directory must be clean.
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   468
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   469
    'merge' can be set to false if a pending uncommitted merge should be
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   470
    ignored (such as when 'update --check' runs).
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   471
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   472
    'hint' is the usual hint given to Abort exception.
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   473
    """
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   474
24472
1bf71faf042e cmdutil: allow bailifchanged to ignore merging in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24471
diff changeset
   475
    if merge and repo.dirstate.p2() != nullid:
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   476
        raise error.Abort(_('outstanding uncommitted merge'), hint=hint)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   477
    modified, added, removed, deleted = repo.status()[:4]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   478
    if modified or added or removed or deleted:
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   479
        raise error.Abort(_('uncommitted changes'), hint=hint)
15231
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
   480
    ctx = repo[None]
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
   481
    for s in sorted(ctx.substate):
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
   482
        ctx.sub(s).bailifchanged(hint=hint)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   483
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
   484
def logmessage(ui, opts):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   485
    """ 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
   486
    message = opts.get('message')
bd5c37d792e6 cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7643
diff changeset
   487
    logfile = opts.get('logfile')
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   488
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   489
    if message and logfile:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   490
        raise error.Abort(_('options --message and --logfile are mutually '
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   491
                           'exclusive'))
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   492
    if not message and logfile:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   493
        try:
32618
d3e1c5b4986c cmdutil: use isstdiofilename() where appropriate
Yuya Nishihara <yuya@tcha.org>
parents: 32584
diff changeset
   494
            if isstdiofilename(logfile):
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
   495
                message = ui.fin.read()
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   496
            else:
14249
f4766e1bb0b3 cmdutil: normalize log message eols when reading from file
Patrick Mezard <pmezard@gmail.com>
parents: 14232
diff changeset
   497
                message = '\n'.join(util.readfile(logfile).splitlines())
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
   498
        except IOError as inst:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   499
            raise error.Abort(_("can't read commit message '%s': %s") %
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   500
                             (logfile, inst.strerror))
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   501
    return message
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
   502
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   503
def mergeeditform(ctxorbool, baseformname):
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   504
    """return appropriate editform name (referencing a committemplate)
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   505
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   506
    'ctxorbool' is either a ctx to be committed, or a bool indicating whether
22248
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   507
    merging is committed.
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   508
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   509
    This returns baseformname with '.merge' appended if it is a merge,
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   510
    otherwise '.normal' is appended.
22248
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   511
    """
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   512
    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
   513
        if ctxorbool:
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   514
            return baseformname + ".merge"
22248
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   515
    elif 1 < len(ctxorbool.parents()):
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   516
        return baseformname + ".merge"
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   517
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
   518
    return baseformname + ".normal"
22248
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
   519
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   520
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
   521
                    editform='', **opts):
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   522
    """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
   523
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   524
    '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
   525
    (= '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
   526
    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
   527
    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
   528
    storing.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   529
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   530
    '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
   531
    '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
   532
    is automatically added.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   533
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
   534
    '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
   535
    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
   536
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   537
    '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
   538
    '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
   539
    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
   540
    """
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
   541
    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
   542
        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
   543
                                                 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
   544
                                                 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
   545
                                                 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
   546
    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
   547
        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
   548
    else:
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   549
        return commiteditor
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
   550
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   551
def loglimit(opts):
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   552
    """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
   553
    limit = opts.get('limit')
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   554
    if limit:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   555
        try:
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   556
            limit = int(limit)
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   557
        except ValueError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   558
            raise error.Abort(_('limit must be a positive integer'))
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   559
        if limit <= 0:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   560
            raise error.Abort(_('limit must be positive'))
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   561
    else:
10111
27457d31ae3f cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10061
diff changeset
   562
        limit = None
6190
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   563
    return limit
a79d9408806f Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6145
diff changeset
   564
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   565
def makefilename(repo, pat, node, desc=None,
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   566
                  total=None, seqno=None, revwidth=None, pathname=None):
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   567
    node_expander = {
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   568
        'H': lambda: hex(node),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   569
        'R': lambda: str(repo.changelog.rev(node)),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   570
        '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
   571
        'm': lambda: re.sub('[^\w]', '_', str(desc))
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   572
        }
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   573
    expander = {
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   574
        '%': lambda: '%',
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   575
        'b': lambda: os.path.basename(repo.root),
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   576
        }
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   577
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   578
    try:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   579
        if node:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   580
            expander.update(node_expander)
4836
0e2d0a78f81a archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4825
diff changeset
   581
        if node:
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   582
            expander['r'] = (lambda:
4836
0e2d0a78f81a archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4825
diff changeset
   583
                    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
   584
        if total is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   585
            expander['N'] = lambda: str(total)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   586
        if seqno is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   587
            expander['n'] = lambda: str(seqno)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   588
        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
   589
            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
   590
        if pathname is not None:
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   591
            expander['s'] = lambda: os.path.basename(pathname)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   592
            expander['d'] = lambda: os.path.dirname(pathname) or '.'
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   593
            expander['p'] = lambda: pathname
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   594
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   595
        newname = []
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   596
        patlen = len(pat)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   597
        i = 0
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   598
        while i < patlen:
32153
6f173560c7f4 py3: slice over bytes to prevent getting ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32147
diff changeset
   599
            c = pat[i:i + 1]
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   600
            if c == '%':
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   601
                i += 1
32153
6f173560c7f4 py3: slice over bytes to prevent getting ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32147
diff changeset
   602
                c = pat[i:i + 1]
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   603
                c = expander[c]()
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   604
            newname.append(c)
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   605
            i += 1
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   606
        return ''.join(newname)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
   607
    except KeyError as inst:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   608
        raise error.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
   609
                         inst.args[0])
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   610
32539
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32538
diff changeset
   611
def isstdiofilename(pat):
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32538
diff changeset
   612
    """True if the given pat looks like a filename denoting stdin/stdout"""
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32538
diff changeset
   613
    return not pat or pat == '-'
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32538
diff changeset
   614
27418
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   615
class _unclosablefile(object):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   616
    def __init__(self, fp):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   617
        self._fp = fp
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   618
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   619
    def close(self):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   620
        pass
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   621
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   622
    def __iter__(self):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   623
        return iter(self._fp)
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   624
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   625
    def __getattr__(self, attr):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   626
        return getattr(self._fp, attr)
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
   627
30142
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30016
diff changeset
   628
    def __enter__(self):
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30016
diff changeset
   629
        return self
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30016
diff changeset
   630
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30016
diff changeset
   631
    def __exit__(self, exc_type, exc_value, exc_tb):
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30016
diff changeset
   632
        pass
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30016
diff changeset
   633
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
   634
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
   635
                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
   636
                pathname=None):
7319
eae1767cc6a8 export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7308
diff changeset
   637
13769
8796fb6af67e cmdutil: fix mode handling in make_file
Adrian Buehlmann <adrian@cadifra.com>
parents: 13534
diff changeset
   638
    writable = mode not in ('r', 'rb')
7319
eae1767cc6a8 export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7308
diff changeset
   639
32539
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32538
diff changeset
   640
    if isstdiofilename(pat):
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   641
        if writable:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   642
            fp = repo.ui.fout
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   643
        else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   644
            fp = repo.ui.fin
27419
7e2495bf0ad8 cmdutil: do not duplicate stdout by makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 27418
diff changeset
   645
        return _unclosablefile(fp)
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   646
    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
   647
    if modemap is not None:
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   648
        mode = modemap.get(fn, mode)
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   649
        if mode == 'wb':
b7f76db06dc0 cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents: 19894
diff changeset
   650
            modemap[fn] = 'ab'
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
   651
    return open(fn, mode)
2882
cf98cd70d2c4 move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2874
diff changeset
   652
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   653
def openrevlog(repo, cmd, file_, opts):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   654
    """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
   655
    cl = opts['changelog']
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   656
    mf = opts['manifest']
25119
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   657
    dir = opts['dir']
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   658
    msg = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   659
    if cl and mf:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   660
        msg = _('cannot specify --changelog and --manifest at the same time')
25119
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   661
    elif cl and dir:
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   662
        msg = _('cannot specify --changelog and --dir at the same time')
29427
33a6b750b5b9 debug: make debug{revlog,index,data} --dir not just a flag
Martin von Zweigbergk <martinvonz@google.com>
parents: 29397
diff changeset
   663
    elif cl or mf or dir:
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   664
        if file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   665
            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
   666
        elif not repo:
25119
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   667
            msg = _('cannot specify --changelog or --manifest or --dir '
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   668
                    'without a repository')
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   669
    if msg:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   670
        raise error.Abort(msg)
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   671
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   672
    r = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   673
    if repo:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   674
        if cl:
21033
254f55b64e31 debugrevlog: use unfiltered view for changelog
Matt Mackall <mpm@selenic.com>
parents: 21024
diff changeset
   675
            r = repo.unfiltered().changelog
25119
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   676
        elif dir:
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   677
            if 'treemanifest' not in repo.requirements:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   678
                raise error.Abort(_("--dir can only be used on repos with "
25119
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   679
                                   "treemanifest enabled"))
30371
fccc3eea2ddb manifest: delete unused dirlog and _newmanifest functions
Durham Goode <durham@fb.com>
parents: 30340
diff changeset
   680
            dirlog = repo.manifestlog._revlog.dirlog(dir)
25119
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   681
            if len(dirlog):
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
   682
                r = dirlog
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   683
        elif mf:
30375
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30371
diff changeset
   684
            r = repo.manifestlog._revlog
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   685
        elif file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   686
            filelog = repo.file(file_)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   687
            if len(filelog):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   688
                r = filelog
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   689
    if not r:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   690
        if not file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   691
            raise error.CommandError(cmd, _('invalid arguments'))
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   692
        if not os.path.isfile(file_):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   693
            raise error.Abort(_("revlog '%s' not found") % file_)
31237
1b08aca7870a vfs: use 'vfs' module directly in 'mercurial.cmdutil'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
   694
        r = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False),
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   695
                          file_[:-2] + ".i")
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   696
    return r
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
   697
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
   698
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
   699
    # called with the repo lock held
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   700
    #
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   701
    # hgsep => pathname that uses "/" to separate directories
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   702
    # 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
   703
    cwd = repo.getcwd()
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   704
    targets = {}
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   705
    after = opts.get("after")
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   706
    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
   707
    wctx = repo[None]
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   708
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   709
    def walkpat(pat):
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   710
        srcs = []
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   711
        if after:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   712
            badstates = '?'
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   713
        else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
   714
            badstates = '?r'
32382
c87db79b9507 cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents: 32375
diff changeset
   715
        m = scmutil.match(wctx, [pat], opts, globbed=True)
c87db79b9507 cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents: 32375
diff changeset
   716
        for abs in wctx.walk(m):
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   717
            state = repo.dirstate[abs]
6584
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
   718
            rel = m.rel(abs)
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
   719
            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
   720
            if state in badstates:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   721
                if exact and state == '?':
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   722
                    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
   723
                if exact and state == 'r':
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   724
                    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
   725
                              ' remove\n') % rel)
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   726
                continue
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   727
            # abs: hgsep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   728
            # rel: ossep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   729
            srcs.append((abs, rel, exact))
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   730
        return srcs
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   731
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   732
    # abssrc: hgsep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   733
    # relsrc: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   734
    # otarget: ossep
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   735
    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
   736
        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
   737
        if '/' in abstarget:
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   738
            # 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
   739
            # case only renames, like a => A.
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   740
            abspath, absname = abstarget.rsplit('/', 1)
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
   741
            abstarget = repo.dirstate.normalize(abspath) + '/' + absname
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   742
        reltarget = repo.pathto(abstarget, cwd)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   743
        target = repo.wjoin(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   744
        src = repo.wjoin(abssrc)
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   745
        state = repo.dirstate[abstarget]
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   746
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13945
diff changeset
   747
        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
   748
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   749
        # check for collisions
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   750
        prevsrc = targets.get(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   751
        if prevsrc is not None:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   752
            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
   753
                    (reltarget, repo.pathto(abssrc, cwd),
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   754
                     repo.pathto(prevsrc, cwd)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   755
            return
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   756
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   757
        # check for overwrites
12342
70236d6fd844 rename: do not overwrite existing broken symlinks
Patrick Mezard <pmezard@gmail.com>
parents: 11950
diff changeset
   758
        exists = os.path.lexists(target)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   759
        samefile = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   760
        if exists and abssrc != abstarget:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   761
            if (repo.dirstate.normalize(abssrc) ==
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   762
                repo.dirstate.normalize(abstarget)):
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   763
                if not rename:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   764
                    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
   765
                    return
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   766
                exists = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   767
                samefile = True
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   768
8117
2b30d8488819 remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents: 8013
diff changeset
   769
        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
   770
            if not opts['force']:
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   771
                if state in 'mn':
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   772
                    msg = _('%s: not overwriting - file already committed\n')
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   773
                    if after:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   774
                        flags = '--after --force'
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   775
                    else:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   776
                        flags = '--force'
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   777
                    if rename:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   778
                        hint = _('(hg rename %s to replace the file by '
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   779
                                 'recording a rename)\n') % flags
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   780
                    else:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   781
                        hint = _('(hg copy %s to replace the file by '
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   782
                                 'recording a copy)\n') % flags
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   783
                else:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   784
                    msg = _('%s: not overwriting - file exists\n')
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   785
                    if rename:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   786
                        hint = _('(hg rename --after to record the rename)\n')
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   787
                    else:
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   788
                        hint = _('(hg copy --after to record the copy)\n')
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   789
                ui.warn(msg % reltarget)
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
   790
                ui.warn(hint)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   791
                return
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   792
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   793
        if after:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   794
            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
   795
                if rename:
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   796
                    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
   797
                            (relsrc, reltarget))
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   798
                else:
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
   799
                    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
   800
                            (relsrc, reltarget))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   801
                return
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   802
        elif not dryrun:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   803
            try:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   804
                if exists:
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   805
                    os.unlink(target)
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   806
                targetdir = os.path.dirname(target) or '.'
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   807
                if not os.path.isdir(targetdir):
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   808
                    os.makedirs(targetdir)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   809
                if samefile:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   810
                    tmp = target + "~hgrename"
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   811
                    os.rename(src, tmp)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   812
                    os.rename(tmp, target)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   813
                else:
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   814
                    util.copyfile(src, target)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   815
                srcexists = True
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
   816
            except IOError as inst:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   817
                if inst.errno == errno.ENOENT:
24364
135b23868f45 commands: replace "working copy" with "working directory" in help/messages
Yuya Nishihara <yuya@tcha.org>
parents: 24359
diff changeset
   818
                    ui.warn(_('%s: deleted in working directory\n') % relsrc)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   819
                    srcexists = False
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   820
                else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   821
                    ui.warn(_('%s: cannot copy - %s\n') %
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   822
                            (relsrc, inst.strerror))
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   823
                    return True # report a failure
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   824
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   825
        if ui.verbose or not exact:
7894
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   826
            if rename:
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   827
                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
   828
            else:
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
   829
                ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
   830
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   831
        targets[abstarget] = abssrc
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   832
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   833
        # fix up dirstate
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   834
        scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   835
                             dryrun=dryrun, cwd=cwd)
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
   836
        if rename and not dryrun:
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
   837
            if not after and srcexists and not samefile:
31309
8908f985570c vfs: use repo.wvfs.unlinkpath
Mads Kiilerich <madski@unity3d.com>
parents: 31237
diff changeset
   838
                repo.wvfs.unlinkpath(abssrc)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
   839
            wctx.forget([abssrc])
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   840
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   841
    # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   842
    # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   843
    # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   844
    # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   845
    def targetpathfn(pat, dest, srcs):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   846
        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
   847
            abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   848
            abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   849
            if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   850
                striplen = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   851
            else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   852
                striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   853
            if striplen:
30615
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30534
diff changeset
   854
                striplen += len(pycompat.ossep)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   855
            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
   856
        elif destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   857
            res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   858
                                         os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   859
        else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   860
            res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   861
        return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   862
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   863
    # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   864
    # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   865
    # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   866
    # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   867
    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
   868
        if matchmod.patkind(pat):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   869
            # a mercurial pattern
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   870
            res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   871
                                         os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   872
        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
   873
            abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   874
            if len(abspfx) < len(srcs[0][0]):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   875
                # 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
   876
                # 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
   877
                def evalpath(striplen):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   878
                    score = 0
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   879
                    for s in srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   880
                        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
   881
                        if os.path.lexists(t):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   882
                            score += 1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   883
                    return score
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   884
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   885
                abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   886
                striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   887
                if striplen:
30615
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30534
diff changeset
   888
                    striplen += len(pycompat.ossep)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   889
                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
   890
                    score = evalpath(striplen)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   891
                    striplen1 = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   892
                    if striplen1:
30615
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30534
diff changeset
   893
                        striplen1 += len(pycompat.ossep)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   894
                    if evalpath(striplen1) > score:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   895
                        striplen = striplen1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   896
                res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   897
                                             util.localpath(p)[striplen:])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   898
            else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   899
                # a file
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   900
                if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   901
                    res = lambda p: os.path.join(dest,
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   902
                                        os.path.basename(util.localpath(p)))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   903
                else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   904
                    res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   905
        return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   906
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
   907
    pats = scmutil.expandpats(pats)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   908
    if not pats:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   909
        raise error.Abort(_('no source or destination specified'))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   910
    if len(pats) == 1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   911
        raise error.Abort(_('no destination specified'))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   912
    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
   913
    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
   914
    if not destdirexists:
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 12032
diff changeset
   915
        if len(pats) > 1 or matchmod.patkind(pats[0]):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   916
            raise error.Abort(_('with multiple sources, destination must be an '
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   917
                               '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
   918
        if util.endswithsep(dest):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   919
            raise error.Abort(_('destination %s is not a directory') % dest)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   920
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   921
    tfn = targetpathfn
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
   922
    if after:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   923
        tfn = targetpathafterfn
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   924
    copylist = []
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   925
    for pat in pats:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   926
        srcs = walkpat(pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   927
        if not srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   928
            continue
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   929
        copylist.append((tfn(pat, dest, srcs), srcs))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   930
    if not copylist:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
   931
        raise error.Abort(_('no files to copy'))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   932
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   933
    errors = 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   934
    for targetpath, srcs in copylist:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
   935
        for abssrc, relsrc, exact in srcs:
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   936
            if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
   937
                errors += 1
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   938
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   939
    if errors:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   940
        ui.warn(_('(consider using --after)\n'))
5609
a783d3627144 copy: move rename logic
Matt Mackall <mpm@selenic.com>
parents: 5608
diff changeset
   941
11177
6a64813276ed commands: initial audit of exit codes
Matt Mackall <mpm@selenic.com>
parents: 11152
diff changeset
   942
    return errors != 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
   943
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   944
## facility to let extension process additional data into an import patch
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   945
# list of identifier to be executed in order
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   946
extrapreimport = []  # run before commit
26562
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
   947
extrapostimport = [] # run after commit
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   948
# mapping from identifier to actual import function
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   949
#
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   950
# 'preimport' are run before the commit is made and are provided the following
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   951
# arguments:
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   952
# - repo: the localrepository instance,
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   953
# - patchdata: data extracted from patch header (cf m.patch.patchheadermap),
26781
1aee2ab0f902 spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents: 26750
diff changeset
   954
# - extra: the future extra dictionary of the changeset, please mutate it,
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   955
# - opts: the import options.
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   956
# XXX ideally, we would just pass an ctx ready to be computed, that would allow
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   957
# mutation of in memory commit and more. Feel free to rework the code to get
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   958
# there.
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   959
extrapreimportmap = {}
26562
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
   960
# 'postimport' are run after the commit is made and are provided the following
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
   961
# argument:
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
   962
# - ctx: the changectx created by import.
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
   963
extrapostimportmap = {}
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
   964
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   965
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
   966
    """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
   967
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   968
    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
   969
    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
   970
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   971
    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
   972
    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
   973
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   974
    :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
   975
    :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
   976
    :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
   977
    :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
   978
           (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
   979
    :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
   980
                 updatefunc(<repo>, <node>)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   981
    """
25930
221491bbaf7e cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25795
diff changeset
   982
    # avoid cycle context -> subrepo -> cmdutil
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
   983
    from . import context
26547
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   984
    extractdata = patch.extract(ui, hunk)
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   985
    tmpname = extractdata.get('filename')
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   986
    message = extractdata.get('message')
27612
a0dfe8d286fe import: refactor date and user handling
timeless <timeless@mozdev.org>
parents: 27611
diff changeset
   987
    user = opts.get('user') or extractdata.get('user')
a0dfe8d286fe import: refactor date and user handling
timeless <timeless@mozdev.org>
parents: 27611
diff changeset
   988
    date = opts.get('date') or extractdata.get('date')
26547
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   989
    branch = extractdata.get('branch')
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   990
    nodeid = extractdata.get('nodeid')
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   991
    p1 = extractdata.get('p1')
b9be8ab6e628 patch: move 'extract' return to a dictionnary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26545
diff changeset
   992
    p2 = extractdata.get('p2')
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   993
27613
dffd2ed9a7c4 import: refactor nocommit and importbranch handling
timeless <timeless@mozdev.org>
parents: 27612
diff changeset
   994
    nocommit = opts.get('no_commit')
dffd2ed9a7c4 import: refactor nocommit and importbranch handling
timeless <timeless@mozdev.org>
parents: 27612
diff changeset
   995
    importbranch = opts.get('import_branch')
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   996
    update = not opts.get('bypass')
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   997
    strip = opts["strip"]
24259
5ac8ce04baa2 cmdutil.tryimportone: allow importing relative patches into the working dir
Siddharth Agarwal <sid0@fb.com>
parents: 24222
diff changeset
   998
    prefix = opts["prefix"]
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
   999
    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
  1000
    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
  1001
        return (None, None, False)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1002
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
  1003
    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
  1004
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1005
    try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1006
        cmdline_message = logmessage(ui, opts)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1007
        if cmdline_message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1008
            # pickup the cmdline msg
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1009
            message = cmdline_message
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1010
        elif message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1011
            # pickup the patch msg
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1012
            message = message.strip()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1013
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1014
            # launch the editor
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1015
            message = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1016
        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
  1017
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1018
        if len(parents) == 1:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1019
            parents.append(repo[nullid])
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1020
        if opts.get('exact'):
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1021
            if not nodeid or not p1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1022
                raise error.Abort(_('not a Mercurial patch'))
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1023
            p1 = repo[p1]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1024
            p2 = repo[p2 or nullid]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1025
        elif p2:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1026
            try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1027
                p1 = repo[p1]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1028
                p2 = repo[p2]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1029
                # 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
  1030
                # 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
  1031
                # first parent.
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1032
                if p1 != parents[0]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1033
                    p1 = parents[0]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1034
                    p2 = repo[nullid]
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1035
            except error.RepoError:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1036
                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
  1037
            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
  1038
                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
  1039
                          "(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
  1040
        else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1041
            p1, p2 = parents
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1042
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1043
        n = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1044
        if update:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1045
            if p1 != parents[0]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1046
                updatefunc(repo, p1.node())
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1047
            if p2 != parents[1]:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1048
                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
  1049
27613
dffd2ed9a7c4 import: refactor nocommit and importbranch handling
timeless <timeless@mozdev.org>
parents: 27612
diff changeset
  1050
            if opts.get('exact') or importbranch:
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1051
                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
  1052
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
  1053
            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
  1054
            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
  1055
            try:
24259
5ac8ce04baa2 cmdutil.tryimportone: allow importing relative patches into the working dir
Siddharth Agarwal <sid0@fb.com>
parents: 24222
diff changeset
  1056
                patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix,
5ac8ce04baa2 cmdutil.tryimportone: allow importing relative patches into the working dir
Siddharth Agarwal <sid0@fb.com>
parents: 24222
diff changeset
  1057
                            files=files, eolmode=None, similarity=sim / 100.0)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
  1058
            except patch.PatchError as e:
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
  1059
                if not partial:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1060
                    raise error.Abort(str(e))
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
  1061
                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
  1062
                    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
  1063
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1064
            files = list(files)
27613
dffd2ed9a7c4 import: refactor nocommit and importbranch handling
timeless <timeless@mozdev.org>
parents: 27612
diff changeset
  1065
            if nocommit:
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1066
                if message:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1067
                    msgs.append(message)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1068
            else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1069
                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
  1070
                    # 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
  1071
                    # 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
  1072
                    # 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
  1073
                    m = None
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1074
                else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1075
                    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
  1076
                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
  1077
                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
  1078
                    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
  1079
                else:
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
  1080
                    editor = getcommiteditor(editform=editform, **opts)
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
  1081
                extra = {}
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
  1082
                for idfunc in extrapreimport:
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
  1083
                    extrapreimportmap[idfunc](repo, extractdata, extra, opts)
31457
707f9fd2dcad import: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31451
diff changeset
  1084
                overrides = {}
707f9fd2dcad import: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31451
diff changeset
  1085
                if partial:
707f9fd2dcad import: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31451
diff changeset
  1086
                    overrides[('ui', 'allowemptycommit')] = True
707f9fd2dcad import: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31451
diff changeset
  1087
                with repo.ui.configoverride(overrides, 'import'):
27612
a0dfe8d286fe import: refactor date and user handling
timeless <timeless@mozdev.org>
parents: 27611
diff changeset
  1088
                    n = repo.commit(message, user,
a0dfe8d286fe import: refactor date and user handling
timeless <timeless@mozdev.org>
parents: 27611
diff changeset
  1089
                                    date, match=m,
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
  1090
                                    editor=editor, extra=extra)
26562
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
  1091
                    for idfunc in extrapostimport:
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
  1092
                        extrapostimportmap[idfunc](repo[n])
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1093
        else:
27613
dffd2ed9a7c4 import: refactor nocommit and importbranch handling
timeless <timeless@mozdev.org>
parents: 27612
diff changeset
  1094
            if opts.get('exact') or importbranch:
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1095
                branch = branch or 'default'
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1096
            else:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1097
                branch = p1.branch()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1098
            store = patch.filestore()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1099
            try:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1100
                files = set()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1101
                try:
24260
76225ab5a5da cmdutil.tryimportone: allow importing relative patches with --bypass
Siddharth Agarwal <sid0@fb.com>
parents: 24259
diff changeset
  1102
                    patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix,
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1103
                                    files, eolmode=None)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
  1104
                except patch.PatchError as e:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1105
                    raise error.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
  1106
                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
  1107
                    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
  1108
                else:
ffaaa80fa724 import: avoid editor invocation when importing with "--exact" for exact-ness
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22260
diff changeset
  1109
                    editor = getcommiteditor(editform='import.bypass')
32765
041d976b662a context: inline makememctx (API)
Sean Farley <sean@farley.io>
parents: 32662
diff changeset
  1110
                memctx = context.memctx(repo, (p1.node(), p2.node()),
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1111
                                            message,
32765
041d976b662a context: inline makememctx (API)
Sean Farley <sean@farley.io>
parents: 32662
diff changeset
  1112
                                            files=files,
041d976b662a context: inline makememctx (API)
Sean Farley <sean@farley.io>
parents: 32662
diff changeset
  1113
                                            filectxfn=store,
041d976b662a context: inline makememctx (API)
Sean Farley <sean@farley.io>
parents: 32662
diff changeset
  1114
                                            user=user,
041d976b662a context: inline makememctx (API)
Sean Farley <sean@farley.io>
parents: 32662
diff changeset
  1115
                                            date=date,
041d976b662a context: inline makememctx (API)
Sean Farley <sean@farley.io>
parents: 32662
diff changeset
  1116
                                            branch=branch,
22011
97acb4504704 import: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22010
diff changeset
  1117
                                            editor=editor)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1118
                n = memctx.commit()
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1119
            finally:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1120
                store.close()
27613
dffd2ed9a7c4 import: refactor nocommit and importbranch handling
timeless <timeless@mozdev.org>
parents: 27612
diff changeset
  1121
        if opts.get('exact') and nocommit:
22485
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
  1122
            # --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
  1123
            # and branch bits
efedda4aed49 import: let --exact 'work' with --no-commit (issue4376)
Matt Mackall <mpm@selenic.com>
parents: 22427
diff changeset
  1124
            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
  1125
        elif opts.get('exact') and hex(n) != nodeid:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1126
            raise error.Abort(_('patch is damaged or loses information'))
27611
fa8c491f2deb import: limit scope of msg in tryimportone
timeless <timeless@mozdev.org>
parents: 27533
diff changeset
  1127
        msg = _('applied to working directory')
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1128
        if n:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1129
            # 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
  1130
            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
  1131
        return (msg, n, rejects)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1132
    finally:
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1133
        os.unlink(tmpname)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
  1134
26545
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1135
# facility to let extensions include additional data in an exported patch
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1136
# list of identifiers to be executed in order
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1137
extraexport = []
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1138
# mapping from identifier to actual export function
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1139
# function as to return a string to be added to the header or None
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1140
# it is given two arguments (sequencenumber, changectx)
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1141
extraexportmap = {}
e99c3846d78a export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26533
diff changeset
  1142
32433
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1143
def _exportsingle(repo, ctx, match, switch_parent, rev, seqno, write, diffopts):
32662
9d201b39ccd9 export: map wctx.node() to 'ff...' node id (issue5438)
Yuya Nishihara <yuya@tcha.org>
parents: 32658
diff changeset
  1144
    node = scmutil.binnode(ctx)
32433
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1145
    parents = [p.node() for p in ctx.parents() if p]
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1146
    branch = ctx.branch()
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1147
    if switch_parent:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1148
        parents.reverse()
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1149
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1150
    if parents:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1151
        prev = parents[0]
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1152
    else:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1153
        prev = nullid
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1154
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1155
    write("# HG changeset patch\n")
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1156
    write("# User %s\n" % ctx.user())
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1157
    write("# Date %d %d\n" % ctx.date())
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1158
    write("#      %s\n" % util.datestr(ctx.date()))
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1159
    if branch and branch != 'default':
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1160
        write("# Branch %s\n" % branch)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1161
    write("# Node ID %s\n" % hex(node))
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1162
    write("# Parent  %s\n" % hex(prev))
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1163
    if len(parents) > 1:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1164
        write("# Parent  %s\n" % hex(parents[1]))
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1165
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1166
    for headerid in extraexport:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1167
        header = extraexportmap[headerid](seqno, ctx)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1168
        if header is not None:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1169
            write('# %s\n' % header)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1170
    write(ctx.description().rstrip())
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1171
    write("\n\n")
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1172
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1173
    for chunk, label in patch.diffui(repo, prev, node, match, opts=diffopts):
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1174
        write(chunk, label=label)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1175
32431
9fd9f91b0c43 cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents: 32430
diff changeset
  1176
def export(repo, revs, fntemplate='hg-%h.patch', fp=None, switch_parent=False,
26229
d1530c6e8613 extdiff: enable -I/-X with --patch
Matt Harbison <matt_harbison@yahoo.com>
parents: 26222
diff changeset
  1177
           opts=None, match=None):
32430
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1178
    '''export changesets as hg patches
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1179
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1180
    Args:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1181
      repo: The repository from which we're exporting revisions.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1182
      revs: A list of revisions to export as revision numbers.
32431
9fd9f91b0c43 cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents: 32430
diff changeset
  1183
      fntemplate: An optional string to use for generating patch file names.
32430
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1184
      fp: An optional file-like object to which patches should be written.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1185
      switch_parent: If True, show diffs against second parent when not nullid.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1186
                     Default is false, which always shows diff against p1.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1187
      opts: diff options to use for generating the patch.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1188
      match: If specified, only export changes to files matching this matcher.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1189
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1190
    Returns:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1191
      Nothing.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1192
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1193
    Side Effect:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1194
      "HG Changeset Patch" data is emitted to one of the following
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1195
      destinations:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1196
        fp is specified: All revs are written to the specified
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1197
                         file-like object.
32431
9fd9f91b0c43 cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents: 32430
diff changeset
  1198
        fntemplate specified: Each rev is written to a unique file named using
32430
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1199
                            the given template.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1200
        Neither fp nor template specified: All revs written to repo.ui.write()
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
  1201
    '''
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
  1202
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
  1203
    total = len(revs)
32432
75544176bc28 cmdutil: use a generator expression instead of a list comprehension
Augie Fackler <augie@google.com>
parents: 32431
diff changeset
  1204
    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
  1205
    filemode = {}
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
  1206
32434
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1207
    write = None
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1208
    dest = '<unnamed>'
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1209
    if fp:
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1210
        dest = getattr(fp, 'name', dest)
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1211
        def write(s, **kw):
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1212
            fp.write(s)
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1213
    elif not fntemplate:
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1214
        write = repo.ui.write
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1215
32433
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1216
    for seqno, rev in enumerate(revs, 1):
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
  1217
        ctx = repo[rev]
32433
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1218
        fo = None
32434
69c864149d69 cmdutil: avoid redefining write() function in export if possible
Augie Fackler <augie@google.com>
parents: 32433
diff changeset
  1219
        if not fp and fntemplate:
14986
70e11de6964d export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents: 14948
diff changeset
  1220
            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
  1221
            desc = desc_lines[0]    #Commit always has a first line.
32433
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1222
            fo = makefileobj(repo, fntemplate, ctx.node(), desc=desc,
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1223
                             total=total, seqno=seqno, revwidth=revwidth,
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1224
                             mode='wb', modemap=filemode)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1225
            dest = fo.name
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1226
            def write(s, **kw):
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1227
                fo.write(s)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1228
        if not dest.startswith('<'):
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1229
            repo.ui.note("%s\n" % dest)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1230
        _exportsingle(
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1231
            repo, ctx, match, switch_parent, rev, seqno, write, opts)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1232
        if fo is not None:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32432
diff changeset
  1233
            fo.close()
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
  1234
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1235
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
  1236
                   changes=None, stat=False, fp=None, prefix='',
24455
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
  1237
                   root='', listsubrepos=False):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1238
    '''show diff or diffstat.'''
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1239
    if fp is None:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1240
        write = ui.write
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1241
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1242
        def write(s, **kw):
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1243
            fp.write(s)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1244
24455
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
  1245
    if root:
16961d43dc89 diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents: 24451
diff changeset
  1246
        relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1247
    else:
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1248
        relroot = ''
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1249
    if relroot != '':
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1250
        # XXX relative roots currently don't work if the root is within a
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1251
        # subrepo
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1252
        uirelroot = match.uipath(relroot)
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1253
        relroot += '/'
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1254
        for matchroot in match.files():
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1255
            if not matchroot.startswith(relroot):
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1256
                ui.warn(_('warning: %s not inside relative root %s\n') % (
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1257
                    match.uipath(matchroot), uirelroot))
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1258
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1259
    if stat:
11950
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1260
        diffopts = diffopts.copy(context=0)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1261
        width = 80
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1262
        if not ui.plain():
12689
c52c629ce19e termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents: 12619
diff changeset
  1263
            width = ui.termwidth()
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
  1264
        chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1265
                            prefix=prefix, relroot=relroot)
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1266
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
30407
e1677cc29da6 patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents: 30375
diff changeset
  1267
                                             width=width):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1268
            write(chunk, label=label)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1269
    else:
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1270
        for chunk, label in patch.diffui(repo, node1, node2, match,
24431
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1271
                                         changes, diffopts, prefix=prefix,
a0004402776b cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 24422
diff changeset
  1272
                                         relroot=relroot):
11050
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1273
            write(chunk, label=label)
5d35f7d93514 commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents: 11017
diff changeset
  1274
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
  1275
    if listsubrepos:
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
  1276
        ctx1 = repo[node1]
12175
c0a8f9dea0f6 subrepos: handle modified but uncommitted .hgsub
Martin Geisler <mg@lazybytes.net>
parents: 12167
diff changeset
  1277
        ctx2 = repo[node2]
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
  1278
        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
  1279
            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
  1280
            try:
cfc15cbecc5e diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents: 15600
diff changeset
  1281
                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
  1282
                    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
  1283
            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
  1284
                # 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
  1285
                # 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
  1286
                # 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
  1287
                tempnode2 = None
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
  1288
            submatch = matchmod.subdirmatcher(subpath, match)
18006
0c10cf819146 subrepo: add argument to "diff()" to pass "ui" of caller side (issue3712) (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17924
diff changeset
  1289
            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
  1290
                     stat=stat, fp=fp, prefix=prefix)
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12164
diff changeset
  1291
30694
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
  1292
def _changesetlabels(ctx):
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
  1293
    labels = ['log.changeset', 'changeset.%s' % ctx.phasestr()]
31698
9b3577796291 cmdutil: add a "changeset.obsolete" label in changeset_printer
Denis Laxalde <denis@laxalde.org>
parents: 31486
diff changeset
  1294
    if ctx.obsolete():
9b3577796291 cmdutil: add a "changeset.obsolete" label in changeset_printer
Denis Laxalde <denis@laxalde.org>
parents: 31486
diff changeset
  1295
        labels.append('changeset.obsolete')
30695
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1296
    if ctx.troubled():
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1297
        labels.append('changeset.troubled')
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1298
        for trouble in ctx.troubles():
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1299
            labels.append('trouble.%s' % trouble)
30694
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
  1300
    return ' '.join(labels)
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
  1301
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1302
class changeset_printer(object):
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1303
    '''show changeset information when templating not requested.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1304
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1305
    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
  1306
        self.ui = ui
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1307
        self.repo = repo
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1308
        self.buffered = buffered
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1309
        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
  1310
        self.diffopts = diffopts
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1311
        self.header = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1312
        self.hunk = {}
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1313
        self.lastheader = None
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1314
        self.footer = None
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1315
25763
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
  1316
    def flush(self, ctx):
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
  1317
        rev = ctx.rev()
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1318
        if rev in self.header:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1319
            h = self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1320
            if h != self.lastheader:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1321
                self.lastheader = h
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1322
                self.ui.write(h)
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1323
            del self.header[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1324
        if rev in self.hunk:
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1325
            self.ui.write(self.hunk[rev])
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1326
            del self.hunk[rev]
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1327
            return 1
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1328
        return 0
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1329
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1330
    def close(self):
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1331
        if self.footer:
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1332
            self.ui.write(self.footer)
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 10111
diff changeset
  1333
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1334
    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
  1335
        if self.buffered:
27107
c57ebef70f6f cmdutil: pass labeled=True to pushbuffer()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27065
diff changeset
  1336
            self.ui.pushbuffer(labeled=True)
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1337
            self._show(ctx, copies, matchfn, props)
27109
a93d53f79e6e ui: remove labeled argument from popbuffer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27107
diff changeset
  1338
            self.hunk[ctx.rev()] = self.ui.popbuffer()
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1339
        else:
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1340
            self._show(ctx, copies, matchfn, props)
3738
cb48cd27d3f4 use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents: 3718
diff changeset
  1341
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1342
    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
  1343
        '''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
  1344
        changenode = ctx.node()
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
  1345
        rev = ctx.rev()
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  1346
        if self.ui.debugflag:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  1347
            hexfunc = hex
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  1348
        else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  1349
            hexfunc = short
25762
f4412380d357 changeset_printer: display wdirrev/wdirnode values for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 25759
diff changeset
  1350
        # as of now, wctx.node() and wctx.rev() return None, but we want to
f4412380d357 changeset_printer: display wdirrev/wdirnode values for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 25759
diff changeset
  1351
        # show the same values as {node} and {rev} templatekw
32658
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32656
diff changeset
  1352
        revnode = (scmutil.intrev(ctx), hexfunc(scmutil.binnode(ctx)))
24584
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1353
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1354
        if self.ui.quiet:
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1355
            self.ui.write("%d:%s\n" % revnode, label='log.node')
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1356
            return
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1357
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1358
        date = util.datestr(ctx.date())
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1359
17891
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
  1360
        # i18n: column positioning for "hg log"
24584
5a40b5d45396 changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24583
diff changeset
  1361
        self.ui.write(_("changeset:   %d:%s\n") % revnode,
30694
5289fd78017a cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30615
diff changeset
  1362
                      label=_changesetlabels(ctx))
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1363
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
  1364
        # 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
  1365
        # compatibility
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
  1366
        branch = ctx.branch()
4176
f9bbcebcacea "default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4055
diff changeset
  1367
        # 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
  1368
        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
  1369
            # 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
  1370
            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
  1371
                          label='log.branch')
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
  1372
28904
80be5dbe6e74 cmdutil: avoid recycling variable name "name" in namespaces code
Nathaniel Manista <nathaniel@google.com>
parents: 28891
diff changeset
  1373
        for nsname, ns in self.repo.names.iteritems():
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
  1374
            # 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
  1375
            # skip it
28904
80be5dbe6e74 cmdutil: avoid recycling variable name "name" in namespaces code
Nathaniel Manista <nathaniel@google.com>
parents: 28891
diff changeset
  1376
            if nsname == 'branches':
23772
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
  1377
                continue
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
  1378
            # 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
  1379
            # should be the same
07309e527df7 log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents: 23735
diff changeset
  1380
            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
  1381
                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
  1382
                              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
  1383
        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
  1384
            # i18n: column positioning for "hg log"
24864
bff42a92012e cmdutil: avoid wrapping ctx.phasestr() by _()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24857
diff changeset
  1385
            self.ui.write(_("phase:       %s\n") % ctx.phasestr(),
15907
51fc43253a52 changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15777
diff changeset
  1386
                          label='log.phase')
26433
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 26426
diff changeset
  1387
        for pctx in scmutil.meaningfulparents(self.repo, ctx):
24483
870d2eb82f6d changeset_printer: use context objects consistently to show parents
Yuya Nishihara <yuya@tcha.org>
parents: 24480
diff changeset
  1388
            label = 'log.parent changeset.%s' % pctx.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
  1389
            # i18n: column positioning for "hg log"
24483
870d2eb82f6d changeset_printer: use context objects consistently to show parents
Yuya Nishihara <yuya@tcha.org>
parents: 24480
diff changeset
  1390
            self.ui.write(_("parent:      %d:%s\n")
870d2eb82f6d changeset_printer: use context objects consistently to show parents
Yuya Nishihara <yuya@tcha.org>
parents: 24480
diff changeset
  1391
                          % (pctx.rev(), hexfunc(pctx.node())),
22301
f6371cc62d2a log: use correct phase info for parent field (issue4347)
Sean Farley <sean.michael.farley@gmail.com>
parents: 22167
diff changeset
  1392
                          label=label)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1393
24585
e191d5d8d515 changeset_printer: hide manifest node for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24584
diff changeset
  1394
        if self.ui.debugflag and rev is not None:
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
  1395
            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
  1396
            # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1397
            self.ui.write(_("manifest:    %d:%s\n") %
30375
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30371
diff changeset
  1398
                          (self.repo.manifestlog._revlog.rev(mnode),
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 30371
diff changeset
  1399
                           hex(mnode)),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1400
                          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
  1401
        # 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
  1402
        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
  1403
                      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
  1404
        # 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
  1405
        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
  1406
                      label='log.date')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1407
30695
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1408
        if ctx.troubled():
30710
7e95e70bad57 cmdutil: add missing "i18n" comment about "trouble: " line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30703
diff changeset
  1409
            # i18n: column positioning for "hg log"
30695
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1410
            self.ui.write(_("trouble:     %s\n") % ', '.join(ctx.troubles()),
30720
32f160ceb99d log: drop unnecessary ui.note label from "trouble: " line
Denis Laxalde <denis@laxalde.org>
parents: 30710
diff changeset
  1411
                          label='log.trouble')
30695
f05ede08dcf7 cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30694
diff changeset
  1412
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1413
        if self.ui.debugflag:
24485
914caae9a86a changeset_printer: use changectx to get status tuple
Yuya Nishihara <yuya@tcha.org>
parents: 24484
diff changeset
  1414
            files = ctx.p1().status(ctx)[: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
  1415
            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
  1416
                                   _("files:"),
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
  1417
                                   # 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
  1418
                                   _("files+:"),
8f85151ce201 i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17863
diff changeset
  1419
                                   # 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
  1420
                                   _("files-:")], files):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1421
                if value:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1422
                    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
  1423
                                  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
  1424
        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
  1425
            # 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
  1426
            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
  1427
                          label='ui.note log.files')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1428
        if copies and self.ui.verbose:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1429
            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
  1430
            # 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
  1431
            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
  1432
                          label='ui.note log.copies')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1433
9637
64425c5a9257 cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents: 9547
diff changeset
  1434
        extra = ctx.extra()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1435
        if extra and self.ui.debugflag:
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
  1436
            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
  1437
                # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1438
                self.ui.write(_("extra:       %s=%s\n")
31451
53865692a354 util: wrap s.encode('string_escape') call for future py3 compatibility
Yuya Nishihara <yuya@tcha.org>
parents: 31320
diff changeset
  1439
                              % (key, util.escapestr(value)),
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1440
                              label='ui.debug log.extra')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1441
9547
f57640bf10d4 cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents: 9536
diff changeset
  1442
        description = ctx.description().strip()
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1443
        if description:
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1444
            if self.ui.verbose:
10819
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1445
                self.ui.write(_("description:\n"),
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1446
                              label='ui.note log.description')
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1447
                self.ui.write(description,
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1448
                              label='ui.note log.description')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1449
                self.ui.write("\n\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1450
            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
  1451
                # i18n: column positioning for "hg log"
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1452
                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
  1453
                              description.splitlines()[0],
36c6a667d733 cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents: 10724
diff changeset
  1454
                              label='log.summary')
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1455
        self.ui.write("\n")
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1456
27065
93bcc73df8d5 cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26938
diff changeset
  1457
        self.showpatch(ctx, matchfn)
93bcc73df8d5 cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26938
diff changeset
  1458
93bcc73df8d5 cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26938
diff changeset
  1459
    def showpatch(self, ctx, matchfn):
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1460
        if not matchfn:
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1461
            matchfn = self.matchfn
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1462
        if matchfn:
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
  1463
            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
  1464
            diff = self.diffopts.get('patch')
23691
e41bcb019633 cmdutil.changeset_printer: explicitly honor all diffopts
Siddharth Agarwal <sid0@fb.com>
parents: 23686
diff changeset
  1465
            diffopts = patch.diffallopts(self.ui, self.diffopts)
27065
93bcc73df8d5 cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26938
diff changeset
  1466
            node = ctx.node()
27622
0bc71f45d362 cmdutil: pass node instead of ctx to diffordiffstat
Durham Goode <durham@fb.com>
parents: 27613
diff changeset
  1467
            prev = ctx.p1().node()
11950
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1468
            if stat:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1469
                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
  1470
                               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
  1471
            if diff:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1472
                if stat:
d157e040ac4c log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents: 11488
diff changeset
  1473
                    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
  1474
                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
  1475
                               match=matchfn, stat=False)
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1476
            self.ui.write("\n")
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1477
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1478
class jsonchangeset(changeset_printer):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1479
    '''format changeset information.'''
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1480
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1481
    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
  1482
        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
  1483
        self.cache = {}
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1484
        self._first = True
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1485
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1486
    def close(self):
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1487
        if not self._first:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1488
            self.ui.write("\n]\n")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1489
        else:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1490
            self.ui.write("[]\n")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1491
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1492
    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
  1493
        '''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
  1494
        rev = ctx.rev()
24602
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
  1495
        if rev is None:
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
  1496
            jrev = jnode = 'null'
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
  1497
        else:
32155
055cca8e167b py3: use %d to format integers into bytestrings
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32153
diff changeset
  1498
            jrev = '%d' % rev
24602
201caa10536b jsonchangeset: set rev and node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24585
diff changeset
  1499
            jnode = '"%s"' % hex(ctx.node())
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1500
        j = encoding.jsonescape
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1501
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1502
        if self._first:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1503
            self.ui.write("[\n {")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1504
            self._first = False
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1505
        else:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1506
            self.ui.write(",\n {")
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1507
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1508
        if self.ui.quiet:
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1509
            self.ui.write(('\n  "rev": %s') % jrev)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1510
            self.ui.write((',\n  "node": %s') % jnode)
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1511
            self.ui.write('\n }')
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1512
            return
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1513
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1514
        self.ui.write(('\n  "rev": %s') % jrev)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1515
        self.ui.write((',\n  "node": %s') % jnode)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1516
        self.ui.write((',\n  "branch": "%s"') % j(ctx.branch()))
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1517
        self.ui.write((',\n  "phase": "%s"') % ctx.phasestr())
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1518
        self.ui.write((',\n  "user": "%s"') % j(ctx.user()))
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1519
        self.ui.write((',\n  "date": [%d, %d]') % ctx.date())
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1520
        self.ui.write((',\n  "desc": "%s"') % j(ctx.description()))
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1521
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1522
        self.ui.write((',\n  "bookmarks": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1523
                      ", ".join('"%s"' % j(b) for b in ctx.bookmarks()))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1524
        self.ui.write((',\n  "tags": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1525
                      ", ".join('"%s"' % j(t) for t in ctx.tags()))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1526
        self.ui.write((',\n  "parents": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1527
                      ", ".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
  1528
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1529
        if self.ui.debugflag:
24603
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
  1530
            if rev is None:
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
  1531
                jmanifestnode = 'null'
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
  1532
            else:
e74f819e9160 jsonchangeset: set manifest node to "null" for workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24602
diff changeset
  1533
                jmanifestnode = '"%s"' % hex(ctx.manifestnode())
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1534
            self.ui.write((',\n  "manifest": %s') % jmanifestnode)
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1535
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1536
            self.ui.write((',\n  "extra": {%s}') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1537
                          ", ".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
  1538
                                    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
  1539
23734
f4e6475950f1 cmdutil.jsonchangeset: properly compute added and removed files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23501
diff changeset
  1540
            files = ctx.p1().status(ctx)
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1541
            self.ui.write((',\n  "modified": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1542
                          ", ".join('"%s"' % j(f) for f in files[0]))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1543
            self.ui.write((',\n  "added": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1544
                          ", ".join('"%s"' % j(f) for f in files[1]))
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1545
            self.ui.write((',\n  "removed": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1546
                          ", ".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
  1547
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1548
        elif self.ui.verbose:
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1549
            self.ui.write((',\n  "files": [%s]') %
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1550
                          ", ".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
  1551
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1552
            if copies:
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1553
                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
  1554
                              ", ".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
  1555
                                                        for k, v in copies))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1556
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1557
        matchfn = self.matchfn
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1558
        if matchfn:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1559
            stat = self.diffopts.get('stat')
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1560
            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
  1561
            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
  1562
            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
  1563
            if stat:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1564
                self.ui.pushbuffer()
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1565
                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
  1566
                               match=matchfn, stat=True)
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1567
                self.ui.write((',\n  "diffstat": "%s"')
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1568
                              % j(self.ui.popbuffer()))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1569
            if diff:
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1570
                self.ui.pushbuffer()
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1571
                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
  1572
                               match=matchfn, stat=False)
29397
844f72885fb9 check-code: detect "missing _() in ui message" more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29346
diff changeset
  1573
                self.ui.write((',\n  "diff": "%s"') % j(self.ui.popbuffer()))
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1574
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1575
        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
  1576
3645
b984dcb1df71 Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
  1577
class changeset_templater(changeset_printer):
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1578
    '''format changeset information.'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1579
32839
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  1580
    def __init__(self, ui, repo, tmplspec, matchfn, diffopts, buffered):
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1581
        changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
32840
57c13c0d1cde formatter: put topic in templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32839
diff changeset
  1582
        self.t = formatter.loadtemplater(ui, tmplspec,
32832
11e667a8fcba formatter: factor out function to create templater from literal or map file
Yuya Nishihara <yuya@tcha.org>
parents: 32831
diff changeset
  1583
                                         cache=templatekw.defaulttempl)
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31698
diff changeset
  1584
        self._counter = itertools.count()
20667
e96e9f805c19 changeset_templater: remove use_template method
Matt Mackall <mpm@selenic.com>
parents: 20666
diff changeset
  1585
        self.cache = {}
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1586
32842
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
  1587
        self._tref = tmplspec.ref
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
  1588
        self._parts = {'header': '', 'footer': '',
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
  1589
                       tmplspec.ref: tmplspec.ref,
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1590
                       'docheader': '', 'docfooter': '',
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1591
                       'separator': ''}
32947
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1592
        if tmplspec.mapfile:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1593
            # find correct templates for current mode, for backward
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1594
            # compatibility with 'log -v/-q/--debug' using a mapfile
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1595
            tmplmodes = [
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1596
                (True, ''),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1597
                (self.ui.verbose, '_verbose'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1598
                (self.ui.quiet, '_quiet'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1599
                (self.ui.debugflag, '_debug'),
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1600
            ]
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1601
            for mode, postfix in tmplmodes:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1602
                for t in self._parts:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1603
                    cur = t + postfix
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1604
                    if mode and cur in self.t:
3f07f12c6e10 changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents: 32946
diff changeset
  1605
                        self._parts[t] = cur
26086
3670efdc7088 templater: move verbosity-to-template matcher to constructor
Matt Mackall <mpm@selenic.com>
parents: 26085
diff changeset
  1606
26222
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1607
        if self._parts['docheader']:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1608
            self.ui.write(templater.stringify(self.t(self._parts['docheader'])))
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1609
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1610
    def close(self):
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1611
        if self._parts['docfooter']:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1612
            if not self.footer:
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1613
                self.footer = ""
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1614
            self.footer += templater.stringify(self.t(self._parts['docfooter']))
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1615
        return super(changeset_templater, self).close()
3095b1027661 templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents: 26206
diff changeset
  1616
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1617
    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
  1618
        '''show a single changeset or file revision'''
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1619
        props = props.copy()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
  1620
        props.update(templatekw.keywords)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents: 10026
diff changeset
  1621
        props['templ'] = self.t
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
  1622
        props['ctx'] = ctx
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
  1623
        props['repo'] = self.repo
28384
3356bf61fa25 formatter: make labels work with templated output
Kostia Balytskyi <ikostia@fb.com>
parents: 28375
diff changeset
  1624
        props['ui'] = self.repo.ui
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1625
        props['index'] = index = next(self._counter)
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
  1626
        props['revcache'] = {'copies': copies}
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
  1627
        props['cache'] = self.cache
32289
770bbfdc9644 py3: convert kwargs' keys to str using pycompat.strkwargs
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32174
diff changeset
  1628
        props = pycompat.strkwargs(props)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1629
32951
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1630
        # write separator, which wouldn't work well with the header part below
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1631
        # since there's inherently a conflict between header (across items) and
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1632
        # separator (per item)
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1633
        if self._parts['separator'] and index > 0:
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1634
            self.ui.write(templater.stringify(self.t(self._parts['separator'])))
050efe9a1644 changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents: 32947
diff changeset
  1635
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1636
        # write header
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1637
        if self._parts['header']:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1638
            h = templater.stringify(self.t(self._parts['header'], **props))
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1639
            if self.buffered:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1640
                self.header[ctx.rev()] = h
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1641
            else:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1642
                if self.lastheader != h:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1643
                    self.lastheader = h
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1644
                    self.ui.write(h)
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1645
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1646
        # write changeset metadata, then patch if requested
32842
97a4d09f5140 changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32840
diff changeset
  1647
        key = self._parts[self._tref]
28837
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1648
        self.ui.write(templater.stringify(self.t(key, **props)))
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1649
        self.showpatch(ctx, matchfn)
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1650
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1651
        if self._parts['footer']:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1652
            if not self.footer:
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1653
                self.footer = templater.stringify(
d54a7410307f templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 28815
diff changeset
  1654
                    self.t(self._parts['footer'], **props))
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1655
32840
57c13c0d1cde formatter: put topic in templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32839
diff changeset
  1656
def logtemplatespec(tmpl, mapfile):
32875
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
  1657
    if mapfile:
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
  1658
        return formatter.templatespec('changeset', tmpl, mapfile)
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
  1659
    else:
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
  1660
        return formatter.templatespec('', tmpl, None)
32838
615ec3f14aa9 formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32837
diff changeset
  1661
32834
edde2e974ed0 cmdutil: rename gettemplate() to _lookuplogtemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32832
diff changeset
  1662
def _lookuplogtemplate(ui, tmpl, style):
32835
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
  1663
    """Find the template matching the given template spec or style
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
  1664
9d76812f9b0b formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32834
diff changeset
  1665
    See formatter.lookuptemplate() for details.
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1666
    """
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1667
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1668
    # ui settings
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
  1669
    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
  1670
        tmpl = ui.config('ui', 'logtemplate')
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1671
        if tmpl:
32838
615ec3f14aa9 formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32837
diff changeset
  1672
            return logtemplatespec(templater.unquotestring(tmpl), None)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1673
        else:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1674
            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
  1675
22582
4fe5fa49eac8 templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents: 22303
diff changeset
  1676
    if not tmpl and style:
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1677
        mapfile = style
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1678
        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
  1679
            mapname = (templater.templatepath('map-cmdline.' + mapfile)
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1680
                       or templater.templatepath(mapfile))
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1681
            if mapname:
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1682
                mapfile = mapname
32838
615ec3f14aa9 formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32837
diff changeset
  1683
        return logtemplatespec(None, mapfile)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1684
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1685
    if not tmpl:
32838
615ec3f14aa9 formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents: 32837
diff changeset
  1686
        return logtemplatespec(None, None)
20668
3a35ba2681ec templating: make -T much more flexible
Matt Mackall <mpm@selenic.com>
parents: 20667
diff changeset
  1687
25511
c2a4dfe2a336 formatter: move most of template option helper to formatter
Matt Mackall <mpm@selenic.com>
parents: 25439
diff changeset
  1688
    return formatter.lookuptemplate(ui, 'changeset', tmpl)
20666
e3eb480a9391 cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents: 20604
diff changeset
  1689
32837
50586a0a946f cmdutil: factor out helper to create changeset_templater with literal template
Yuya Nishihara <yuya@tcha.org>
parents: 32835
diff changeset
  1690
def makelogtemplater(ui, repo, tmpl, buffered=False):
50586a0a946f cmdutil: factor out helper to create changeset_templater with literal template
Yuya Nishihara <yuya@tcha.org>
parents: 32835
diff changeset
  1691
    """Create a changeset_templater from a literal template 'tmpl'"""
32839
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  1692
    spec = logtemplatespec(tmpl, None)
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  1693
    return changeset_templater(ui, repo, spec, matchfn=None, diffopts={},
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  1694
                               buffered=buffered)
32837
50586a0a946f cmdutil: factor out helper to create changeset_templater with literal template
Yuya Nishihara <yuya@tcha.org>
parents: 32835
diff changeset
  1695
11488
f786fc4b8764 log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents: 11465
diff changeset
  1696
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
  1697
    """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
  1698
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1699
    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
  1700
    1. option 'template'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1701
    2. option 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1702
    3. [ui] setting 'logtemplate'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1703
    4. [ui] setting 'style'
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1704
    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
  1705
    regular display via changeset_printer() is done.
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1706
    """
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1707
    # options
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1708
    matchfn = None
11061
51d0387523c6 log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents: 11059
diff changeset
  1709
    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
  1710
        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
  1711
22427
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1712
    if opts.get('template') == 'json':
bd15932846a4 cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents: 22405
diff changeset
  1713
        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
  1714
32834
edde2e974ed0 cmdutil: rename gettemplate() to _lookuplogtemplate()
Yuya Nishihara <yuya@tcha.org>
parents: 32832
diff changeset
  1715
    spec = _lookuplogtemplate(ui, opts.get('template'), opts.get('style'))
32839
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  1716
32875
c8f2cf18b82e formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents: 32873
diff changeset
  1717
    if not spec.ref and not spec.tmpl and not spec.mapfile:
22386
54e614a297ac cmdutil: avoid the confusing name 'patch' for a matcher
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22374
diff changeset
  1718
        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
  1719
32839
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  1720
    return changeset_templater(ui, repo, spec, matchfn, opts, buffered)
3643
b4ad640a3bcf templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3531
diff changeset
  1721
29795
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1722
def showmarker(fm, marker, index=None):
20470
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1723
    """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
  1724
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1725
    To be used by debug function."""
28613
6433da9c96a9 debugobsolete: add an option to show marker index
Kostia Balytskyi <ikostia@fb.com>
parents: 28608
diff changeset
  1726
    if index is not None:
29795
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1727
        fm.write('index', '%i ', index)
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1728
    fm.write('precnode', '%s ', hex(marker.precnode()))
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1729
    succs = marker.succnodes()
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1730
    fm.condwrite(succs, 'succnodes', '%s ',
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1731
                 fm.formatlist(map(hex, succs), name='node'))
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1732
    fm.write('flag', '%X ', marker.flags())
22260
2229d757802d debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22250
diff changeset
  1733
    parents = marker.parentnodes()
2229d757802d debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22250
diff changeset
  1734
    if parents is not None:
29795
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1735
        fm.write('parentnodes', '{%s} ',
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1736
                 fm.formatlist(map(hex, parents), name='node', sep=', '))
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1737
    fm.write('date', '(%s) ', fm.formatdate(marker.date()))
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1738
    meta = marker.metadata().copy()
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1739
    meta.pop('date', None)
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1740
    fm.write('metadata', '{%s}', fm.formatdict(meta, fmt='%r: %r', sep=', '))
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29758
diff changeset
  1741
    fm.plain('\n')
20470
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
  1742
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1743
def finddate(ui, repo, date):
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1744
    """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
  1745
5836
c5c9a022bd9a Tweak finddate to pass date directly.
mark.williamson@cl.cam.ac.uk
parents: 5829
diff changeset
  1746
    df = util.matchdate(date)
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14321
diff changeset
  1747
    m = scmutil.matchall(repo)
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1748
    results = {}
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1749
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1750
    def prep(ctx, fns):
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1751
        d = ctx.date()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1752
        if df(d[0]):
9668
2c24471d478c cmdutil: fix bug in finddate() implementation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9667
diff changeset
  1753
            results[ctx.rev()] = d
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1754
9667
8743f2e1bc54 merge changes from mpm
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9666 9665
diff changeset
  1755
    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
  1756
        rev = ctx.rev()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1757
        if rev in results:
16937
5487088f0d43 cmdutil: lowercase finddate status message
Martin Geisler <mg@aragost.com>
parents: 16776
diff changeset
  1758
            ui.status(_("found revision %s from %s\n") %
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1759
                      (rev, util.datestr(results[rev])))
32155
055cca8e167b py3: use %d to format integers into bytestrings
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32153
diff changeset
  1760
            return '%d' % rev
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1761
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1762
    raise error.Abort(_("revision matching date not found"))
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
  1763
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1764
def increasingwindows(windowsize=8, sizelimit=512):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1765
    while True:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1766
        yield windowsize
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1767
        if windowsize < sizelimit:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1768
            windowsize *= 2
16776
5088d0b9a9a1 cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents: 16701
diff changeset
  1769
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1770
class FileWalkError(Exception):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1771
    pass
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1772
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1773
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
  1774
    '''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
  1775
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1776
    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
  1777
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1778
    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
  1779
    filelogs alone.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1780
    '''
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1781
    wanted = set()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1782
    copies = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1783
    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
  1784
    def filerevgen(filelog, last):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1785
        """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1786
        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
  1787
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1788
        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
  1789
        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
  1790
        tuples in backwards order
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1791
        """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1792
        cl_count = len(repo)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1793
        revs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1794
        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
  1795
            linkrev = filelog.linkrev(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1796
            if linkrev < minrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1797
                continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1798
            # 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
  1799
            # 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
  1800
            if linkrev >= cl_count:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1801
                break
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1802
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1803
            parentlinkrevs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1804
            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
  1805
                if p != nullrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1806
                    parentlinkrevs.append(filelog.linkrev(p))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1807
            n = filelog.node(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1808
            revs.append((linkrev, parentlinkrevs,
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1809
                         follow and filelog.renamed(n)))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1810
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1811
        return reversed(revs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1812
    def iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1813
        pctx = repo['.']
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1814
        for filename in match.files():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1815
            if follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1816
                if filename not in pctx:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1817
                    raise error.Abort(_('cannot follow file not in parent '
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1818
                                       'revision: "%s"') % filename)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1819
                yield filename, pctx[filename].filenode()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1820
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1821
                yield filename, None
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1822
        for filename_node in copies:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1823
            yield filename_node
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1824
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1825
    for file_, node in iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1826
        filelog = repo.file(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1827
        if not len(filelog):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1828
            if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1829
                # 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
  1830
                # 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
  1831
                if follow:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1832
                    raise error.Abort(
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1833
                        _('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
  1834
                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
  1835
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1836
                continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1837
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1838
        if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1839
            last = len(filelog) - 1
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1840
        else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1841
            last = filelog.rev(node)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1842
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1843
        # keep track of all ancestors of the file
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32289
diff changeset
  1844
        ancestors = {filelog.linkrev(last)}
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1845
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1846
        # 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
  1847
        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
  1848
            if not follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1849
                if rev > maxrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1850
                    continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1851
            else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1852
                # 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
  1853
                # rev to us:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1854
                # 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
  1855
                # 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
  1856
                # to explore the file graph
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1857
                if rev not in ancestors:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1858
                    continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1859
                # XXX insert 1327 fix here
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1860
                if flparentlinkrevs:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1861
                    ancestors.update(flparentlinkrevs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1862
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1863
            fncache.setdefault(rev, []).append(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1864
            wanted.add(rev)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1865
            if copied:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1866
                copies.append(copied)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1867
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1868
    return wanted
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1869
24391
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1870
class _followfilter(object):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1871
    def __init__(self, repo, onlyfirst=False):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1872
        self.repo = repo
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1873
        self.startrev = nullrev
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1874
        self.roots = set()
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1875
        self.onlyfirst = onlyfirst
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1876
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1877
    def match(self, rev):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1878
        def realparents(rev):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1879
            if self.onlyfirst:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1880
                return self.repo.changelog.parentrevs(rev)[0:1]
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1881
            else:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1882
                return filter(lambda x: x != nullrev,
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1883
                              self.repo.changelog.parentrevs(rev))
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1884
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1885
        if self.startrev == nullrev:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1886
            self.startrev = rev
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1887
            return True
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1888
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1889
        if rev > self.startrev:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1890
            # forward: all descendants
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1891
            if not self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1892
                self.roots.add(self.startrev)
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1893
            for parent in realparents(rev):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1894
                if parent in self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1895
                    self.roots.add(rev)
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1896
                    return True
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1897
        else:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1898
            # backwards: all parents
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1899
            if not self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1900
                self.roots.update(realparents(self.startrev))
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1901
            if rev in self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1902
                self.roots.remove(rev)
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1903
                self.roots.update(realparents(rev))
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1904
                return True
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1905
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1906
        return False
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  1907
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9664
diff changeset
  1908
def walkchangerevs(repo, match, opts, prepare):
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
  1909
    '''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
  1910
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1911
    Callers most commonly need to iterate backwards over the history
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
  1912
    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
  1913
    performance, so we use iterators in a "windowed" way.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1914
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1915
    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
  1916
    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
  1917
    order (usually backwards) to display it.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1918
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1919
    This function returns an iterator yielding contexts. Before
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  1920
    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
  1921
    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
  1922
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1923
    follow = opts.get('follow') or opts.get('follow_first')
24063
c98fa0ca4678 cmdutil: have walkchangerevs utilize common function to build revs
Yuya Nishihara <yuya@tcha.org>
parents: 24062
diff changeset
  1924
    revs = _logrevs(repo, opts)
11281
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
  1925
    if not revs:
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
  1926
        return []
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8119
diff changeset
  1927
    wanted = set()
25272
6c76c42a5893 walkchangerevs: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25271
diff changeset
  1928
    slowpath = match.anypats() or ((match.isexact() or match.prefix()) and
6c76c42a5893 walkchangerevs: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25271
diff changeset
  1929
                                   opts.get('removed'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1930
    fncache = {}
16108
f7e0d95d0a0b log: remove caching of all visited revisions (issue3253)
Matt Mackall <mpm@selenic.com>
parents: 16070
diff changeset
  1931
    change = repo.changectx
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1932
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1933
    # 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
  1934
    # 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
  1935
    # 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
  1936
    # match the file filtering conditions.
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1937
24384
5cb459dc32d2 walkchangerevs: simplify by using match.always() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 24379
diff changeset
  1938
    if match.always():
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1939
        # No files, no patterns.  Display all revs.
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  1940
        wanted = revs
25271
1b1eaf1885df walkchangerevs: simplify with an 'elif'
Martin von Zweigbergk <martinvonz@google.com>
parents: 25259
diff changeset
  1941
    elif not slowpath:
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1942
        # 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
  1943
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1944
        try:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1945
            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
  1946
        except FileWalkError:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1947
            slowpath = True
11608
183e63112698 log: remove increasing windows usage in fastpath
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11607
diff changeset
  1948
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
  1949
            # 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
  1950
            # 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
  1951
            # existed in history, otherwise simply return
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1952
            for path in match.files():
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1953
                if path == '.' or path in repo.store:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1954
                    break
18340
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
  1955
            else:
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
  1956
                return []
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  1957
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1958
    if slowpath:
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1959
        # 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
  1960
        # changed files
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  1961
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1962
        if follow:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  1963
            raise error.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
  1964
                               'filenames'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1965
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1966
        # 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
  1967
        # 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
  1968
        class lazywantedset(object):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1969
            def __init__(self):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1970
                self.set = set()
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1971
                self.revs = set(revs)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1972
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1973
            # 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
  1974
            # 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
  1975
            def __contains__(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1976
                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
  1977
                    return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1978
                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
  1979
                    return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1980
                else:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1981
                    self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1982
                    ctx = change(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1983
                    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
  1984
                    if matches:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1985
                        fncache[value] = matches
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1986
                        self.set.add(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1987
                        return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1988
                    return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1989
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1990
            def discard(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1991
                self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1992
                self.set.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1993
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
  1994
        wanted = lazywantedset()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1995
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  1996
    # 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
  1997
    # 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
  1998
    for rev in opts.get('prune', ()):
16380
84ba30e8c790 cmdutil: use context instead of lookup
Matt Mackall <mpm@selenic.com>
parents: 16304
diff changeset
  1999
        rev = repo[rev].rev()
24391
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  2000
        ff = _followfilter(repo)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2001
        stop = min(revs[0], revs[-1])
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  2002
        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
  2003
            if ff.match(x):
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2004
                wanted = wanted - [x]
18710
49ef9d0ca815 cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents: 18688
diff changeset
  2005
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
  2006
    # 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
  2007
    # revision range, yielding only revisions in wanted.
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2008
    def iterate():
25272
6c76c42a5893 walkchangerevs: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25271
diff changeset
  2009
        if follow and match.always():
24391
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
  2010
            ff = _followfilter(repo, onlyfirst=opts.get('follow_first'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2011
            def want(rev):
8119
af44d0b953c6 cmdutil: return boolean result directly in want function
Martin Geisler <mg@lazybytes.net>
parents: 8117
diff changeset
  2012
                return ff.match(rev) and rev in wanted
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2013
        else:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2014
            def want(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2015
                return rev in wanted
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2016
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2017
        it = iter(revs)
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2018
        stopiteration = False
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2019
        for windowsize in increasingwindows():
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2020
            nrevs = []
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2021
            for i in xrange(windowsize):
25147
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
  2022
                rev = next(it, None)
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
  2023
                if rev is None:
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2024
                    stopiteration = True
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2025
                    break
25147
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
  2026
                elif want(rev):
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
  2027
                    nrevs.append(rev)
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
  2028
            for rev in sorted(nrevs):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2029
                fns = fncache.get(rev)
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
  2030
                ctx = change(rev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2031
                if not fns:
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2032
                    def fns_generator():
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
  2033
                        for f in ctx.files():
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  2034
                            if match(f):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2035
                                yield f
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2036
                    fns = fns_generator()
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  2037
                prepare(ctx, fns)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
  2038
            for rev in nrevs:
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
  2039
                yield change(rev)
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2040
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2041
            if stopiteration:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2042
                break
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
  2043
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
  2044
    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
  2045
22166
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  2046
def _makefollowlogfilematcher(repo, files, followfirst):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2047
    # 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
  2048
    # 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
  2049
    # --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
  2050
    # 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
  2051
    # reproducing the graph traversal already done by --follow revset
30016
2963fba2d18a log: copy the way of ancestor traversal to --follow matcher (issue5376)
Yuya Nishihara <yuya@tcha.org>
parents: 30015
diff changeset
  2052
    # and relating revs to file names (which is not "correct" but
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2053
    # good enough).
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2054
    fcache = {}
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2055
    fcacheready = [False]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2056
    pctx = repo['.']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2057
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2058
    def populate():
21876
584bbfd1b50d log: make --patch --follow work inside a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents: 21825
diff changeset
  2059
        for fn in files:
30015
96b2dd3b184d log: unroll loop that populates file paths for --patch --follow matcher
Yuya Nishihara <yuya@tcha.org>
parents: 30004
diff changeset
  2060
            fctx = pctx[fn]
30016
2963fba2d18a log: copy the way of ancestor traversal to --follow matcher (issue5376)
Yuya Nishihara <yuya@tcha.org>
parents: 30015
diff changeset
  2061
            fcache.setdefault(fctx.introrev(), set()).add(fctx.path())
30015
96b2dd3b184d log: unroll loop that populates file paths for --patch --follow matcher
Yuya Nishihara <yuya@tcha.org>
parents: 30004
diff changeset
  2062
            for c in fctx.ancestors(followfirst=followfirst):
30016
2963fba2d18a log: copy the way of ancestor traversal to --follow matcher (issue5376)
Yuya Nishihara <yuya@tcha.org>
parents: 30015
diff changeset
  2063
                fcache.setdefault(c.rev(), set()).add(c.path())
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2064
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2065
    def filematcher(rev):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2066
        if not fcacheready[0]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2067
            # Lazy initialization
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2068
            fcacheready[0] = True
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2069
            populate()
21878
e2530d4a47c1 log: use an exact matcher for --patch --follow
Siddharth Agarwal <sid0@fb.com>
parents: 21877
diff changeset
  2070
        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
  2071
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2072
    return filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2073
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  2074
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
  2075
    '''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
  2076
    return None
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  2077
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  2078
def _makelogrevset(repo, pats, opts, revs):
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2079
    """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
  2080
    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
  2081
    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
  2082
    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
  2083
    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
  2084
    """
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2085
    opt2revset = {
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2086
        'no_merges':        ('not merge()', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2087
        'only_merges':      ('merge()', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2088
        '_ancestors':       ('ancestors(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2089
        '_fancestors':      ('_firstancestors(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2090
        '_descendants':     ('descendants(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2091
        '_fdescendants':    ('_firstdescendants(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2092
        '_matchfiles':      ('_matchfiles(%(val)s)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2093
        'date':             ('date(%(val)r)', None),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2094
        'branch':           ('branch(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2095
        '_patslog':         ('filelog(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2096
        '_patsfollow':      ('follow(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2097
        '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2098
        'keyword':          ('keyword(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2099
        '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
  2100
        'user':             ('user(%(val)r)', ' or '),
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2101
        }
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2102
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2103
    opts = dict(opts)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2104
    # follow or not follow?
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2105
    follow = opts.get('follow') or opts.get('follow_first')
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  2106
    if opts.get('follow_first'):
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  2107
        followfirst = 1
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  2108
    else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
  2109
        followfirst = 0
26098
ce26928cbe41 spelling: behaviour -> behavior
timeless@mozdev.org
parents: 26086
diff changeset
  2110
    # --follow with FILE behavior depends on revs...
20756
e7833e63bb42 cmdutil: changed code in _makegraphlogrevset not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20755
diff changeset
  2111
    it = iter(revs)
29216
ead25aa27a43 py3: convert to next() function
timeless <timeless@mozdev.org>
parents: 29137
diff changeset
  2112
    startrev = next(it)
25168
4dfd4d3b9b93 _makelogrevset: replace try/except with 'next' usage
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25147
diff changeset
  2113
    followdescendants = startrev < next(it, startrev)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2114
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2115
    # 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
  2116
    # the same time
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2117
    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
  2118
    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
  2119
    # 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
  2120
    # _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
  2121
    # 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
  2122
    # platforms without shell expansion (windows).
24534
1925769b4ff8 log: prefer 'wctx' over 'pctx' for working context
Martin von Zweigbergk <martinvonz@google.com>
parents: 24485
diff changeset
  2123
    wctx = repo[None]
1925769b4ff8 log: prefer 'wctx' over 'pctx' for working context
Martin von Zweigbergk <martinvonz@google.com>
parents: 24485
diff changeset
  2124
    match, pats = scmutil.matchandpats(wctx, pats, opts)
25273
8e0e334bad42 _makelogrevset: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25272
diff changeset
  2125
    slowpath = match.anypats() or ((match.isexact() or match.prefix()) and
8e0e334bad42 _makelogrevset: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25272
diff changeset
  2126
                                   opts.get('removed'))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2127
    if not slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2128
        for f in match.files():
24534
1925769b4ff8 log: prefer 'wctx' over 'pctx' for working context
Martin von Zweigbergk <martinvonz@google.com>
parents: 24485
diff changeset
  2129
            if follow and f not in wctx:
21998
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2130
                # 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
  2131
                # take the slow path.
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2132
                if os.path.exists(repo.wjoin(f)):
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2133
                    slowpath = True
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2134
                    continue
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2135
                else:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  2136
                    raise error.Abort(_('cannot follow file not in parent '
21998
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2137
                                       'revision: "%s"') % f)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2138
            filelog = repo.file(f)
19293
446ab88d3f1c filelog: switch 'not len(filerevlog)' to 'not filerevlog'
Durham Goode <durham@fb.com>
parents: 19290
diff changeset
  2139
            if not filelog:
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2140
                # 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
  2141
                # 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
  2142
                if follow:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  2143
                    raise error.Abort(
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2144
                        _('cannot follow nonexistent file: "%s"') % f)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2145
                slowpath = True
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2146
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2147
        # 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
  2148
        # 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
  2149
        # 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
  2150
        # slowpath; otherwise, we can turn off the slowpath
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2151
        if slowpath:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2152
            for path in match.files():
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2153
                if path == '.' or path in repo.store:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2154
                    break
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2155
            else:
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2156
                slowpath = False
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
  2157
23500
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  2158
    fpats = ('_patsfollow', '_patsfollowfirst')
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  2159
    fnopats = (('_ancestors', '_fancestors'),
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  2160
               ('_descendants', '_fdescendants'))
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2161
    if slowpath:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2162
        # See walkchangerevs() slow path.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2163
        #
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2164
        # 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
  2165
        # 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
  2166
        # 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
  2167
        # "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
  2168
        # 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
  2169
        # directory.
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2170
        matchargs = ['r:', 'd:relpath']
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2171
        for p in pats:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2172
            matchargs.append('p:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2173
        for p in opts.get('include', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2174
            matchargs.append('i:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2175
        for p in opts.get('exclude', []):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2176
            matchargs.append('x:' + p)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2177
        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
  2178
        opts['_matchfiles'] = matchargs
23500
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  2179
        if follow:
9601229ed361 log: fix log -f slow path to actually follow history
Durham Goode <durham@fb.com>
parents: 23403
diff changeset
  2180
            opts[fnopats[0][followfirst]] = '.'
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2181
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2182
        if follow:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2183
            if pats:
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17391
diff changeset
  2184
                # 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
  2185
                # 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
  2186
                opts[fpats[followfirst]] = list(match.files())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2187
            else:
23955
8a29897d42d2 log: use rev() to build revset of --follow option from numeric revision
Yuya Nishihara <yuya@tcha.org>
parents: 23885
diff changeset
  2188
                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
  2189
                opts[op] = 'rev(%d)' % startrev
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2190
        else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2191
            opts['_patslog'] = list(pats)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2192
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2193
    filematcher = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2194
    if opts.get('patch') or opts.get('stat'):
21998
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2195
        # When following files, track renames via a special matcher.
739095270f48 log: allow patterns with -f
Durham Goode <durham@fb.com>
parents: 21966
diff changeset
  2196
        # 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
  2197
        # 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
  2198
        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
  2199
            # _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
  2200
            # 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
  2201
            filematcher = _makefollowlogfilematcher(repo, match.files(),
ac7a3b2a85e3 cmdutil: rename _makelogfilematcher to _makefollowlogfilematcher
Siddharth Agarwal <sid0@fb.com>
parents: 21966
diff changeset
  2202
                                                    followfirst)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2203
        else:
22167
d4bc38f6eab7 cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents: 22166
diff changeset
  2204
            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
  2205
            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
  2206
                filematcher = lambda rev: match
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2207
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2208
    expr = []
23501
424d669118d3 log: fix log revset instability
Durham Goode <durham@fb.com>
parents: 23500
diff changeset
  2209
    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
  2210
        if not val:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2211
            continue
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2212
        if op not in opt2revset:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2213
            continue
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2214
        revop, andor = opt2revset[op]
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2215
        if '%(val)' not in revop:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2216
            expr.append(revop)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2217
        else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2218
            if not isinstance(val, list):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2219
                e = revop % {'val': val}
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2220
            else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2221
                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
  2222
            expr.append(e)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2223
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2224
    if expr:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2225
        expr = '(' + ' and '.join(expr) + ')'
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2226
    else:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2227
        expr = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2228
    return expr, filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2229
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2230
def _logrevs(repo, opts):
26098
ce26928cbe41 spelling: behaviour -> behavior
timeless@mozdev.org
parents: 26086
diff changeset
  2231
    # Default --rev value depends on --follow but --follow behavior
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2232
    # depends on revisions resolved from --rev...
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2233
    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
  2234
    if opts.get('rev'):
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2235
        revs = scmutil.revrange(repo, opts['rev'])
24064
c260887cdbcd log: fix --follow null parent not to include revision 0
Yuya Nishihara <yuya@tcha.org>
parents: 24063
diff changeset
  2236
    elif follow and repo.dirstate.p1() == nullid:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
  2237
        revs = smartset.baseset()
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2238
    elif follow:
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2239
        revs = repo.revs('reverse(:.)')
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2240
    else:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
  2241
        revs = smartset.spanset(repo)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2242
        revs.reverse()
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2243
    return revs
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2244
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2245
def getgraphlogrevs(repo, pats, opts):
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2246
    """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
  2247
    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
  2248
    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
  2249
    --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
  2250
    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
  2251
    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
  2252
    """
18172
e6c5e0092469 cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents: 18171
diff changeset
  2253
    limit = loglimit(opts)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2254
    revs = _logrevs(repo, opts)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2255
    if not revs:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
  2256
        return smartset.baseset(), None, None
21108
e5ad36a845af cmdutil: changed _makegraphlogrevset to _makelogrevset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21051
diff changeset
  2257
    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
  2258
    if opts.get('rev'):
eb1c9700d19d graphlog: move comment and flag denoting revs might be unsorted
Yuya Nishihara <yuya@tcha.org>
parents: 24059
diff changeset
  2259
        # 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
  2260
        # _makelogrevset because it might depend on the order of revs
29346
38e0c83c7ee4 revset: record if a set is in topographical order
Martijn Pieters <mjpieters@fb.com>
parents: 29335
diff changeset
  2261
        if not (revs.isdescending() or revs.istopo()):
29335
631617262e55 graphmod: avoid sorting when already sorted
Martijn Pieters <mjpieters@fb.com>
parents: 29327
diff changeset
  2262
            revs.sort(reverse=True)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2263
    if expr:
30003
46825334f270 graphlog: preserve topo sort even if additional filter options specified
Yuya Nishihara <yuya@tcha.org>
parents: 29963
diff changeset
  2264
        matcher = revset.match(repo.ui, expr, order=revset.followorder)
18171
9d350f2d9458 cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents: 18170
diff changeset
  2265
        revs = matcher(repo, revs)
18243
b3b1b8e127e5 log: use "hidden" filtering instead of manual check at display time
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18235
diff changeset
  2266
    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
  2267
        limitedrevs = []
20755
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  2268
        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
  2269
            if idx >= limit:
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  2270
                break
cfd03c069e08 cmdutil: changed code in getgraphlogrevs not to use getitem
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20710
diff changeset
  2271
            limitedrevs.append(rev)
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
  2272
        revs = smartset.baseset(limitedrevs)
18172
e6c5e0092469 cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents: 18171
diff changeset
  2273
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2274
    return revs, expr, filematcher
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2275
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2276
def getlogrevs(repo, pats, opts):
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2277
    """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
  2278
    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
  2279
    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
  2280
    --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
  2281
    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
  2282
    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
  2283
    """
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2284
    limit = loglimit(opts)
24062
f576addb5b77 log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 24061
diff changeset
  2285
    revs = _logrevs(repo, opts)
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2286
    if not revs:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
  2287
        return smartset.baseset([]), None, None
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2288
    expr, filematcher = _makelogrevset(repo, pats, opts, revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2289
    if expr:
29956
fa5e4f58dfbc log: drop hack to fix order of revset (issue5100)
Yuya Nishihara <yuya@tcha.org>
parents: 29819
diff changeset
  2290
        matcher = revset.match(repo.ui, expr, order=revset.followorder)
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2291
        revs = matcher(repo, revs)
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2292
    if limit is not None:
22806
65ccc733d58e getlogrevs: remove user of baseset.append
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22765
diff changeset
  2293
        limitedrevs = []
25169
7855d1f5f152 getlogrevs: rewrite a loop to get read of try/except
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25168
diff changeset
  2294
        for idx, r in enumerate(revs):
7855d1f5f152 getlogrevs: rewrite a loop to get read of try/except
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25168
diff changeset
  2295
            if limit <= idx:
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2296
                break
25169
7855d1f5f152 getlogrevs: rewrite a loop to get read of try/except
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25168
diff changeset
  2297
            limitedrevs.append(r)
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30877
diff changeset
  2298
        revs = smartset.baseset(limitedrevs)
21127
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2299
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2300
    return revs, expr, filematcher
69402eb72115 log: changed implementation to use graphlog code
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 21108
diff changeset
  2301
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2302
def _graphnodeformatter(ui, displayer):
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2303
    spec = ui.config('ui', 'graphnodetemplate')
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2304
    if not spec:
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2305
        return templatekw.showgraphnode  # fast path for "{graphnode}"
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2306
32045
3eceeede26e9 graphlog: optionally strip quotes from graphnode template (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 32005
diff changeset
  2307
    spec = templater.unquotestring(spec)
32873
2ecce24dfcd3 templater: add simple interface for unnamed template (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32862
diff changeset
  2308
    templ = formatter.maketemplater(ui, spec)
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2309
    cache = {}
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2310
    if isinstance(displayer, changeset_templater):
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2311
        cache = displayer.cache  # reuse cache of slow templates
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2312
    props = templatekw.keywords.copy()
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2313
    props['templ'] = templ
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2314
    props['cache'] = cache
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2315
    def formatnode(repo, ctx):
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2316
        props['ctx'] = ctx
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2317
        props['repo'] = repo
28428
6a4a4ca21907 graphlog: bring back color to node symbol template
Yuya Nishihara <yuya@tcha.org>
parents: 28384
diff changeset
  2318
        props['ui'] = repo.ui
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2319
        props['revcache'] = {}
32873
2ecce24dfcd3 templater: add simple interface for unnamed template (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32862
diff changeset
  2320
        return templ.render(props)
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2321
    return formatnode
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2322
27213
ccae1588117f graphlog: move creation of workingdir-parent nodes to displaygraph()
Yuya Nishihara <yuya@tcha.org>
parents: 27155
diff changeset
  2323
def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None,
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2324
                 filematcher=None):
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2325
    formatnode = _graphnodeformatter(ui, displayer)
28375
97cb1aeaca78 graphmod: refactor state handling
Martijn Pieters <mjpieters@fb.com>
parents: 28322
diff changeset
  2326
    state = graphmod.asciistate()
28600
0d6137891114 graphmod: allow for different styles for different edge types
Martijn Pieters <mjpieters@fb.com>
parents: 28570
diff changeset
  2327
    styles = state['styles']
28999
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2328
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2329
    # only set graph styling if HGPLAIN is not set.
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2330
    if ui.plain('graph'):
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2331
        # set all edge styles to |, the default pre-3.8 behaviour
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2332
        styles.update(dict.fromkeys(styles, '|'))
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2333
    else:
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2334
        edgetypes = {
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2335
            'parent': graphmod.PARENT,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2336
            'grandparent': graphmod.GRANDPARENT,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2337
            'missing': graphmod.MISSINGPARENT
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2338
        }
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2339
        for name, key in edgetypes.items():
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2340
            # experimental config: experimental.graphstyle.*
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2341
            styles[key] = ui.config('experimental', 'graphstyle.%s' % name,
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2342
                                    styles[key])
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2343
            if not styles[key]:
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2344
                styles[key] = None
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2345
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2346
        # experimental config: experimental.graphshorten
790c076cd4a2 graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents: 28955
diff changeset
  2347
        state['graphshorten'] = ui.configbool('experimental', 'graphshorten')
28891
ac30adb260ea graphmod: shorten graph
santiagopim <santiagopim@gmail.com>
parents: 28861
diff changeset
  2348
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2349
    for rev, type, ctx, parents in dag:
27216
8117e2cd959e graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
  2350
        char = formatnode(repo, ctx)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2351
        copies = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2352
        if getrenamed and ctx.rev():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2353
            copies = []
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2354
            for fn in ctx.files():
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2355
                rename = getrenamed(fn, ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2356
                if rename:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2357
                    copies.append((fn, rename[0]))
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2358
        revmatchfn = None
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2359
        if filematcher is not None:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2360
            revmatchfn = filematcher(ctx.rev())
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2361
        displayer.show(ctx, copies=copies, matchfn=revmatchfn)
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2362
        lines = displayer.hunk.pop(rev).split('\n')
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2363
        if not lines[-1]:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2364
            del lines[-1]
25763
60c791592aa7 changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents: 25762
diff changeset
  2365
        displayer.flush(ctx)
28375
97cb1aeaca78 graphmod: refactor state handling
Martijn Pieters <mjpieters@fb.com>
parents: 28322
diff changeset
  2366
        edges = edgefn(type, char, lines, state, rev, parents)
17180
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2367
        for type, char, lines, coldata in edges:
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2368
            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
  2369
    displayer.close()
ae0629161090 graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents: 17059
diff changeset
  2370
31486
06d3c40fc3e7 graphlog: pass function arguments without expansion
Yuya Nishihara <yuya@tcha.org>
parents: 31457
diff changeset
  2371
def graphlog(ui, repo, pats, opts):
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2372
    # Parameters are identical to log command ones
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2373
    revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2374
    revdag = graphmod.dagwalker(repo, revs)
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2375
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2376
    getrenamed = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2377
    if opts.get('copies'):
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2378
        endrev = None
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2379
        if opts.get('rev'):
20760
d5fa413346e7 cmdutil: changed max method for lazy call
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20759
diff changeset
  2380
            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
  2381
        getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
31078
a113284f54a0 graphlog: restore pager lost at 1cec1d863008
Yuya Nishihara <yuya@tcha.org>
parents: 31023
diff changeset
  2382
a113284f54a0 graphlog: restore pager lost at 1cec1d863008
Yuya Nishihara <yuya@tcha.org>
parents: 31023
diff changeset
  2383
    ui.pager('log')
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2384
    displayer = show_changeset(ui, repo, opts, buffered=True)
27213
ccae1588117f graphlog: move creation of workingdir-parent nodes to displaygraph()
Yuya Nishihara <yuya@tcha.org>
parents: 27155
diff changeset
  2385
    displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed,
ccae1588117f graphlog: move creation of workingdir-parent nodes to displaygraph()
Yuya Nishihara <yuya@tcha.org>
parents: 27155
diff changeset
  2386
                 filematcher)
17181
6f71167292f2 log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents: 17180
diff changeset
  2387
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2388
def checkunsupportedgraphflags(pats, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2389
    for op in ["newest_first"]:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2390
        if op in opts and opts[op]:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  2391
            raise error.Abort(_("-G/--graph option is incompatible with --%s")
17182
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2392
                             % op.replace("_", "-"))
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2393
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2394
def graphrevs(repo, nodes, opts):
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2395
    limit = loglimit(opts)
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2396
    nodes.reverse()
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2397
    if limit is not None:
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2398
        nodes = nodes[:limit]
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2399
    return graphmod.nodes(repo, nodes)
cdf1532d89c6 incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents: 17181
diff changeset
  2400
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  2401
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
  2402
    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
  2403
    bad = []
25436
9724cbe2d546 add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25424
diff changeset
  2404
9724cbe2d546 add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25424
diff changeset
  2405
    badfn = lambda x, y: bad.append(x) or match.bad(x, y)
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  2406
    names = []
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  2407
    wctx = repo[None]
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  2408
    cca = None
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  2409
    abort, warn = scmutil.checkportabilityalert(ui)
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  2410
    if abort or warn:
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17182
diff changeset
  2411
        cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate)
25436
9724cbe2d546 add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25424
diff changeset
  2412
26206
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
  2413
    badmatch = matchmod.badmatch(match, badfn)
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
  2414
    dirstate = repo.dirstate
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
  2415
    # We don't want to just call wctx.walk here, since it would return a lot of
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
  2416
    # clean files, which we aren't interested in and takes time.
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
  2417
    for f in sorted(dirstate.walk(badmatch, sorted(wctx.substate),
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
  2418
                                  True, False, full=False)):
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  2419
        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
  2420
        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
  2421
            if cca:
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
  2422
                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
  2423
            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
  2424
            if ui.verbose or not exact:
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2425
                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
  2426
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  2427
    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
  2428
        sub = wctx.sub(subpath)
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  2429
        try:
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
  2430
            submatch = matchmod.subdirmatcher(subpath, match)
32147
a77e61b45384 py3: handle opts correctly for `hg add`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32144
diff changeset
  2431
            if opts.get(r'subrepos'):
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  2432
                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
  2433
            else:
23885
9994f45ba714 add: pass options via keyword args
Matt Harbison <matt_harbison@yahoo.com>
parents: 23876
diff changeset
  2434
                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
  2435
        except error.LookupError:
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
  2436
            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
  2437
                           % join(subpath))
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  2438
32147
a77e61b45384 py3: handle opts correctly for `hg add`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32144
diff changeset
  2439
    if not opts.get(r'dry_run'):
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
  2440
        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
  2441
        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
  2442
    return bad
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
  2443
32005
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2444
def addwebdirpath(repo, serverpath, webconf):
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2445
    webconf[serverpath] = repo.root
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2446
    repo.ui.debug('adding %s = %s\n' % (serverpath, repo.root))
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2447
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2448
    for r in repo.revs('filelog("path:.hgsub")'):
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2449
        ctx = repo[r]
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2450
        for subpath in ctx.substate:
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2451
            ctx.sub(subpath).addwebdirpath(serverpath, webconf)
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
  2452
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2453
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
  2454
    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
  2455
    bad = []
25437
9c1bcd95b3ff forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25436
diff changeset
  2456
    badfn = lambda x, y: bad.append(x) or match.bad(x, y)
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2457
    wctx = repo[None]
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2458
    forgot = []
25437
9c1bcd95b3ff forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25436
diff changeset
  2459
9c1bcd95b3ff forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25436
diff changeset
  2460
    s = repo.status(match=matchmod.badmatch(match, badfn), clean=True)
32174
e4a4ebfd9d8e forget: access status fields by name, not index
Martin von Zweigbergk <martinvonz@google.com>
parents: 32155
diff changeset
  2461
    forget = sorted(s.modified + s.added + s.deleted + s.clean)
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2462
    if explicitonly:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2463
        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
  2464
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
  2465
    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
  2466
        sub = wctx.sub(subpath)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2467
        try:
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
  2468
            submatch = matchmod.subdirmatcher(subpath, match)
23577
597b071a0e0d subrepo: drop the 'ui' parameter to forget()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23576
diff changeset
  2469
            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
  2470
            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
  2471
            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
  2472
        except error.LookupError:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2473
            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
  2474
                           % join(subpath))
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2475
16070
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
  2476
    if not explicitonly:
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
  2477
        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
  2478
            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
  2479
                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
  2480
                    if repo.wvfs.exists(f):
24548
c780a63f61ca forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents: 24169
diff changeset
  2481
                        # Don't complain if the exact case match wasn't given.
c780a63f61ca forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents: 24169
diff changeset
  2482
                        # But don't do this until after checking 'forgot', so
c780a63f61ca forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents: 24169
diff changeset
  2483
                        # that subrepo files aren't normalized, and this op is
c780a63f61ca forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents: 24169
diff changeset
  2484
                        # purely from data cached by the status walk above.
c780a63f61ca forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents: 24169
diff changeset
  2485
                        if repo.dirstate.normalize(f) in repo.dirstate:
c780a63f61ca forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents: 24169
diff changeset
  2486
                            continue
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2487
                        ui.warn(_('not removing %s: '
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2488
                                  'file is already untracked\n')
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2489
                                % match.rel(f))
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2490
                    bad.append(f)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2491
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2492
    for f in forget:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2493
        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
  2494
            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
  2495
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2496
    rejected = wctx.forget(forget, prefix)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2497
    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
  2498
    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
  2499
    return bad, forgot
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
  2500
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2501
def files(ui, ctx, m, fm, fmt, subrepos):
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2502
    rev = ctx.rev()
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2503
    ret = 1
24301
18b5b2c9d921 files: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24275
diff changeset
  2504
    ds = ctx.repo().dirstate
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2505
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2506
    for f in ctx.matches(m):
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2507
        if rev is None and ds[f] == 'r':
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2508
            continue
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2509
        fm.startitem()
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2510
        if ui.verbose:
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2511
            fc = ctx[f]
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2512
            fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags())
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2513
        fm.data(abspath=f)
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2514
        fm.write('path', fmt, m.rel(f))
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2515
        ret = 0
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2516
25228
63a57a2727b6 files: recurse into subrepos automatically with an explicit path
Matt Harbison <matt_harbison@yahoo.com>
parents: 25169
diff changeset
  2517
    for subpath in sorted(ctx.substate):
29802
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29795
diff changeset
  2518
        submatch = matchmod.subdirmatcher(subpath, m)
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29795
diff changeset
  2519
        if (subrepos or m.exact(subpath) or any(submatch.files())):
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2520
            sub = ctx.sub(subpath)
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2521
            try:
28387
97175d9bf7cf files: don't recurse into subrepos without a path or -S (issue5127)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28253
diff changeset
  2522
                recurse = m.exact(subpath) or subrepos
97175d9bf7cf files: don't recurse into subrepos without a path or -S (issue5127)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28253
diff changeset
  2523
                if sub.printfiles(ui, submatch, fm, fmt, recurse) == 0:
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2524
                    ret = 0
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2525
            except error.LookupError:
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2526
                ui.status(_("skipping missing subrepository: %s\n")
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2527
                               % m.abs(subpath))
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
  2528
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2529
    return ret
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
  2530
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2531
def remove(ui, repo, m, prefix, after, force, subrepos, warnings=None):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2532
    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
  2533
    ret = 0
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2534
    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
  2535
    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
  2536
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2537
    wctx = repo[None]
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2538
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2539
    if warnings is None:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2540
        warnings = []
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2541
        warn = True
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2542
    else:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2543
        warn = False
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2544
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2545
    subs = sorted(wctx.substate)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2546
    total = len(subs)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2547
    count = 0
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2548
    for subpath in subs:
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2549
        count += 1
29802
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29795
diff changeset
  2550
        submatch = matchmod.subdirmatcher(subpath, m)
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29795
diff changeset
  2551
        if subrepos or m.exact(subpath) or any(submatch.files()):
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2552
            ui.progress(_('searching'), count, total=total, unit=_('subrepos'))
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2553
            sub = wctx.sub(subpath)
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2554
            try:
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2555
                if sub.removefiles(submatch, prefix, after, force, subrepos,
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2556
                                   warnings):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2557
                    ret = 1
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2558
            except error.LookupError:
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2559
                warnings.append(_("skipping missing subrepository: %s\n")
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2560
                               % join(subpath))
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2561
    ui.progress(_('searching'), None)
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2562
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2563
    # warn about failure to delete explicit files/dirs
24635
21e1ece30f8c util: move dirs() and finddirs() from scmutil to util
Drew Gottlieb <drgott@google.com>
parents: 24603
diff changeset
  2564
    deleteddirs = util.dirs(deleted)
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2565
    files = m.files()
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2566
    total = len(files)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2567
    count = 0
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2568
    for f in files:
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2569
        def insubrepo():
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2570
            for subpath in wctx.substate:
29622
9c2cc107547f cmdutil: warnings not issued in remove if subrepopath overlaps
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29498
diff changeset
  2571
                if f.startswith(subpath + '/'):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2572
                    return True
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2573
            return False
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2574
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2575
        count += 1
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2576
        ui.progress(_('deleting'), count, total=total, unit=_('files'))
24955
1df233bcb7f6 remove: use ctx.hasdir(f) instead of 'f in ctx.dirs()'
Martin von Zweigbergk <martinvonz@google.com>
parents: 24947
diff changeset
  2577
        isdir = f in deleteddirs or wctx.hasdir(f)
29622
9c2cc107547f cmdutil: warnings not issued in remove if subrepopath overlaps
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29498
diff changeset
  2578
        if (f in repo.dirstate or isdir or f == '.'
9c2cc107547f cmdutil: warnings not issued in remove if subrepopath overlaps
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29498
diff changeset
  2579
            or insubrepo() or f in subs):
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2580
            continue
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
  2581
23674
6e36b9fc7869 remove: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents: 23673
diff changeset
  2582
        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
  2583
            if repo.wvfs.isdir(f):
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2584
                warnings.append(_('not removing %s: no tracked files\n')
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2585
                        % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2586
            else:
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2587
                warnings.append(_('not removing %s: file is untracked\n')
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2588
                        % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2589
        # 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
  2590
        ret = 1
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2591
    ui.progress(_('deleting'), None)
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2592
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2593
    if force:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2594
        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
  2595
    elif after:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2596
        list = deleted
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2597
        remaining = modified + added + clean
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2598
        total = len(remaining)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2599
        count = 0
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2600
        for f in remaining:
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2601
            count += 1
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2602
            ui.progress(_('skipping'), count, total=total, unit=_('files'))
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2603
            warnings.append(_('not removing %s: file still exists\n')
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2604
                    % m.rel(f))
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2605
            ret = 1
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2606
        ui.progress(_('skipping'), None)
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2607
    else:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2608
        list = deleted + clean
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2609
        total = len(modified) + len(added)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2610
        count = 0
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2611
        for f in modified:
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2612
            count += 1
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2613
            ui.progress(_('skipping'), count, total=total, unit=_('files'))
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2614
            warnings.append(_('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
  2615
                      ' 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
  2616
            ret = 1
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2617
        for f in added:
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2618
            count += 1
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2619
            ui.progress(_('skipping'), count, total=total, unit=_('files'))
29963
e824de573112 remove: specify hg in added warning
timeless <timeless@mozdev.org>
parents: 29956
diff changeset
  2620
            warnings.append(_("not removing %s: file has been marked for add"
e824de573112 remove: specify hg in added warning
timeless <timeless@mozdev.org>
parents: 29956
diff changeset
  2621
                      " (use 'hg forget' to undo add)\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
  2622
            ret = 1
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2623
        ui.progress(_('skipping'), None)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2624
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2625
    list = sorted(list)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2626
    total = len(list)
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2627
    count = 0
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2628
    for f in list:
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2629
        count += 1
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2630
        if ui.verbose or not m.exact(f):
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2631
            ui.progress(_('deleting'), count, total=total, unit=_('files'))
23686
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23674
diff changeset
  2632
            ui.status(_('removing %s\n') % m.rel(f))
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
  2633
    ui.progress(_('deleting'), None)
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2634
27802
ed44a66fd7ae with: use context manager for wlock in remove
Bryan O'Sullivan <bryano@fb.com>
parents: 27801
diff changeset
  2635
    with repo.wlock():
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2636
        if not after:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2637
            for f in list:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2638
                if f in added:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2639
                    continue # we never unlink added files on remove
31309
8908f985570c vfs: use repo.wvfs.unlinkpath
Mads Kiilerich <madski@unity3d.com>
parents: 31237
diff changeset
  2640
                repo.wvfs.unlinkpath(f, ignoremissing=True)
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2641
        repo[None].forget(list)
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2642
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2643
    if warn:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2644
        for warning in warnings:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2645
            ui.warn(warning)
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
  2646
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2647
    return ret
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
  2648
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2649
def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts):
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2650
    err = 1
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2651
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2652
    def write(path):
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2653
        filename = None
32582
7f4435078a8f cat: stop using makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
  2654
        if fntemplate:
7f4435078a8f cat: stop using makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
  2655
            filename = makefilename(repo, fntemplate, ctx.node(),
7f4435078a8f cat: stop using makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
  2656
                                    pathname=os.path.join(prefix, path))
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2657
        with formatter.maybereopen(basefm, filename, opts) as fm:
32583
7bfa1b199972 cat: use with statement to close output file
Yuya Nishihara <yuya@tcha.org>
parents: 32582
diff changeset
  2658
            data = ctx[path].data()
7bfa1b199972 cat: use with statement to close output file
Yuya Nishihara <yuya@tcha.org>
parents: 32582
diff changeset
  2659
            if opts.get('decode'):
7bfa1b199972 cat: use with statement to close output file
Yuya Nishihara <yuya@tcha.org>
parents: 32582
diff changeset
  2660
                data = repo.wwritedata(path, data)
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2661
            fm.startitem()
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2662
            fm.write('data', '%s', data)
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2663
            fm.data(abspath=path, path=matcher.rel(path))
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2664
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2665
    # 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
  2666
    # 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
  2667
    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
  2668
        file = matcher.files()[0]
30340
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2669
        mfl = repo.manifestlog
24718
a4191e0c728f cat: use ctx.manifestnode() in place of ctx._changeset[0]
Yuya Nishihara <yuya@tcha.org>
parents: 24711
diff changeset
  2670
        mfnode = ctx.manifestnode()
30340
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2671
        try:
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2672
            if mfnode and mfl[mfnode].find(file)[0]:
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2673
                write(file)
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2674
                return 0
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2675
        except KeyError:
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30332
diff changeset
  2676
            pass
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2677
29739
84a8de5ac901 cmdutil: remove duplicated badmatch call in cat()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29707
diff changeset
  2678
    for abs in ctx.walk(matcher):
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2679
        write(abs)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2680
        err = 0
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2681
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2682
    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
  2683
        sub = ctx.sub(subpath)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2684
        try:
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
  2685
            submatch = matchmod.subdirmatcher(subpath, matcher)
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2686
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32583
diff changeset
  2687
            if not sub.cat(submatch, basefm, fntemplate,
32540
f4cd4c49e302 cat: pass filename template as explicit argument
Yuya Nishihara <yuya@tcha.org>
parents: 32539
diff changeset
  2688
                           os.path.join(prefix, sub._path), **opts):
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2689
                err = 0
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2690
        except error.RepoLookupError:
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2691
            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
  2692
                           % os.path.join(prefix, subpath))
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
  2693
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2694
    return err
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
  2695
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
  2696
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
  2697
    '''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
  2698
    date = opts.get('date')
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  2699
    if date:
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6112
diff changeset
  2700
        opts['date'] = util.parsedate(date)
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
  2701
    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
  2702
    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
  2703
5829
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  2704
    # 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
  2705
    # that doesn't support addremove
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
  2706
    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
  2707
        if scmutil.addremove(repo, matcher, "", opts) != 0:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  2708
            raise error.Abort(
23535
72c23fa4f52f commit: abort if --addremove is specified, but fails
Matt Harbison <matt_harbison@yahoo.com>
parents: 23533
diff changeset
  2709
                _("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
  2710
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23509
diff changeset
  2711
    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
  2712
29819
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2713
def samefile(f, ctx1, ctx2):
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2714
    if f in ctx1.manifest():
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2715
        a = ctx1.filectx(f)
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2716
        if f in ctx2.manifest():
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2717
            b = ctx2.filectx(f)
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2718
            return (not a.cmp(b)
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2719
                    and a.flags() == b.flags())
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2720
        else:
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2721
            return False
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2722
    else:
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2723
        return f not in ctx2.manifest()
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2724
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2725
def amend(ui, repo, commitfunc, old, extra, pats, opts):
25930
221491bbaf7e cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25795
diff changeset
  2726
    # avoid cycle context -> subrepo -> cmdutil
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
  2727
    from . import context
25930
221491bbaf7e cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25795
diff changeset
  2728
23101
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2729
    # 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
  2730
    # marker creation requires that the current user's name is specified.
24379
8c445d8a915b obsolete: remove last instance of _enabled
Durham Goode <durham@fb.com>
parents: 24364
diff changeset
  2731
    if obsolete.isenabled(repo, obsolete.createmarkersopt):
23101
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
  2732
        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
  2733
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2734
    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
  2735
    base = old.p1()
25709
c87373179ff3 amend: move createmarkers evaluation earlier
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25694
diff changeset
  2736
    createmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt)
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2737
32921
5694311db6ed amend: use context manager for locking
Martin von Zweigbergk <martinvonz@google.com>
parents: 32878
diff changeset
  2738
    newid = None
5694311db6ed amend: use context manager for locking
Martin von Zweigbergk <martinvonz@google.com>
parents: 32878
diff changeset
  2739
    with repo.wlock(), repo.lock():
27868
d1a55366d825 with: use context manager in amend
Bryan O'Sullivan <bryano@fb.com>
parents: 27803
diff changeset
  2740
        with repo.transaction('amend') as tr:
17473
9732473aa24b amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17472
diff changeset
  2741
            # 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
  2742
            # 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
  2743
            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
  2744
            # 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
  2745
            # 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
  2746
            # `logmessage` anyway.
034e55bbf7c0 amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17812
diff changeset
  2747
            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
  2748
            # 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
  2749
            # 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
  2750
            ui.callhooks = False
27698
dad6404ccddb bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents: 27651
diff changeset
  2751
            activebookmark = repo._bookmarks.active
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2752
            try:
27698
dad6404ccddb bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents: 27651
diff changeset
  2753
                repo._bookmarks.active = 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
  2754
                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
  2755
                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
  2756
            finally:
27698
dad6404ccddb bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents: 27651
diff changeset
  2757
                repo._bookmarks.active = activebookmark
dad6404ccddb bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents: 27651
diff changeset
  2758
                repo._bookmarks.recordchange(tr)
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2759
                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
  2760
            ctx = repo[node]
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2761
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2762
            # 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
  2763
            #
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2764
            # 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
  2765
            #          |   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
  2766
            #          |   (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
  2767
            #          |
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2768
            # 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
  2769
            #          |
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2770
            # 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
  2771
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2772
            # 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
  2773
            # source)
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2774
            extra.update(old.extra())
16630
f30226b1a46a amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents: 16553
diff changeset
  2775
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2776
            # 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
  2777
            extra.update(ctx.extra())
16630
f30226b1a46a amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents: 16553
diff changeset
  2778
18909
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2779
            if len(old.parents()) > 1:
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2780
                # 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
  2781
                # slower repo.status() method
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2782
                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
  2783
                             for fn in st])
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2784
            else:
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2785
                files = set(old.files())
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2786
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2787
            # 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
  2788
            # 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
  2789
            # 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
  2790
            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
  2791
                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
  2792
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2793
                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
  2794
                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
  2795
                # 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
  2796
                copied = copies.pathcopies(base, ctx)
24169
ac41aa4a66ab amend: check for directory renames for both merge parents (issue4516)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24013
diff changeset
  2797
                if old.p2:
ac41aa4a66ab amend: check for directory renames for both merge parents (issue4516)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24013
diff changeset
  2798
                    copied.update(copies.pathcopies(old.p2(), ctx))
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2799
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2800
                # 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
  2801
                # 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
  2802
                # 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
  2803
                # 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
  2804
                # 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
  2805
                files.update(ctx.files())
29819
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29802
diff changeset
  2806
                files = [f for f in files if not samefile(f, ctx, base)]
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2807
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2808
                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
  2809
                    try:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2810
                        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
  2811
                        flags = fctx.flags()
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21579
diff changeset
  2812
                        mctx = context.memfilectx(repo,
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21579
diff changeset
  2813
                                                  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
  2814
                                                  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
  2815
                                                  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
  2816
                                                  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
  2817
                        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
  2818
                    except KeyError:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22278
diff changeset
  2819
                        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
  2820
            else:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2821
                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
  2822
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2823
                # 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
  2824
                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
  2825
                    try:
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2826
                        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
  2827
                    except KeyError:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22278
diff changeset
  2828
                        return None
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2829
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2830
                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
  2831
                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
  2832
            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
  2833
            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
  2834
            if not message:
22010
41e969cb9468 commit: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21999
diff changeset
  2835
                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
  2836
                message = old.description()
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2837
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
  2838
            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
  2839
            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
  2840
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2841
            new = context.memctx(repo,
18909
3a72c89a83ec amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents: 18853
diff changeset
  2842
                                 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
  2843
                                 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
  2844
                                 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
  2845
                                 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
  2846
                                 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
  2847
                                 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
  2848
                                 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
  2849
                                 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
  2850
27637
b502138f5faa cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents: 27625
diff changeset
  2851
            newdesc = changelog.stripdesc(new.description())
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
  2852
            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
  2853
                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
  2854
                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
  2855
                and date == old.date()
27973
ce9696193175 amend: don't preserve most extra fields
Siddharth Agarwal <sid0@fb.com>
parents: 27943
diff changeset
  2856
                and pureextra == old.extra()):
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
  2857
                # 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
  2858
                # 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
  2859
                #
a8aba2921456 amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17788
diff changeset
  2860
                # 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
  2861
                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
  2862
17472
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2863
            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
  2864
            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
  2865
                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
  2866
                    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
  2867
                else:
b0153cb8b64e commit: create new amend changeset as secret correctly for "--secret" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20072
diff changeset
  2868
                    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
  2869
                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
  2870
                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
  2871
            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
  2872
                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
  2873
            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
  2874
                # 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
  2875
                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
  2876
965fbe04fd96 amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17471
diff changeset
  2877
                # 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
  2878
                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
  2879
                if bms:
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2880
                    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
  2881
                    for bm in bms:
25694
5ede49f4383a amend: stop updating the bookmarks twice
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25693
diff changeset
  2882
                        ui.debug('moving bookmarks %r from %s to %s\n' %
5ede49f4383a amend: stop updating the bookmarks twice
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25693
diff changeset
  2883
                                 (marks, old.hex(), hex(newid)))
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 17891
diff changeset
  2884
                        marks[bm] = newid
25693
a6c1eac2fb1e amend: collaborate with the transaction when moving bookmarks
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
  2885
                    marks.recordchange(tr)
25710
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2886
                #commit the whole amend process
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2887
                if createmarkers:
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2888
                    # mark the new changeset as successor of the rewritten one
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2889
                    new = repo[newid]
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2890
                    obs = [(old, (new,))]
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2891
                    if node:
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2892
                        obs.append((ctx, ()))
68c83b8d407a amend: move obsmarkers creation in the "new changeset" conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25709
diff changeset
  2893
32327
3546a771e376 obsolete: add operation metadata to rebase/amend/histedit obsmarkers
Durham Goode <durham@fb.com>
parents: 32291
diff changeset
  2894
                    obsolete.createmarkers(repo, obs, operation='amend')
22951
6c86c673dde6 obsolete: add createmarkers option
Durham Goode <durham@fb.com>
parents: 22901
diff changeset
  2895
        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
  2896
            # 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
  2897
            # commit
17471
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2898
            if node:
ad1561723dde amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17468
diff changeset
  2899
                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
  2900
            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
  2901
            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
  2902
    return newid
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
  2903
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
  2904
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
  2905
    if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2906
        return ctx.description()
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2907
    return commitforceeditor(repo, ctx, subs, editform=editform,
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2908
                             unchangedmessagedetection=True)
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2909
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
  2910
def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2911
                      editform='', unchangedmessagedetection=False):
21923
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2912
    if not extramsg:
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
  2913
        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
  2914
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2915
    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
  2916
    forms.insert(0, 'changeset')
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2917
    templatetext = None
22012
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2918
    while forms:
32878
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2919
        ref = '.'.join(forms)
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2920
        if repo.ui.config('committemplate', ref):
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2921
            templatetext = committext = buildcommittemplate(
32878
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2922
                repo, ctx, subs, extramsg, ref)
22012
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2923
            break
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
  2924
        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
  2925
    else:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2926
        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
  2927
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2928
    # run editor in the repository root
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30506
diff changeset
  2929
    olddir = pycompat.getcwd()
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2930
    os.chdir(repo.root)
26750
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
  2931
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
  2932
    # make in-memory changes visible to external process
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
  2933
    tr = repo.currenttransaction()
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
  2934
    repo.dirstate.write(tr)
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
  2935
    pending = tr and tr.writepending() and repo.root
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
  2936
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2937
    editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
30836
565c07036066 cmdutil: add tmpdir parament to ui.edit calls
Sean Farley <sean@farley.io>
parents: 30833
diff changeset
  2938
                              editform=editform, pending=pending,
30848
7080652af6e6 ui: rename tmpdir parameter to more specific repopath
Sean Farley <sean@farley.io>
parents: 30836
diff changeset
  2939
                              repopath=repo.path)
30724
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
  2940
    text = editortext
30703
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
  2941
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
  2942
    # strip away anything below this special string (used for editors that want
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
  2943
    # to display the diff)
30724
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
  2944
    stripbelow = re.search(_linebelow, text, flags=re.MULTILINE)
30703
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
  2945
    if stripbelow:
30724
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
  2946
        text = text[:stripbelow.start()]
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
  2947
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
  2948
    text = re.sub("(?m)^HG:.*(\n|$)", "", text)
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2949
    os.chdir(olddir)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2950
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2951
    if finishdesc:
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2952
        text = finishdesc(text)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2953
    if not text.strip():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  2954
        raise error.Abort(_("empty commit message"))
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2955
    if unchangedmessagedetection and editortext == templatetext:
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
  2956
        raise error.Abort(_("commit message unchanged"))
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2957
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2958
    return text
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2959
32878
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2960
def buildcommittemplate(repo, ctx, subs, extramsg, ref):
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2961
    ui = repo.ui
32878
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2962
    spec = formatter.templatespec(ref, None, None)
32839
b425ec7fb7f6 cmdutil: pass templatespec tuple directly to changeset_templater (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32838
diff changeset
  2963
    t = changeset_templater(ui, repo, spec, None, {}, False)
32878
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2964
    t.t.cache.update((k, templater.unquotestring(v))
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32877
diff changeset
  2965
                     for k, v in repo.ui.configitems('committemplate'))
22013
de5cee8ba088 cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22012
diff changeset
  2966
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2967
    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
  2968
        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
  2969
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
  2970
    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
  2971
    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
  2972
    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
  2973
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2974
def hgprefix(msg):
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2975
    return "\n".join(["HG: %s" % a for a in msg.split("\n") if a])
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2976
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  2977
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
  2978
    edittext = []
8707
0550dfe4fca1 commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents: 8680
diff changeset
  2979
    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
  2980
    if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2981
        edittext.append(ctx.description())
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2982
    edittext.append("")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2983
    edittext.append("") # Empty line between message and comments.
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2984
    edittext.append(hgprefix(_("Enter commit message."
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2985
                      "  Lines beginning with 'HG:' are removed.")))
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2986
    edittext.append(hgprefix(extramsg))
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2987
    edittext.append("HG: --")
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2988
    edittext.append(hgprefix(_("user: %s") % ctx.user()))
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2989
    if ctx.p2():
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2990
        edittext.append(hgprefix(_("branch merge")))
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  2991
    if ctx.branch():
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2992
        edittext.append(hgprefix(_("branch '%s'") % ctx.branch()))
24986
fb9b7b937b3e bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents: 24955
diff changeset
  2993
    if bookmarks.isactivewdirparent(repo):
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2994
        edittext.append(hgprefix(_("bookmark '%s'") % repo._activebookmark))
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2995
    edittext.extend([hgprefix(_("subrepo %s") % s) for s in subs])
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2996
    edittext.extend([hgprefix(_("added %s") % f) for f in added])
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2997
    edittext.extend([hgprefix(_("changed %s") % f) for f in modified])
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  2998
    edittext.extend([hgprefix(_("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
  2999
    if not added and not modified and not removed:
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
  3000
        edittext.append(hgprefix(_("no files changed")))
8407
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  3001
    edittext.append("")
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
  3002
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
  3003
    return "\n".join(edittext)
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
  3004
26324
4a8e21578e14 addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26229
diff changeset
  3005
def commitstatus(repo, node, branch, bheads=None, opts=None):
4a8e21578e14 addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26229
diff changeset
  3006
    if opts is None:
4a8e21578e14 addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26229
diff changeset
  3007
        opts = {}
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3008
    ctx = repo[node]
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3009
    parents = ctx.parents()
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3010
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3011
    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
  3012
        [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
  3013
        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
  3014
        # 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
  3015
        # 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
  3016
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3017
        # 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
  3018
        #   N: null or no parent
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3019
        #   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
  3020
        #   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
  3021
        #   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
  3022
        # 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
  3023
        # 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
  3024
        # 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
  3025
        # printed anyway.
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3026
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3027
        # Par Msg Comment
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3028
        # 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
  3029
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3030
        # 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
  3031
        # 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
  3032
        # H N  n  usual case
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3033
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3034
        # 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
  3035
        # C B  y  branch merge
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3036
        # 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
  3037
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3038
        # 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
  3039
        # 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
  3040
        #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3041
        # 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
  3042
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3043
    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
  3044
        for r in parents:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3045
            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
  3046
                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
  3047
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3048
    if repo.ui.debugflag:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3049
        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
  3050
    elif repo.ui.verbose:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
  3051
        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
  3052
27943
02c5f8ad00ac commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents: 27868
diff changeset
  3053
def postcommitstatus(repo, pats, opts):
02c5f8ad00ac commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents: 27868
diff changeset
  3054
    return repo.status(match=scmutil.match(repo[None], pats, opts))
02c5f8ad00ac commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents: 27868
diff changeset
  3055
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3056
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
  3057
    parent, p2 = parents
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3058
    node = ctx.node()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3059
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3060
    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
  3061
    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
  3062
        parent = p2
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3063
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3064
    # 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
  3065
    # so have to walk both. do not print errors if files exist in one
24451
c3bbafef25d6 revert: comment that filesets are always evaluated against workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24450
diff changeset
  3066
    # but not other. in both cases, filesets should be evaluated against
c3bbafef25d6 revert: comment that filesets are always evaluated against workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24450
diff changeset
  3067
    # workingctx to get consistent result (issue4497). this means 'set:**'
c3bbafef25d6 revert: comment that filesets are always evaluated against workingctx
Yuya Nishihara <yuya@tcha.org>
parents: 24450
diff changeset
  3068
    # cannot be used to select missing files from target rev.
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3069
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3070
    # `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
  3071
    # The mapping is in the form:
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3072
    #   <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
  3073
    names = {}
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3074
27803
a8e8950ebd4d with: use context manager for wlock in revert
Bryan O'Sullivan <bryano@fb.com>
parents: 27802
diff changeset
  3075
    with repo.wlock():
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3076
        ## filling of the `names` mapping
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3077
        # 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
  3078
24475
06cbff4674a3 revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents: 24472
diff changeset
  3079
        interactive = opts.get('interactive', False)
24449
bab983bb6fd1 revert: define 'wctx' a little earlier and use it more
Martin von Zweigbergk <martinvonz@google.com>
parents: 24438
diff changeset
  3080
        wctx = repo[None]
bab983bb6fd1 revert: define 'wctx' a little earlier and use it more
Martin von Zweigbergk <martinvonz@google.com>
parents: 24438
diff changeset
  3081
        m = scmutil.match(wctx, pats, opts)
24479
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
  3082
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
  3083
        # we'll need this later
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
  3084
        targetsubs = sorted(s for s in wctx.substate if m(s))
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
  3085
24450
961790c35b4f revert: take fast path also when not reverting to '.'
Martin von Zweigbergk <martinvonz@google.com>
parents: 24449
diff changeset
  3086
        if not m.always():
32362
7b3c27af90c2 cmdutil: use repo[None].walk instead of repo.walk
Augie Fackler <augie@google.com>
parents: 32343
diff changeset
  3087
            matcher = matchmod.badmatch(m, lambda x, y: False)
32382
c87db79b9507 cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents: 32375
diff changeset
  3088
            for abs in wctx.walk(matcher):
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3089
                names[abs] = m.rel(abs), m.exact(abs)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3090
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3091
            # walk target manifest to fill `names`
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3092
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3093
            def badfn(path, msg):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3094
                if path in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3095
                    return
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3096
                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
  3097
                    return
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3098
                path_ = path + '/'
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3099
                for f in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3100
                    if f.startswith(path_):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3101
                        return
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3102
                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
  3103
25439
aaede04c0ba6 revert: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25438
diff changeset
  3104
            for abs in ctx.walk(matchmod.badmatch(m, badfn)):
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3105
                if abs not in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3106
                    names[abs] = m.rel(abs), m.exact(abs)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3107
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3108
            # Find status of all file in `names`.
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3109
            m = scmutil.matchfiles(repo, names)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3110
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3111
            changes = repo.status(node1=node, match=m,
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3112
                                  unknown=True, ignored=True, clean=True)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3113
        else:
24450
961790c35b4f revert: take fast path also when not reverting to '.'
Martin von Zweigbergk <martinvonz@google.com>
parents: 24449
diff changeset
  3114
            changes = repo.status(node1=node, match=m)
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3115
            for kind in changes:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3116
                for abs in kind:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3117
                    names[abs] = m.rel(abs), m.exact(abs)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3118
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3119
            m = scmutil.matchfiles(repo, names)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
  3120
23374
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3121
        modified = set(changes.modified)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3122
        added    = set(changes.added)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3123
        removed  = set(changes.removed)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3124
        _deleted = set(changes.deleted)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3125
        unknown  = set(changes.unknown)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3126
        unknown.update(changes.ignored)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3127
        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
  3128
        modadded = set()
22185
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
  3129
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
  3130
        # We need to account for the state of the file in the dirstate,
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
  3131
        # 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
  3132
        # 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
  3133
        # 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
  3134
        if parent == node:
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  3135
            dsmodified = modified
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  3136
            dsadded = added
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  3137
            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
  3138
            # 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
  3139
            localchanges = dsmodified | dsadded
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  3140
            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
  3141
        else:
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
  3142
            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
  3143
            dsmodified = set(changes.modified)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3144
            dsadded    = set(changes.added)
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
  3145
            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
  3146
            # 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
  3147
            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
  3148
22188
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  3149
            # 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
  3150
            clean |= dsremoved - removed
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  3151
            dsremoved &= removed
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  3152
            # 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
  3153
            removed -= dsremoved
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
  3154
22610
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  3155
            modadded = added & dsmodified
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  3156
            added -= modadded
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
  3157
22190
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  3158
            # tell newly modified apart.
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  3159
            dsmodified &= modified
29103
f2aa1c3e7e77 cmdutil: typo fix in comment
Augie Fackler <augie@google.com>
parents: 28999
diff changeset
  3160
            dsmodified |= modified & dsadded # dirstate added may need backup
22190
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  3161
            modified -= dsmodified
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
  3162
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
  3163
            # 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
  3164
            # 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
  3165
            # that purpose.
22208
d3659b3795e9 revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22205
diff changeset
  3166
            dsadded = added
d3659b3795e9 revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22205
diff changeset
  3167
22209
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  3168
        # 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
  3169
        # 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
  3170
        if p2 != nullid:
31134
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31078
diff changeset
  3171
            mergeadd = set(dsmodified)
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31078
diff changeset
  3172
            for path in dsmodified:
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31078
diff changeset
  3173
                if path in mf:
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31078
diff changeset
  3174
                    mergeadd.remove(path)
22209
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  3175
            dsadded |= mergeadd
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
  3176
            dsmodified -= mergeadd
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3177
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3178
        # 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
  3179
        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
  3180
        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
  3181
            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
  3182
            # 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
  3183
            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
  3184
                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
  3185
                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
  3186
31157
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3187
        # determine the exact nature of the deleted changesets
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3188
        deladded = set(_deleted)
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3189
        for path in _deleted:
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3190
            if path in mf:
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3191
                deladded.remove(path)
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3192
        deleted = _deleted - deladded
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31134
diff changeset
  3193
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
  3194
        # 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
  3195
        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
  3196
        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
  3197
            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
  3198
                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
  3199
        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
  3200
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  3201
        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
  3202
            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
  3203
                dsadded.add(abs)
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  3204
        deladded -= dsadded
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  3205
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
  3206
        # 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
  3207
        # 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
  3208
        # 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
  3209
        # 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
  3210
        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
  3211
        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
  3212
            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
  3213
            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
  3214
                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
  3215
        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
  3216
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
  3217
        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
  3218
        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
  3219
            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
  3220
            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
  3221
                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
  3222
        dsremoved -= dsremovunk
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3223
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3224
        # 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
  3225
        # (<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
  3226
        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
  3227
                   '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
  3228
                   'remove': ([], _('removing %s\n')),
22491
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  3229
                   '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
  3230
                   '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
  3231
                   '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
  3232
                   '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
  3233
                   '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
  3234
                  }
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3235
22608
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  3236
        # "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
  3237
        # 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
  3238
        # 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
  3239
        # These values are ordered for comparison purposes
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3240
        backupinteractive = 3 # do backup if interactively modified
22608
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
  3241
        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
  3242
        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
  3243
        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
  3244
        if opts.get('no_backup'):
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3245
            backupinteractive = backup = check = discard
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3246
        if interactive:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3247
            dsmodifiedbackup = backupinteractive
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3248
        else:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3249
            dsmodifiedbackup = backup
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3250
        tobackup = set()
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3251
22611
2ff28e07d7d6 revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22610
diff changeset
  3252
        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
  3253
        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
  3254
            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
  3255
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3256
        disptable = (
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3257
            # dispatch table:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3258
            #   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
  3259
            #   action
fc8bc2787528 revert: move manifest membership condition outside of the loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22013
diff changeset
  3260
            #   make backup
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  3261
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  3262
            ## 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
  3263
            # 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
  3264
            (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
  3265
            # 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
  3266
            (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
  3267
            # Modified compared to target, local change
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3268
            (dsmodified,    actions['revert'],   dsmodifiedbackup),
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
  3269
            # 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
  3270
            (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
  3271
            # 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
  3272
            (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
  3273
            # 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
  3274
            (modadded,      backupanddel,        backup),
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
  3275
            # 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
  3276
            (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
  3277
            # 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
  3278
            (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
  3279
            # 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
  3280
            (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
  3281
            # 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
  3282
            (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
  3283
            # 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
  3284
            (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
  3285
            ## 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
  3286
            # 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
  3287
            (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
  3288
            # 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
  3289
            (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
  3290
            )
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3291
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3292
        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
  3293
            # 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
  3294
            target = repo.wjoin(abs)
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3295
            # 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
  3296
            # 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
  3297
            # 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
  3298
            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
  3299
                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
  3300
                    continue
22233
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3301
                if xlist is not None:
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3302
                    xlist.append(abs)
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3303
                    if dobackup:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3304
                        # If in interactive mode, don't automatically create
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3305
                        # .orig files (issue4793)
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3306
                        if dobackup == backupinteractive:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3307
                            tobackup.add(abs)
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3308
                        elif (backup <= dobackup or wctx[abs].cmp(ctx[abs])):
27651
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 27637
diff changeset
  3309
                            bakname = scmutil.origpath(ui, repo, rel)
22609
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  3310
                            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
  3311
                                    (rel, bakname))
3760ebf786b8 revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22608
diff changeset
  3312
                            if not opts.get('dry_run'):
24475
06cbff4674a3 revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents: 24472
diff changeset
  3313
                                if interactive:
06cbff4674a3 revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents: 24472
diff changeset
  3314
                                    util.copyfile(target, bakname)
06cbff4674a3 revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents: 24472
diff changeset
  3315
                                else:
06cbff4674a3 revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents: 24472
diff changeset
  3316
                                    util.rename(target, bakname)
22233
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3317
                    if ui.verbose or not exact:
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3318
                        if not isinstance(msg, basestring):
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3319
                            msg = msg(abs)
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3320
                        ui.status(msg % rel)
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
  3321
                elif exact:
22234
fe9fc29ac2d0 revert: add a message to noop action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22233
diff changeset
  3322
                    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
  3323
                break
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
  3324
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3325
        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
  3326
            needdata = ('revert', 'add', 'undelete')
6156edaa82aa revert: move prefetch to after the actions logic
Durham Goode <durham@fb.com>
parents: 23955
diff changeset
  3327
            _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata])
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3328
            _performrevert(repo, parents, ctx, actions, interactive, tobackup)
19129
bd19587a3347 revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents: 19024
diff changeset
  3329
24134
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24064
diff changeset
  3330
        if targetsubs:
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24064
diff changeset
  3331
            # Revert the subrepos on the revert list
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24064
diff changeset
  3332
            for sub in targetsubs:
24463
06d199e66bbc revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 24455
diff changeset
  3333
                try:
24464
30ddc3cf76df revert: evaluate subrepos to revert against the working directory
Matt Harbison <matt_harbison@yahoo.com>
parents: 24463
diff changeset
  3334
                    wctx.sub(sub).revert(ctx.substate[sub], *pats, **opts)
24463
06d199e66bbc revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 24455
diff changeset
  3335
                except KeyError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  3336
                    raise error.Abort("subrepository '%s' does not exist in %s!"
24463
06d199e66bbc revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 24455
diff changeset
  3337
                                      % (sub, short(ctx.node())))
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
  3338
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
  3339
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
  3340
    """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
  3341
    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
  3342
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3343
def _performrevert(repo, parents, ctx, actions, interactive=False,
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3344
                   tobackup=None):
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  3345
    """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
  3346
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3347
    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
  3348
    the imminent revert.
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3349
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20790
diff changeset
  3350
    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
  3351
    """
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3352
    parent, p2 = parents
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3353
    node = ctx.node()
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3354
    excluded_files = []
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3355
    matcher_opts = {"exclude": excluded_files}
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3356
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3357
    def checkout(f):
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3358
        fc = ctx[f]
25755
72d395e399c1 cmdutil: remove useless dirstate.normallookup() invocation in revert()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25739
diff changeset
  3359
        repo.wwrite(f, fc.data(), fc.flags())
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3360
30532
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3361
    def doremove(f):
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3362
        try:
31309
8908f985570c vfs: use repo.wvfs.unlinkpath
Mads Kiilerich <madski@unity3d.com>
parents: 31237
diff changeset
  3363
            repo.wvfs.unlinkpath(f)
30532
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3364
        except OSError:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3365
            pass
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3366
        repo.dirstate.remove(f)
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3367
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3368
    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
  3369
    for f in actions['forget'][0]:
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3370
        if interactive:
30530
74013a831872 style: avoid an unnecessary line split
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30519
diff changeset
  3371
            choice = repo.ui.promptchoice(
30531
841092fd6b85 revert: indicate the default choice when prompting to forget files
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30530
diff changeset
  3372
                _("forget added file %s (Yn)?$$ &Yes $$ &No") % f)
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3373
            if choice == 0:
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3374
                repo.dirstate.drop(f)
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3375
            else:
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3376
                excluded_files.append(repo.wjoin(f))
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3377
        else:
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3378
            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
  3379
    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
  3380
        audit_path(f)
30532
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3381
        if interactive:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3382
            choice = repo.ui.promptchoice(
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3383
                _("remove added file %s (Yn)?$$ &Yes $$ &No") % f)
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3384
            if choice == 0:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3385
                doremove(f)
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3386
            else:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3387
                excluded_files.append(repo.wjoin(f))
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3388
        else:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30531
diff changeset
  3389
            doremove(f)
22491
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  3390
    for f in actions['drop'][0]:
5e16fe6fdd32 revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22490
diff changeset
  3391
        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
  3392
        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
  3393
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3394
    normal = None
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3395
    if node == parent:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3396
        # 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
  3397
        # 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
  3398
        # 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
  3399
        if p2 != nullid:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3400
            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
  3401
        else:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3402
            normal = repo.dirstate.normal
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3403
25259
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
  3404
    newlyaddedandmodifiedfiles = set()
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3405
    if interactive:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3406
        # Prompt the user for changes to revert
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3407
        torevert = [repo.wjoin(f) for f in actions['revert'][0]]
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
  3408
        m = scmutil.match(ctx, torevert, matcher_opts)
25258
f37a69ec3f47 revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents: 25257
diff changeset
  3409
        diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
f37a69ec3f47 revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents: 25257
diff changeset
  3410
        diffopts.nodates = True
f37a69ec3f47 revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents: 25257
diff changeset
  3411
        diffopts.git = True
31196
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3412
        operation = 'discard'
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3413
        reversehunks = True
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3414
        if node != parent:
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3415
            operation = 'revert'
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3416
            reversehunks = repo.ui.configbool('experimental',
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3417
                                              'revertalternateinteractivemode',
3af9a9628ecf revert: always display hunks reversed when reverting to parent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31171
diff changeset
  3418
                                              True)
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3419
        if reversehunks:
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3420
            diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3421
        else:
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3422
            diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3423
        originalchunks = patch.parsepatch(diff)
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3424
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3425
        try:
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3426
29283
14eee72c8d52 revert: use "discard"/"revert" verb when reverting interactively (issue5143)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 29216
diff changeset
  3427
            chunks, opts = recordfilter(repo.ui, originalchunks,
14eee72c8d52 revert: use "discard"/"revert" verb when reverting interactively (issue5143)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 29216
diff changeset
  3428
                                        operation=operation)
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3429
            if reversehunks:
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3430
                chunks = patch.reversehunks(chunks)
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
  3431
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
  3432
        except patch.PatchError as err:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  3433
            raise error.Abort(_('error parsing patch: %s') % err)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3434
25259
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
  3435
        newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3436
        if tobackup is None:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3437
            tobackup = set()
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3438
        # Apply changes
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28837
diff changeset
  3439
        fp = stringio()
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3440
        for c in chunks:
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3441
            # Create a backup file only if this hunk should be backed up
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3442
            if ishunk(c) and c.header.filename() in tobackup:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3443
                abs = c.header.filename()
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3444
                target = repo.wjoin(abs)
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3445
                bakname = scmutil.origpath(repo.ui, repo, m.rel(abs))
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3446
                util.copyfile(target, bakname)
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
  3447
                tobackup.remove(abs)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3448
            c.write(fp)
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3449
        dopatch = fp.tell()
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3450
        fp.seek(0)
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3451
        if dopatch:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3452
            try:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3453
                patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
  3454
            except patch.PatchError as err:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  3455
                raise error.Abort(str(err))
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3456
        del fp
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3457
    else:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3458
        for f in actions['revert'][0]:
25755
72d395e399c1 cmdutil: remove useless dirstate.normallookup() invocation in revert()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25739
diff changeset
  3459
            checkout(f)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3460
            if normal:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
  3461
                normal(f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3462
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  3463
    for f in actions['add'][0]:
25259
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
  3464
        # Don't checkout modified files, they are already created by the diff
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
  3465
        if f not in newlyaddedandmodifiedfiles:
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
  3466
            checkout(f)
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
  3467
            repo.dirstate.add(f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3468
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3469
    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
  3470
    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
  3471
        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
  3472
    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
  3473
        checkout(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3474
        normal(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3475
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
  3476
    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
  3477
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
  3478
    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
  3479
        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
  3480
            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
  3481
32343
d47d7d3bd07b extensions: show deprecation warning for the use of cmdutil.command
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
  3482
class command(registrar.command):
d47d7d3bd07b extensions: show deprecation warning for the use of cmdutil.command
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
  3483
    def _doregister(self, func, name, *args, **kwargs):
d47d7d3bd07b extensions: show deprecation warning for the use of cmdutil.command
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
  3484
        func._deprecatedregistrar = True  # flag for deprecwarn in extensions.py
d47d7d3bd07b extensions: show deprecation warning for the use of cmdutil.command
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
  3485
        return super(command, self)._doregister(func, name, *args, **kwargs)
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  3486
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  3487
# 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
  3488
# 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
  3489
# "findcommonoutgoing()"
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  3490
outgoinghooks = util.hooks()
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
  3491
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
  3492
# 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
  3493
summaryhooks = util.hooks()
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3494
21047
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  3495
# 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
  3496
#
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  3497
# 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
  3498
#  (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
  3499
#
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  3500
# 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
  3501
#  - (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
  3502
#  - (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
  3503
summaryremotehooks = util.hooks()
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
  3504
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3505
# 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
  3506
# 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
  3507
# note: bisect is intentionally excluded
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3508
# (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
  3509
unfinishedstates = [
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3510
    ('graftstate', True, False, _('graft in progress'),
19482
499fc471296b update: add tracking of interrupted updates (issue3113)
Matt Mackall <mpm@selenic.com>
parents: 19474
diff changeset
  3511
     _("use 'hg graft --continue' or 'hg update' to abort")),
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3512
    ('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
  3513
     _("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
  3514
    ]
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3515
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3516
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
  3517
    '''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
  3518
    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
  3519
    bailifchanged().
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3520
    '''
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3521
    for f, clearable, allowcommit, msg, hint in unfinishedstates:
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3522
        if commit and allowcommit:
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3523
            continue
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3524
        if repo.vfs.exists(f):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  3525
            raise error.Abort(msg, hint=hint)
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3526
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3527
def clearunfinished(repo):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3528
    '''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
  3529
    that are clearable.
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
  3530
    '''
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3531
    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
  3532
        if not clearable and repo.vfs.exists(f):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
  3533
            raise error.Abort(msg, hint=hint)
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
  3534
    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
  3535
        if clearable and repo.vfs.exists(f):
31320
1b0db28dadf1 cmdutil: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31309
diff changeset
  3536
            util.unlink(repo.vfs.join(f))
24991
4169a4f83548 cmdutil: add class to restore dirstate during unexpected failure
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24988
diff changeset
  3537
27624
d46db4390715 resolve: suggest the next action
timeless <timeless@mozdev.org>
parents: 27622
diff changeset
  3538
afterresolvedstates = [
27625
cdb9493a7e2f graft: hook afterresolvedstates
timeless <timeless@mozdev.org>
parents: 27624
diff changeset
  3539
    ('graftstate',
cdb9493a7e2f graft: hook afterresolvedstates
timeless <timeless@mozdev.org>
parents: 27624
diff changeset
  3540
     _('hg graft --continue')),
27624
d46db4390715 resolve: suggest the next action
timeless <timeless@mozdev.org>
parents: 27622
diff changeset
  3541
    ]
d46db4390715 resolve: suggest the next action
timeless <timeless@mozdev.org>
parents: 27622
diff changeset
  3542
28120
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3543
def howtocontinue(repo):
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3544
    '''Check for an unfinished operation and return the command to finish
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3545
    it.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3546
30332
318a24b52eeb spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents: 30272
diff changeset
  3547
    afterresolvedstates tuples define a .hg/{file} and the corresponding
28120
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3548
    command needed to finish it.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3549
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3550
    Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3551
    a boolean.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3552
    '''
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3553
    contmsg = _("continue: %s")
27624
d46db4390715 resolve: suggest the next action
timeless <timeless@mozdev.org>
parents: 27622
diff changeset
  3554
    for f, msg in afterresolvedstates:
d46db4390715 resolve: suggest the next action
timeless <timeless@mozdev.org>
parents: 27622
diff changeset
  3555
        if repo.vfs.exists(f):
28120
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3556
            return contmsg % msg, True
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3557
    workingctx = repo[None]
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3558
    dirty = any(repo.status()) or any(workingctx.sub(s).dirty()
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3559
                                         for s in workingctx.substate)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3560
    if dirty:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3561
        return contmsg % _("hg commit"), False
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3562
    return None, None
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3563
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3564
def checkafterresolved(repo):
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3565
    '''Inform the user about the next action after completing hg resolve
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3566
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3567
    If there's a matching afterresolvedstates, howtocontinue will yield
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3568
    repo.ui.warn as the reporter.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3569
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3570
    Otherwise, it will yield repo.ui.note.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3571
    '''
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3572
    msg, warning = howtocontinue(repo)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3573
    if msg is not None:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3574
        if warning:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3575
            repo.ui.warn("%s\n" % msg)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3576
        else:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3577
            repo.ui.note("%s\n" % msg)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3578
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3579
def wrongtooltocontinue(repo, task):
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3580
    '''Raise an abort suggesting how to properly continue if there is an
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3581
    active task.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3582
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3583
    Uses howtocontinue() to find the active task.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3584
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3585
    If there's no task (repo.ui.note for 'hg commit'), it does not offer
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3586
    a hint.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3587
    '''
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3588
    after = howtocontinue(repo)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3589
    hint = None
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3590
    if after[1]:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3591
        hint = after[0]
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
  3592
    raise error.Abort(_('no %s in progress') % task, hint=hint)