Mercurial > hg
annotate mercurial/cmdutil.py @ 20408:3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
publicancestors returned the parents of the public ancestors ... and
changegroupsubset used the parents of these as base for the bundle. That gave
bundles with one layer of changesets more than necessary.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 10 Feb 2014 00:52:56 +0100 |
parents | d4f804caa0ed |
children | 78f4c2b7052f |
rev | line source |
---|---|
2957 | 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 | 6 # GNU General Public License version 2 or any later version. |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
7 |
6211
f89fd07fc51d
Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents:
6190
diff
changeset
|
8 from node import hex, nullid, nullrev, short |
3891 | 9 from i18n import _ |
14269
66257848c154
cmdutil: fix errors reported by pyflakes test
Sune Foldager <cryo@cyanite.org>
parents:
14259
diff
changeset
|
10 import os, sys, errno, re, tempfile |
15214
231aac5280ba
rebase: move updatedirstate into cmdutil so it can be shared
Matt Mackall <mpm@selenic.com>
parents:
14986
diff
changeset
|
11 import util, scmutil, templater, patch, error, templatekw, revlog, copies |
12085
6f833fc3ccab
Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents:
12032
diff
changeset
|
12 import match as matchmod |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
13 import context, repair, graphmod, revset, phases, obsolete, pathutil |
17811
a8aba2921456
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17788
diff
changeset
|
14 import changelog |
18538
94317c2d53b8
commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents:
18364
diff
changeset
|
15 import bookmarks |
17471
ad1561723dde
amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17468
diff
changeset
|
16 import lock as lockmod |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
17 |
10401
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
18 def parsealiases(cmd): |
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
19 return cmd.lstrip("^").split("|") |
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
20 |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
21 def findpossible(cmd, table, strict=False): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
22 """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
23 Return cmd -> (aliases, command table entry) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
24 for each matching command. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
25 Return debug commands (or their aliases) only if no normal command matches. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
26 """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
27 choice = {} |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
28 debugchoice = {} |
15600
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
29 |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
30 if cmd in table: |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
31 # short-circuit exact matches, "log" alias beats "^log|history" |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
32 keys = [cmd] |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
33 else: |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
34 keys = table.keys() |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
35 |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
36 for e in keys: |
10401
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
37 aliases = parsealiases(e) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
38 found = None |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
39 if cmd in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
40 found = cmd |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
41 elif not strict: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
42 for a in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
43 if a.startswith(cmd): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
44 found = a |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
45 break |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
46 if found is not None: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
47 if aliases[0].startswith("debug") or found.startswith("debug"): |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
48 debugchoice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
49 else: |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
50 choice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
51 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
52 if not choice and debugchoice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
53 choice = debugchoice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
54 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
55 return choice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
56 |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
57 def findcmd(cmd, table, strict=True): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
58 """Return (aliases, command table entry) for command string.""" |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
59 choice = findpossible(cmd, table, strict) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
60 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5843
diff
changeset
|
61 if cmd in choice: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
62 return choice[cmd] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
63 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
64 if len(choice) > 1: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
65 clist = choice.keys() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
66 clist.sort() |
7643
9a1ea6587557
error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents:
7404
diff
changeset
|
67 raise error.AmbiguousCommand(cmd, clist) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
68 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
69 if choice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
70 return choice.values()[0] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
71 |
7643
9a1ea6587557
error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents:
7404
diff
changeset
|
72 raise error.UnknownCommand(cmd) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
73 |
10402
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
74 def findrepo(p): |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
75 while not os.path.isdir(os.path.join(p, ".hg")): |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
76 oldp, p = p, os.path.dirname(p) |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
77 if p == oldp: |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
78 return None |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
79 |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
80 return p |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
81 |
14289
d68ddccf276b
cmdutil: bail_if_changed to bailifchanged
Matt Mackall <mpm@selenic.com>
parents:
14269
diff
changeset
|
82 def bailifchanged(repo): |
13878
a8d13ee0ce68
misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents:
13769
diff
changeset
|
83 if repo.dirstate.p2() != nullid: |
5716
be367cbafe70
cmdutil: make bail_if_changed bail on uncommitted merge
Matt Mackall <mpm@selenic.com>
parents:
5610
diff
changeset
|
84 raise util.Abort(_('outstanding uncommitted merge')) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
85 modified, added, removed, deleted = repo.status()[:4] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
86 if modified or added or removed or deleted: |
19804
061ce98c888d
cmdutil.bailifchanged: standardize error message for dirty working dir
Siddharth Agarwal <sid0@fb.com>
parents:
19730
diff
changeset
|
87 raise util.Abort(_('uncommitted changes')) |
15231
cd6f10dccf16
cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents:
15214
diff
changeset
|
88 ctx = repo[None] |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
89 for s in sorted(ctx.substate): |
15231
cd6f10dccf16
cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents:
15214
diff
changeset
|
90 if ctx.sub(s).dirty(): |
cd6f10dccf16
cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents:
15214
diff
changeset
|
91 raise util.Abort(_("uncommitted changes in subrepo %s") % s) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
92 |
14635
217b7d83afc3
cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents:
14518
diff
changeset
|
93 def logmessage(ui, opts): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
94 """ get the log message according to -m and -l option """ |
7667
bd5c37d792e6
cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7643
diff
changeset
|
95 message = opts.get('message') |
bd5c37d792e6
cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7643
diff
changeset
|
96 logfile = opts.get('logfile') |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
97 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
98 if message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
99 raise util.Abort(_('options --message and --logfile are mutually ' |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
100 'exclusive')) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
101 if not message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
102 try: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
103 if logfile == '-': |
14635
217b7d83afc3
cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents:
14518
diff
changeset
|
104 message = ui.fin.read() |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
105 else: |
14249
f4766e1bb0b3
cmdutil: normalize log message eols when reading from file
Patrick Mezard <pmezard@gmail.com>
parents:
14232
diff
changeset
|
106 message = '\n'.join(util.readfile(logfile).splitlines()) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
107 except IOError, inst: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
108 raise util.Abort(_("can't read commit message '%s': %s") % |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
109 (logfile, inst.strerror)) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
110 return message |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
111 |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
112 def loglimit(opts): |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
113 """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
|
114 limit = opts.get('limit') |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
115 if limit: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
116 try: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
117 limit = int(limit) |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
118 except ValueError: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
119 raise util.Abort(_('limit must be a positive integer')) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
120 if limit <= 0: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
121 raise util.Abort(_('limit must be positive')) |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
122 else: |
10111
27457d31ae3f
cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10061
diff
changeset
|
123 limit = None |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
124 return limit |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
125 |
14986
70e11de6964d
export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents:
14948
diff
changeset
|
126 def makefilename(repo, pat, node, desc=None, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
127 total=None, seqno=None, revwidth=None, pathname=None): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
128 node_expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
129 'H': lambda: hex(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
130 'R': lambda: str(repo.changelog.rev(node)), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
131 '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
|
132 'm': lambda: re.sub('[^\w]', '_', str(desc)) |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
133 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
134 expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
135 '%': lambda: '%', |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
136 'b': lambda: os.path.basename(repo.root), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
137 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
138 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
139 try: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
140 if node: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
141 expander.update(node_expander) |
4836
0e2d0a78f81a
archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4825
diff
changeset
|
142 if node: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
143 expander['r'] = (lambda: |
4836
0e2d0a78f81a
archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4825
diff
changeset
|
144 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
|
145 if total is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
146 expander['N'] = lambda: str(total) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
147 if seqno is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
148 expander['n'] = lambda: str(seqno) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
149 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
|
150 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
|
151 if pathname is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
152 expander['s'] = lambda: os.path.basename(pathname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
153 expander['d'] = lambda: os.path.dirname(pathname) or '.' |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
154 expander['p'] = lambda: pathname |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
155 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
156 newname = [] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
157 patlen = len(pat) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
158 i = 0 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
159 while i < patlen: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
160 c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
161 if c == '%': |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
162 i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
163 c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
164 c = expander[c]() |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
165 newname.append(c) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
166 i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
167 return ''.join(newname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
168 except KeyError, inst: |
8761
0289f384e1e5
Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents:
8731
diff
changeset
|
169 raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
3072
bc3fe3b5b785
Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2958
diff
changeset
|
170 inst.args[0]) |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
171 |
14986
70e11de6964d
export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents:
14948
diff
changeset
|
172 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
|
173 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
|
174 pathname=None): |
7319
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
175 |
13769
8796fb6af67e
cmdutil: fix mode handling in make_file
Adrian Buehlmann <adrian@cadifra.com>
parents:
13534
diff
changeset
|
176 writable = mode not in ('r', 'rb') |
7319
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
177 |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
178 if not pat or pat == '-': |
14637
5e9d691229d5
cmdutil: use ui descriptors in makefileobj
Idan Kamara <idankk86@gmail.com>
parents:
14635
diff
changeset
|
179 fp = writable and repo.ui.fout or repo.ui.fin |
14948
32302480b402
cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14671
diff
changeset
|
180 if util.safehasattr(fp, 'fileno'): |
14638
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
181 return os.fdopen(os.dup(fp.fileno()), mode) |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
182 else: |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
183 # if this fp can't be duped properly, return |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
184 # a dummy object that can be closed |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
185 class wrappedfileobj(object): |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
186 noop = lambda x: None |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
187 def __init__(self, f): |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
188 self.f = f |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
189 def __getattr__(self, attr): |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
190 if attr == 'close': |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
191 return self.noop |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
192 else: |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
193 return getattr(self.f, attr) |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
194 |
1bdbca0b6604
cmdutil: return a dummy, closable file object if it cannot be duped
Idan Kamara <idankk86@gmail.com>
parents:
14637
diff
changeset
|
195 return wrappedfileobj(fp) |
14948
32302480b402
cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14671
diff
changeset
|
196 if util.safehasattr(pat, 'write') and writable: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
197 return pat |
14948
32302480b402
cmdutil: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14671
diff
changeset
|
198 if util.safehasattr(pat, 'read') and 'r' in mode: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
199 return pat |
18613
1a2f4c633410
export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents:
18538
diff
changeset
|
200 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
|
201 if modemap is not None: |
b7f76db06dc0
cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents:
19894
diff
changeset
|
202 mode = modemap.get(fn, mode) |
b7f76db06dc0
cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents:
19894
diff
changeset
|
203 if mode == 'wb': |
b7f76db06dc0
cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara <yuya@tcha.org>
parents:
19894
diff
changeset
|
204 modemap[fn] = 'ab' |
18613
1a2f4c633410
export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents:
18538
diff
changeset
|
205 return open(fn, mode) |
2882
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2874
diff
changeset
|
206 |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
207 def openrevlog(repo, cmd, file_, opts): |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
208 """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
|
209 cl = opts['changelog'] |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
210 mf = opts['manifest'] |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
211 msg = None |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
212 if cl and mf: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
213 msg = _('cannot specify --changelog and --manifest at the same time') |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
214 elif cl or mf: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
215 if file_: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
216 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
|
217 elif not repo: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
218 msg = _('cannot specify --changelog or --manifest ' |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
219 'without a repository') |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
220 if msg: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
221 raise util.Abort(msg) |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
222 |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
223 r = None |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
224 if repo: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
225 if cl: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
226 r = repo.changelog |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
227 elif mf: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
228 r = repo.manifest |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
229 elif file_: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
230 filelog = repo.file(file_) |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
231 if len(filelog): |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
232 r = filelog |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
233 if not r: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
234 if not file_: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
235 raise error.CommandError(cmd, _('invalid arguments')) |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
236 if not os.path.isfile(file_): |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
237 raise util.Abort(_("revlog '%s' not found") % file_) |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
238 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
239 file_[:-2] + ".i") |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
240 return r |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
241 |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
242 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
|
243 # called with the repo lock held |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
244 # |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
245 # hgsep => pathname that uses "/" to separate directories |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
246 # 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
|
247 cwd = repo.getcwd() |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
248 targets = {} |
5607 | 249 after = opts.get("after") |
250 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
|
251 wctx = repo[None] |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
252 |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
253 def walkpat(pat): |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
254 srcs = [] |
11223
0d09f2244805
rename: make --after work if source is already in R state
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11177
diff
changeset
|
255 badstates = after and '?' or '?r' |
14671
35c2cc322ba8
scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents:
14638
diff
changeset
|
256 m = scmutil.match(repo[None], [pat], opts, globbed=True) |
6586
d3463007d368
walk: return a single value
Matt Mackall <mpm@selenic.com>
parents:
6585
diff
changeset
|
257 for abs in repo.walk(m): |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
258 state = repo.dirstate[abs] |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
259 rel = m.rel(abs) |
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
260 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
|
261 if state in badstates: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
262 if exact and state == '?': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
263 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
|
264 if exact and state == 'r': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
265 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
|
266 ' remove\n') % rel) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
267 continue |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
268 # abs: hgsep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
269 # rel: ossep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
270 srcs.append((abs, rel, exact)) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
271 return srcs |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
272 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
273 # abssrc: hgsep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
274 # relsrc: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
275 # otarget: ossep |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
276 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
|
277 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
|
278 if '/' in abstarget: |
e596a631210e
dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents:
16458
diff
changeset
|
279 # 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
|
280 # case only renames, like a => A. |
e596a631210e
dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents:
16458
diff
changeset
|
281 abspath, absname = abstarget.rsplit('/', 1) |
e596a631210e
dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents:
16458
diff
changeset
|
282 abstarget = repo.dirstate.normalize(abspath) + '/' + absname |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
283 reltarget = repo.pathto(abstarget, cwd) |
5607 | 284 target = repo.wjoin(abstarget) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
285 src = repo.wjoin(abssrc) |
5608 | 286 state = repo.dirstate[abstarget] |
5607 | 287 |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13945
diff
changeset
|
288 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
|
289 |
5607 | 290 # check for collisions |
291 prevsrc = targets.get(abstarget) | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
292 if prevsrc is not None: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
293 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
|
294 (reltarget, repo.pathto(abssrc, cwd), |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
295 repo.pathto(prevsrc, cwd))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
296 return |
5607 | 297 |
298 # check for overwrites | |
12342
70236d6fd844
rename: do not overwrite existing broken symlinks
Patrick Mezard <pmezard@gmail.com>
parents:
11950
diff
changeset
|
299 exists = os.path.lexists(target) |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
300 samefile = False |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
301 if exists and abssrc != abstarget: |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
302 if (repo.dirstate.normalize(abssrc) == |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
303 repo.dirstate.normalize(abstarget)): |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
304 if not rename: |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
305 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
|
306 return |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
307 exists = False |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
308 samefile = True |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
309 |
8117
2b30d8488819
remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents:
8013
diff
changeset
|
310 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
|
311 if not opts['force']: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
312 ui.warn(_('%s: not overwriting - file exists\n') % |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
313 reltarget) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
314 return |
5607 | 315 |
316 if after: | |
5608 | 317 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
|
318 if rename: |
e8d10d085f47
cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents:
11061
diff
changeset
|
319 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
|
320 (relsrc, reltarget)) |
e8d10d085f47
cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents:
11061
diff
changeset
|
321 else: |
e8d10d085f47
cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents:
11061
diff
changeset
|
322 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
|
323 (relsrc, reltarget)) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
324 return |
5608 | 325 elif not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
326 try: |
5608 | 327 if exists: |
328 os.unlink(target) | |
329 targetdir = os.path.dirname(target) or '.' | |
330 if not os.path.isdir(targetdir): | |
331 os.makedirs(targetdir) | |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
332 if samefile: |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
333 tmp = target + "~hgrename" |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
334 os.rename(src, tmp) |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
335 os.rename(tmp, target) |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
336 else: |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
337 util.copyfile(src, target) |
14518
a67e866f46f9
workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents:
14442
diff
changeset
|
338 srcexists = True |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
339 except IOError, inst: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
340 if inst.errno == errno.ENOENT: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
341 ui.warn(_('%s: deleted in working copy\n') % relsrc) |
14518
a67e866f46f9
workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents:
14442
diff
changeset
|
342 srcexists = False |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
343 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
344 ui.warn(_('%s: cannot copy - %s\n') % |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
345 (relsrc, inst.strerror)) |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
346 return True # report a failure |
5607 | 347 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
348 if ui.verbose or not exact: |
7894
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
349 if rename: |
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
350 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
|
351 else: |
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
352 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
5608 | 353 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
354 targets[abstarget] = abssrc |
5607 | 355 |
356 # fix up dirstate | |
14321
003d63bb4fa5
scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14320
diff
changeset
|
357 scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget, |
003d63bb4fa5
scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14320
diff
changeset
|
358 dryrun=dryrun, cwd=cwd) |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
359 if rename and not dryrun: |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
360 if not after and srcexists and not samefile: |
14518
a67e866f46f9
workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents:
14442
diff
changeset
|
361 util.unlinkpath(repo.wjoin(abssrc)) |
a67e866f46f9
workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents:
14442
diff
changeset
|
362 wctx.forget([abssrc]) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
363 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
364 # pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
365 # dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
366 # srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
367 # return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
368 def targetpathfn(pat, dest, srcs): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
369 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
|
370 abspfx = pathutil.canonpath(repo.root, cwd, pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
371 abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
372 if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
373 striplen = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
374 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
375 striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
376 if striplen: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
377 striplen += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
378 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
|
379 elif destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
380 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
381 os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
382 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
383 res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
384 return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
385 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
386 # pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
387 # dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
388 # srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
389 # return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
390 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
|
391 if matchmod.patkind(pat): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
392 # a mercurial pattern |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
393 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
394 os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
395 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
|
396 abspfx = pathutil.canonpath(repo.root, cwd, pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
397 if len(abspfx) < len(srcs[0][0]): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
398 # 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
|
399 # 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
|
400 def evalpath(striplen): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
401 score = 0 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
402 for s in srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
403 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
|
404 if os.path.lexists(t): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
405 score += 1 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
406 return score |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
407 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
408 abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
409 striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
410 if striplen: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
411 striplen += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
412 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
|
413 score = evalpath(striplen) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
414 striplen1 = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
415 if striplen1: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
416 striplen1 += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
417 if evalpath(striplen1) > score: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
418 striplen = striplen1 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
419 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
420 util.localpath(p)[striplen:]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
421 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
422 # a file |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
423 if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
424 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
425 os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
426 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
427 res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
428 return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
429 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
430 |
14321
003d63bb4fa5
scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14320
diff
changeset
|
431 pats = scmutil.expandpats(pats) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
432 if not pats: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
433 raise util.Abort(_('no source or destination specified')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
434 if len(pats) == 1: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
435 raise util.Abort(_('no destination specified')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
436 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
|
437 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
|
438 if not destdirexists: |
12085
6f833fc3ccab
Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents:
12032
diff
changeset
|
439 if len(pats) > 1 or matchmod.patkind(pats[0]): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
440 raise util.Abort(_('with multiple sources, destination must be an ' |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
441 '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
|
442 if util.endswithsep(dest): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
443 raise util.Abort(_('destination %s is not a directory') % dest) |
5607 | 444 |
445 tfn = targetpathfn | |
446 if after: | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
447 tfn = targetpathafterfn |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
448 copylist = [] |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
449 for pat in pats: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
450 srcs = walkpat(pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
451 if not srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
452 continue |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
453 copylist.append((tfn(pat, dest, srcs), srcs)) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
454 if not copylist: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
455 raise util.Abort(_('no files to copy')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
456 |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
457 errors = 0 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
458 for targetpath, srcs in copylist: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
459 for abssrc, relsrc, exact in srcs: |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
460 if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
461 errors += 1 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
462 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
463 if errors: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
464 ui.warn(_('(consider using --after)\n')) |
5609 | 465 |
11177
6a64813276ed
commands: initial audit of exit codes
Matt Mackall <mpm@selenic.com>
parents:
11152
diff
changeset
|
466 return errors != 0 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
467 |
9513
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
468 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
10012
2bfe1a23dafa
cmdutil: service: add appendpid parameter to append pids to pid file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9975
diff
changeset
|
469 runargs=None, appendpid=False): |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
470 '''Run a command as a service.''' |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
471 |
19867
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
472 def writepid(pid): |
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
473 if opts['pid_file']: |
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
474 mode = appendpid and 'a' or 'w' |
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
475 fp = open(opts['pid_file'], mode) |
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
476 fp.write(str(pid) + '\n') |
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
477 fp.close() |
edce20ebe1f3
cmdutil.service: move pidfile writing to a local function
Siddharth Agarwal <sid0@fb.com>
parents:
19804
diff
changeset
|
478 |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
479 if opts['daemon'] and not opts['daemon_pipefds']: |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
480 # Signal child process startup with file removal |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
481 lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
482 os.close(lockfd) |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
483 try: |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
484 if not runargs: |
10239
8e4be44a676f
Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents:
10238
diff
changeset
|
485 runargs = util.hgcmd() + sys.argv[1:] |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
486 runargs.append('--daemon-pipefds=%s' % lockpath) |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
487 # Don't pass --cwd to the child process, because we've already |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
488 # changed directory. |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
489 for i in xrange(1, len(runargs)): |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
490 if runargs[i].startswith('--cwd='): |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
491 del runargs[i] |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
492 break |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
493 elif runargs[i].startswith('--cwd'): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
494 del runargs[i:i + 2] |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
495 break |
10344
9501cde4c034
util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
496 def condfn(): |
9501cde4c034
util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
497 return not os.path.exists(lockpath) |
9501cde4c034
util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
498 pid = util.rundetached(runargs, condfn) |
9501cde4c034
util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
499 if pid < 0: |
9501cde4c034
util: make spawndetached() handle subprocess early terminations
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
500 raise util.Abort(_('child process failed to start')) |
19868
0532c8f8e911
cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents:
19867
diff
changeset
|
501 writepid(pid) |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
502 finally: |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
503 try: |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
504 os.unlink(lockpath) |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
505 except OSError, e: |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
506 if e.errno != errno.ENOENT: |
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
507 raise |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
508 if parentfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
509 return parentfn(pid) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
510 else: |
9896
2c2f7593ffc4
cmdutil.service: do not _exit(0) in the parent process
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9668
diff
changeset
|
511 return |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
512 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
513 if initfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
514 initfn() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
515 |
19868
0532c8f8e911
cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents:
19867
diff
changeset
|
516 if not opts['daemon']: |
0532c8f8e911
cmdutil.service: move pidfile writing to the parent in daemon mode
Siddharth Agarwal <sid0@fb.com>
parents:
19867
diff
changeset
|
517 writepid(os.getpid()) |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
518 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
519 if opts['daemon_pipefds']: |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
520 lockpath = opts['daemon_pipefds'] |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
521 try: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
522 os.setsid() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
523 except AttributeError: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
524 pass |
10238
e22695b4472f
cmdutil: replace unix pipe handshake with file lock
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
525 os.unlink(lockpath) |
10240
3af4b39afe2a
cmdutil: hide child window created by win32 spawndetached()
Patrick Mezard <pmezard@gmail.com>
parents:
10239
diff
changeset
|
526 util.hidewindow() |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
527 sys.stdout.flush() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
528 sys.stderr.flush() |
8789
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
529 |
17391
fc24c10424d2
util: replace util.nulldev with os.devnull
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17308
diff
changeset
|
530 nullfd = os.open(os.devnull, os.O_RDWR) |
8789
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
531 logfilefd = nullfd |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
532 if logfile: |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
533 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
534 os.dup2(nullfd, 0) |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
535 os.dup2(logfilefd, 1) |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
536 os.dup2(logfilefd, 2) |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
537 if nullfd not in (0, 1, 2): |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
538 os.close(nullfd) |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
539 if logfile and logfilefd not in (0, 1, 2): |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
540 os.close(logfilefd) |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
541 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
542 if runfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
543 return runfn() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
544 |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
545 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
546 opts=None): |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
547 '''export changesets as hg patches.''' |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
548 |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
549 total = len(revs) |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
550 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
|
551 filemode = {} |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
552 |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
553 def single(rev, seqno, fp): |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
554 ctx = repo[rev] |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
555 node = ctx.node() |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
556 parents = [p.node() for p in ctx.parents() if p] |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
557 branch = ctx.branch() |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
558 if switch_parent: |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
559 parents.reverse() |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
560 prev = (parents and parents[0]) or nullid |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
561 |
13400
14f3795a5ed7
explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13386
diff
changeset
|
562 shouldclose = False |
17460
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
563 if not fp and len(template) > 0: |
14986
70e11de6964d
export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents:
14948
diff
changeset
|
564 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
|
565 desc = desc_lines[0] #Commit always has a first line. |
70e11de6964d
export: add %m to file format string (first line of the commit message)
Andrzej Bieniek <andyhelp@gmail.com>
parents:
14948
diff
changeset
|
566 fp = makefileobj(repo, template, node, desc=desc, total=total, |
18613
1a2f4c633410
export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents:
18538
diff
changeset
|
567 seqno=seqno, revwidth=revwidth, mode='wb', |
1a2f4c633410
export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents:
18538
diff
changeset
|
568 modemap=filemode) |
13467
31aa2e5b0750
export: only close files which export itself has opened
Waqas Hussain <waqas20@gmail.com>
parents:
13400
diff
changeset
|
569 if fp != template: |
31aa2e5b0750
export: only close files which export itself has opened
Waqas Hussain <waqas20@gmail.com>
parents:
13400
diff
changeset
|
570 shouldclose = True |
17460
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
571 if fp and fp != sys.stdout and util.safehasattr(fp, 'name'): |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
572 repo.ui.note("%s\n" % fp.name) |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
573 |
17460
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
574 if not fp: |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
575 write = repo.ui.write |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
576 else: |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
577 def write(s, **kw): |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
578 fp.write(s) |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
579 |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
580 |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
581 write("# HG changeset patch\n") |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
582 write("# User %s\n" % ctx.user()) |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
583 write("# Date %d %d\n" % ctx.date()) |
18648
76b69cccb07a
export: show 'Date' header in a format that also is readable for humans
Mads Kiilerich <mads@kiilerich.com>
parents:
18613
diff
changeset
|
584 write("# %s\n" % util.datestr(ctx.date())) |
11821
15aa42aaae4c
cmdutil: remove unnecessary parenthesis
Martin Geisler <mg@aragost.com>
parents:
11635
diff
changeset
|
585 if branch and branch != 'default': |
17460
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
586 write("# Branch %s\n" % branch) |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
587 write("# Node ID %s\n" % hex(node)) |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
588 write("# Parent %s\n" % hex(prev)) |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
589 if len(parents) > 1: |
17460
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
590 write("# Parent %s\n" % hex(parents[1])) |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
591 write(ctx.description().rstrip()) |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
592 write("\n\n") |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
593 |
17460
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
594 for chunk, label in patch.diffui(repo, prev, node, opts=opts): |
a306837f8c87
color: enabled color support for export command (issue1507)
Ankur Dahiya <ankurd@fb.com>
parents:
17424
diff
changeset
|
595 write(chunk, label=label) |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
596 |
13400
14f3795a5ed7
explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13386
diff
changeset
|
597 if shouldclose: |
14f3795a5ed7
explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13386
diff
changeset
|
598 fp.close() |
13081
79184986658c
export: flush the file pointer between patches
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13047
diff
changeset
|
599 |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
600 for seqno, rev in enumerate(revs): |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
601 single(rev, seqno + 1, fp) |
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
602 |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
603 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
|
604 changes=None, stat=False, fp=None, prefix='', |
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
605 listsubrepos=False): |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
606 '''show diff or diffstat.''' |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
607 if fp is None: |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
608 write = ui.write |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
609 else: |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
610 def write(s, **kw): |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
611 fp.write(s) |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
612 |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
613 if stat: |
11950
d157e040ac4c
log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents:
11488
diff
changeset
|
614 diffopts = diffopts.copy(context=0) |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
615 width = 80 |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
616 if not ui.plain(): |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12619
diff
changeset
|
617 width = ui.termwidth() |
12167
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
618 chunks = patch.diff(repo, node1, node2, match, changes, diffopts, |
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
619 prefix=prefix) |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
620 for chunk, label in patch.diffstatui(util.iterlines(chunks), |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
621 width=width, |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
622 git=diffopts.git): |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
623 write(chunk, label=label) |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
624 else: |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
625 for chunk, label in patch.diffui(repo, node1, node2, match, |
12167
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
626 changes, diffopts, prefix=prefix): |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
627 write(chunk, label=label) |
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
628 |
12167
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
629 if listsubrepos: |
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
630 ctx1 = repo[node1] |
12175
c0a8f9dea0f6
subrepos: handle modified but uncommitted .hgsub
Martin Geisler <mg@lazybytes.net>
parents:
12167
diff
changeset
|
631 ctx2 = repo[node2] |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
632 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
|
633 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
|
634 try: |
cfc15cbecc5e
diff: don't crash when diffing a revision with a deleted subrepo (issue3153)
Renato Cunha <renato@renatocunha.com>
parents:
15600
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 # 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
|
639 # 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
|
640 # 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
|
641 tempnode2 = None |
12167
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
642 submatch = matchmod.narrowmatcher(subpath, match) |
18006
0c10cf819146
subrepo: add argument to "diff()" to pass "ui" of caller side (issue3712) (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17924
diff
changeset
|
643 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
|
644 stat=stat, fp=fp, prefix=prefix) |
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
645 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
646 class changeset_printer(object): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
647 '''show changeset information when templating not requested.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
648 |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
649 def __init__(self, ui, repo, patch, diffopts, buffered): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
650 self.ui = ui |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
651 self.repo = repo |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
652 self.buffered = buffered |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
653 self.patch = patch |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
654 self.diffopts = diffopts |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
655 self.header = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
656 self.hunk = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
657 self.lastheader = None |
10152
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
658 self.footer = None |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
659 |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
660 def flush(self, rev): |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
661 if rev in self.header: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
662 h = self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
663 if h != self.lastheader: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
664 self.lastheader = h |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
665 self.ui.write(h) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
666 del self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
667 if rev in self.hunk: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
668 self.ui.write(self.hunk[rev]) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
669 del self.hunk[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
670 return 1 |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
671 return 0 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
672 |
10152
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
673 def close(self): |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
674 if self.footer: |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
675 self.ui.write(self.footer) |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
676 |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
677 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
|
678 if self.buffered: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
679 self.ui.pushbuffer() |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
680 self._show(ctx, copies, matchfn, props) |
10819
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
681 self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True) |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
682 else: |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
683 self._show(ctx, copies, matchfn, props) |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
684 |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
685 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
|
686 '''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
|
687 changenode = ctx.node() |
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
688 rev = ctx.rev() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
689 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
690 if self.ui.quiet: |
10819
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
691 self.ui.write("%d:%s\n" % (rev, short(changenode)), |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
692 label='log.node') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
693 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
694 |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
695 log = self.repo.changelog |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
696 date = util.datestr(ctx.date()) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
697 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
698 hexfunc = self.ui.debugflag and hex or short |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
699 |
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
|
700 parents = [(p, hexfunc(log.node(p))) |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
701 for p in self._meaningful_parentrevs(log, rev)] |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
702 |
17891
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
703 # 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
|
704 self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)), |
17788
9912baaae7df
color: add additional changeset.phase label to log.changeset and log.parent
Sean Farley <sean.michael.farley@gmail.com>
parents:
17746
diff
changeset
|
705 label='log.changeset changeset.%s' % ctx.phasestr()) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
706 |
9637
64425c5a9257
cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents:
9547
diff
changeset
|
707 branch = ctx.branch() |
4176
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4055
diff
changeset
|
708 # 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
|
709 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
|
710 # 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
|
711 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
|
712 label='log.branch') |
13386
f78bc5ddbe4f
templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents:
13121
diff
changeset
|
713 for bookmark in self.repo.nodebookmarks(changenode): |
17891
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
714 # i18n: column positioning for "hg log" |
13386
f78bc5ddbe4f
templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents:
13121
diff
changeset
|
715 self.ui.write(_("bookmark: %s\n") % bookmark, |
f78bc5ddbe4f
templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents:
13121
diff
changeset
|
716 label='log.bookmark') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
717 for tag in self.repo.nodetags(changenode): |
17891
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
718 # 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
|
719 self.ui.write(_("tag: %s\n") % tag, |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
720 label='log.tag') |
15907
51fc43253a52
changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15777
diff
changeset
|
721 if self.ui.debugflag and ctx.phase(): |
17891
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
722 # i18n: column positioning for "hg log" |
15907
51fc43253a52
changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15777
diff
changeset
|
723 self.ui.write(_("phase: %s\n") % _(ctx.phasestr()), |
51fc43253a52
changeset_printer: display changeset phase on debug level
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15777
diff
changeset
|
724 label='log.phase') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
725 for parent in parents: |
17891
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
726 # 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
|
727 self.ui.write(_("parent: %d:%s\n") % parent, |
17788
9912baaae7df
color: add additional changeset.phase label to log.changeset and log.parent
Sean Farley <sean.michael.farley@gmail.com>
parents:
17746
diff
changeset
|
728 label='log.parent changeset.%s' % ctx.phasestr()) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
729 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
730 if self.ui.debugflag: |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
731 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
|
732 # i18n: column positioning for "hg log" |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
733 self.ui.write(_("manifest: %d:%s\n") % |
10819
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
734 (self.repo.manifest.rev(mnode), hex(mnode)), |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
735 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
|
736 # 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
|
737 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
|
738 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
|
739 # 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
|
740 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
|
741 label='log.date') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
742 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
743 if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
744 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
17891
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
745 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
|
746 _("files:"), |
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
747 # 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
|
748 _("files+:"), |
8f85151ce201
i18n: add "i18n" comment to column positioning messages of "hg log"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17863
diff
changeset
|
749 # 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
|
750 _("files-:")], files): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
751 if value: |
10819
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
752 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
|
753 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
|
754 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
|
755 # 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
|
756 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
|
757 label='ui.note log.files') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
758 if copies and self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
759 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
|
760 # 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
|
761 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
|
762 label='ui.note log.copies') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
763 |
9637
64425c5a9257
cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents:
9547
diff
changeset
|
764 extra = ctx.extra() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
765 if extra and self.ui.debugflag: |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8189
diff
changeset
|
766 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
|
767 # i18n: column positioning for "hg log" |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
768 self.ui.write(_("extra: %s=%s\n") |
10819
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
769 % (key, value.encode('string_escape')), |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
770 label='ui.debug log.extra') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
771 |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
772 description = ctx.description().strip() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
773 if description: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
774 if self.ui.verbose: |
10819
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
775 self.ui.write(_("description:\n"), |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
776 label='ui.note log.description') |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
777 self.ui.write(description, |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
778 label='ui.note log.description') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
779 self.ui.write("\n\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
780 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
|
781 # i18n: column positioning for "hg log" |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
782 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
|
783 description.splitlines()[0], |
36c6a667d733
cmdutil: make use of output labeling in changeset_printer
Brodie Rao <brodie@bitheap.org>
parents:
10724
diff
changeset
|
784 label='log.summary') |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
785 self.ui.write("\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
786 |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
787 self.showpatch(changenode, matchfn) |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
788 |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
789 def showpatch(self, node, matchfn): |
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
790 if not matchfn: |
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
791 matchfn = self.patch |
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
792 if matchfn: |
11061
51d0387523c6
log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents:
11059
diff
changeset
|
793 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
|
794 diff = self.diffopts.get('patch') |
11061
51d0387523c6
log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents:
11059
diff
changeset
|
795 diffopts = patch.diffopts(self.ui, self.diffopts) |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
796 prev = self.repo.changelog.parents(node)[0] |
11950
d157e040ac4c
log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents:
11488
diff
changeset
|
797 if stat: |
d157e040ac4c
log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents:
11488
diff
changeset
|
798 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
|
799 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
|
800 if diff: |
d157e040ac4c
log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents:
11488
diff
changeset
|
801 if stat: |
d157e040ac4c
log: fix the bug 'hg log --stat -p == hg log --stat'
Alecs King <alecsk@gmail.com>
parents:
11488
diff
changeset
|
802 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
|
803 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
|
804 match=matchfn, stat=False) |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
805 self.ui.write("\n") |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
806 |
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
|
807 def _meaningful_parentrevs(self, log, rev): |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
808 """Return list of meaningful (or all if debug) parentrevs for rev. |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
809 |
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
|
810 For merges (two non-nullrev revisions) both parents are meaningful. |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
811 Otherwise the first parent revision is considered meaningful if it |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
812 is not the preceding revision. |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
813 """ |
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
|
814 parents = log.parentrevs(rev) |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
815 if not self.ui.debugflag and parents[1] == nullrev: |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
816 if parents[0] >= rev - 1: |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
817 parents = [] |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
818 else: |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
819 parents = [parents[0]] |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
820 return parents |
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
821 |
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
|
822 |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
823 class changeset_templater(changeset_printer): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
824 '''format changeset information.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
825 |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
826 def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): |
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
827 changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) |
8360
acc202b71619
templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8312
diff
changeset
|
828 formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
10061
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
829 defaulttempl = { |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
830 'parent': '{rev}:{node|formatnode} ', |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
831 'manifest': '{rev}:{node|formatnode}', |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
832 'file_copy': '{name} ({source})', |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
833 'extra': '{key}={value|stringescape}' |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
834 } |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
835 # filecopy is preserved for compatibility reasons |
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
836 defaulttempl['filecopy'] = defaulttempl['file_copy'] |
8360
acc202b71619
templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8312
diff
changeset
|
837 self.t = templater.templater(mapfile, {'formatnode': formatnode}, |
10061
9e2ab10728a2
Make {file_copies} usable as a --template key
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
838 cache=defaulttempl) |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
839 self.cache = {} |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
840 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
841 def use_template(self, t): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
842 '''set template string to use''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
843 self.t.cache['changeset'] = t |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
844 |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
845 def _meaningful_parentrevs(self, ctx): |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
846 """Return list of meaningful (or all if debug) parentrevs for rev. |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
847 """ |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
848 parents = ctx.parents() |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
849 if len(parents) > 1: |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
850 return parents |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
851 if self.ui.debugflag: |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
852 return [parents[0], self.repo['null']] |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
853 if parents[0].rev() >= ctx.rev() - 1: |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
854 return [] |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
855 return parents |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
856 |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
857 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
|
858 '''show a single changeset or file revision''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
859 |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
10026
diff
changeset
|
860 showlist = templatekw.showlist |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
861 |
10058
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
862 # showparents() behaviour depends on ui trace level which |
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
863 # causes unexpected behaviours at templating level and makes |
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
864 # it harder to extract it in a standalone function. Its |
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
865 # behaviour cannot be changed so leave it here for now. |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
866 def showparents(**args): |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10250
diff
changeset
|
867 ctx = args['ctx'] |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
868 parents = [[('rev', p.rev()), ('node', p.hex())] |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
869 for p in self._meaningful_parentrevs(ctx)] |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
870 return showlist('parent', parents, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
871 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
872 props = props.copy() |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
873 props.update(templatekw.keywords) |
10058
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
874 props['parents'] = showparents |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
10026
diff
changeset
|
875 props['templ'] = self.t |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
876 props['ctx'] = ctx |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
877 props['repo'] = self.repo |
10058
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
878 props['revcache'] = {'copies': copies} |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
879 props['cache'] = self.cache |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
880 |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
881 # find correct templates for current mode |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
882 |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
883 tmplmodes = [ |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
884 (True, None), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
885 (self.ui.verbose, 'verbose'), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
886 (self.ui.quiet, 'quiet'), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
887 (self.ui.debugflag, 'debug'), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
888 ] |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
889 |
10152
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
890 types = {'header': '', 'footer':'', 'changeset': 'changeset'} |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
891 for mode, postfix in tmplmodes: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
892 for type in types: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
893 cur = postfix and ('%s_%s' % (type, postfix)) or type |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
894 if mode and cur in self.t: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
895 types[type] = cur |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
896 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
897 try: |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
898 |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
899 # write header |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
900 if types['header']: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
901 h = templater.stringify(self.t(types['header'], **props)) |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
902 if self.buffered: |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
903 self.header[ctx.rev()] = h |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
904 else: |
11465
ace5bd98bee3
heads: fix templating of headers again (issue2130)
Simon Howkins <simonh@symbian.org>
parents:
11441
diff
changeset
|
905 if self.lastheader != h: |
ace5bd98bee3
heads: fix templating of headers again (issue2130)
Simon Howkins <simonh@symbian.org>
parents:
11441
diff
changeset
|
906 self.lastheader = h |
11441
d74fe370ab04
cmdutil: only output style header once in non-buffered mode (issue2130)
Simon Howkins <simonh@symbian.org>
parents:
11410
diff
changeset
|
907 self.ui.write(h) |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
908 |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
909 # write changeset metadata, then patch if requested |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
910 key = types['changeset'] |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
911 self.ui.write(templater.stringify(self.t(key, **props))) |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
912 self.showpatch(ctx.node(), matchfn) |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
913 |
10160
48653dea23dd
Bugfix and test for hg log XML output
Robert Bachmann <rbachm@gmail.com>
parents:
10152
diff
changeset
|
914 if types['footer']: |
10152
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
915 if not self.footer: |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
916 self.footer = templater.stringify(self.t(types['footer'], |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
917 **props)) |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
918 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
919 except KeyError, inst: |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
920 msg = _("%s: no key named '%s'") |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
921 raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
922 except SyntaxError, inst: |
10829
56fffc9c8928
cmdutil: do not translate trivial string
Martin Geisler <mg@lazybytes.net>
parents:
10819
diff
changeset
|
923 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
924 |
11488
f786fc4b8764
log: follow filenames through renames (issue647)
Mads Kiilerich <mads@kiilerich.com>
parents:
11465
diff
changeset
|
925 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
|
926 """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
|
927 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
928 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
|
929 1. option 'template' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
930 2. option 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
931 3. [ui] setting 'logtemplate' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
932 4. [ui] setting 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
933 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
|
934 regular display via changeset_printer() is done. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
935 """ |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
936 # options |
19894
df91e2df6ba3
cmdutil: use None as default value for "function pointer" instead of False
Mads Kiilerich <madski@unity3d.com>
parents:
19868
diff
changeset
|
937 patch = None |
11061
51d0387523c6
log: add --stat for diffstat output
Yuya Nishihara <yuya@tcha.org>
parents:
11059
diff
changeset
|
938 if opts.get('patch') or opts.get('stat'): |
14322
a90131b85fd8
scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents:
14321
diff
changeset
|
939 patch = scmutil.matchall(repo) |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
940 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
941 tmpl = opts.get('template') |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
942 style = None |
20066
64b4f0cd7336
templater: fix escaping in nested string literals (issue4102)
Matt Mackall <mpm@selenic.com>
parents:
19944
diff
changeset
|
943 if not tmpl: |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
944 style = opts.get('style') |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
945 |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
946 # ui settings |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
947 if not (tmpl or style): |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
948 tmpl = ui.config('ui', 'logtemplate') |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
949 if tmpl: |
16678
48b1674ac1e7
templater: handle SyntaxError when parsing ui.logtemplate
Martin Geisler <martin@geisler.net>
parents:
16630
diff
changeset
|
950 try: |
48b1674ac1e7
templater: handle SyntaxError when parsing ui.logtemplate
Martin Geisler <martin@geisler.net>
parents:
16630
diff
changeset
|
951 tmpl = templater.parsestring(tmpl) |
48b1674ac1e7
templater: handle SyntaxError when parsing ui.logtemplate
Martin Geisler <martin@geisler.net>
parents:
16630
diff
changeset
|
952 except SyntaxError: |
48b1674ac1e7
templater: handle SyntaxError when parsing ui.logtemplate
Martin Geisler <martin@geisler.net>
parents:
16630
diff
changeset
|
953 tmpl = templater.parsestring(tmpl, quoted=False) |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
954 else: |
10249
8ebb34b0f6f7
cmdutil: expand style paths (issue1948)
Patrick Mezard <pmezard@gmail.com>
parents:
10025
diff
changeset
|
955 style = util.expandpath(ui.config('ui', 'style', '')) |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
956 |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
957 if not (tmpl or style): |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
958 return changeset_printer(ui, repo, patch, opts, buffered) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
959 |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
960 mapfile = None |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
961 if style and not tmpl: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
962 mapfile = style |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
963 if not os.path.split(mapfile)[0]: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
964 mapname = (templater.templatepath('map-cmdline.' + mapfile) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
965 or templater.templatepath(mapfile)) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
966 if mapname: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
967 mapfile = mapname |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
968 |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
969 try: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
970 t = changeset_templater(ui, repo, patch, opts, mapfile, buffered) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
971 except SyntaxError, inst: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
972 raise util.Abort(inst.args[0]) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
973 if tmpl: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
974 t.use_template(tmpl) |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
975 return t |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
976 |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
977 def finddate(ui, repo, date): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
978 """Find the tipmost changeset that matches the given date spec""" |
9667 | 979 |
5836
c5c9a022bd9a
Tweak finddate to pass date directly.
mark.williamson@cl.cam.ac.uk
parents:
5829
diff
changeset
|
980 df = util.matchdate(date) |
14322
a90131b85fd8
scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents:
14321
diff
changeset
|
981 m = scmutil.matchall(repo) |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
982 results = {} |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
983 |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
984 def prep(ctx, fns): |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
985 d = ctx.date() |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
986 if df(d[0]): |
9668
2c24471d478c
cmdutil: fix bug in finddate() implementation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9667
diff
changeset
|
987 results[ctx.rev()] = d |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
988 |
9667 | 989 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
|
990 rev = ctx.rev() |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
991 if rev in results: |
16937
5487088f0d43
cmdutil: lowercase finddate status message
Martin Geisler <mg@aragost.com>
parents:
16776
diff
changeset
|
992 ui.status(_("found revision %s from %s\n") % |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
993 (rev, util.datestr(results[rev]))) |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
994 return str(rev) |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
995 |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
996 raise util.Abort(_("revision matching date not found")) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
997 |
16776
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
998 def increasingwindows(start, end, windowsize=8, sizelimit=512): |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
999 if start < end: |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1000 while start < end: |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1001 yield start, min(windowsize, end - start) |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1002 start += windowsize |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1003 if windowsize < sizelimit: |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1004 windowsize *= 2 |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1005 else: |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1006 while start > end: |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1007 yield start, min(windowsize, start - end - 1) |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1008 start -= windowsize |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1009 if windowsize < sizelimit: |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1010 windowsize *= 2 |
5088d0b9a9a1
cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents:
16701
diff
changeset
|
1011 |
19290
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1012 class FileWalkError(Exception): |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1013 pass |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1014 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1015 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
|
1016 '''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
|
1017 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1018 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
|
1019 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1020 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
|
1021 filelogs alone. |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1022 ''' |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1023 wanted = set() |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1024 copies = [] |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1025 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
|
1026 def filerevgen(filelog, last): |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1027 """ |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1028 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
|
1029 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1030 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
|
1031 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
|
1032 tuples in backwards order |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1033 """ |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1034 cl_count = len(repo) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1035 revs = [] |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1036 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
|
1037 linkrev = filelog.linkrev(j) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1038 if linkrev < minrev: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1039 continue |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1040 # 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
|
1041 # 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
|
1042 if linkrev >= cl_count: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1043 break |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1044 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1045 parentlinkrevs = [] |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1046 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
|
1047 if p != nullrev: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1048 parentlinkrevs.append(filelog.linkrev(p)) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1049 n = filelog.node(j) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1050 revs.append((linkrev, parentlinkrevs, |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1051 follow and filelog.renamed(n))) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1052 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1053 return reversed(revs) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1054 def iterfiles(): |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1055 pctx = repo['.'] |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1056 for filename in match.files(): |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1057 if follow: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1058 if filename not in pctx: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1059 raise util.Abort(_('cannot follow file not in parent ' |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1060 'revision: "%s"') % filename) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1061 yield filename, pctx[filename].filenode() |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1062 else: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1063 yield filename, None |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1064 for filename_node in copies: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1065 yield filename_node |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1066 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1067 for file_, node in iterfiles(): |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1068 filelog = repo.file(file_) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1069 if not len(filelog): |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1070 if node is None: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1071 # 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
|
1072 # 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
|
1073 if follow: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1074 raise util.Abort( |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1075 _('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
|
1076 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
|
1077 else: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1078 continue |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1079 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1080 if node is None: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1081 last = len(filelog) - 1 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1082 else: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1083 last = filelog.rev(node) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1084 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1085 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1086 # keep track of all ancestors of the file |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1087 ancestors = set([filelog.linkrev(last)]) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1088 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1089 # 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
|
1090 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
|
1091 if not follow: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1092 if rev > maxrev: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1093 continue |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1094 else: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1095 # 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
|
1096 # rev to us: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1097 # 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
|
1098 # 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
|
1099 # to explore the file graph |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1100 if rev not in ancestors: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1101 continue |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1102 # XXX insert 1327 fix here |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1103 if flparentlinkrevs: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1104 ancestors.update(flparentlinkrevs) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1105 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1106 fncache.setdefault(rev, []).append(file_) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1107 wanted.add(rev) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1108 if copied: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1109 copies.append(copied) |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1110 |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1111 return wanted |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1112 |
9665
1de5ebfa5585
walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents:
9664
diff
changeset
|
1113 def walkchangerevs(repo, match, opts, prepare): |
7807
bd8f44638847
help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents:
7779
diff
changeset
|
1114 '''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
|
1115 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1116 Callers most commonly need to iterate backwards over the history |
7807
bd8f44638847
help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents:
7779
diff
changeset
|
1117 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
|
1118 performance, so we use iterators in a "windowed" way. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1119 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1120 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
|
1121 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
|
1122 order (usually backwards) to display it. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1123 |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1124 This function returns an iterator yielding contexts. Before |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1125 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
|
1126 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
|
1127 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1128 follow = opts.get('follow') or opts.get('follow_first') |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1129 |
17676
f87683a1b02a
clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17675
diff
changeset
|
1130 if opts.get('rev'): |
f87683a1b02a
clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17675
diff
changeset
|
1131 revs = scmutil.revrange(repo, opts.get('rev')) |
f87683a1b02a
clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17675
diff
changeset
|
1132 elif follow: |
f87683a1b02a
clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17675
diff
changeset
|
1133 revs = repo.revs('reverse(:.)') |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1134 else: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20072
diff
changeset
|
1135 revs = revset.baseset(repo) |
17676
f87683a1b02a
clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17675
diff
changeset
|
1136 revs.reverse() |
11281
b724b8467b82
walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents:
11277
diff
changeset
|
1137 if not revs: |
b724b8467b82
walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents:
11277
diff
changeset
|
1138 return [] |
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
8119
diff
changeset
|
1139 wanted = set() |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1140 slowpath = match.anypats() or (match.files() and opts.get('removed')) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1141 fncache = {} |
16108
f7e0d95d0a0b
log: remove caching of all visited revisions (issue3253)
Matt Mackall <mpm@selenic.com>
parents:
16070
diff
changeset
|
1142 change = repo.changectx |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20072
diff
changeset
|
1143 revs = revset.baseset(revs) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1144 |
11632
f418d2570920
log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11631
diff
changeset
|
1145 # 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
|
1146 # 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
|
1147 # 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
|
1148 # match the file filtering conditions. |
f418d2570920
log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11631
diff
changeset
|
1149 |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1150 if not slowpath and not match.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1151 # No files, no patterns. Display all revs. |
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
8119
diff
changeset
|
1152 wanted = set(revs) |
9665
1de5ebfa5585
walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents:
9664
diff
changeset
|
1153 |
16381
64c8ae09162e
log: bypass file scan part of fastpath when no files
Matt Mackall <mpm@selenic.com>
parents:
16380
diff
changeset
|
1154 if not slowpath and match.files(): |
11632
f418d2570920
log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11631
diff
changeset
|
1155 # 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
|
1156 |
19290
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1157 try: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1158 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
|
1159 except FileWalkError: |
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1160 slowpath = True |
11608
183e63112698
log: remove increasing windows usage in fastpath
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11607
diff
changeset
|
1161 |
19290
f21f4a1b6c24
log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents:
19211
diff
changeset
|
1162 # 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
|
1163 # 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
|
1164 # existed in history, otherwise simply return |
17746
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1165 for path in match.files(): |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1166 if path == '.' or path in repo.store: |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1167 break |
18340
8802277c40ee
log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents:
18267
diff
changeset
|
1168 else: |
8802277c40ee
log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents:
18267
diff
changeset
|
1169 return [] |
17746
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1170 |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1171 if slowpath: |
11632
f418d2570920
log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11631
diff
changeset
|
1172 # 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
|
1173 # changed files |
f418d2570920
log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11631
diff
changeset
|
1174 |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1175 if follow: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1176 raise util.Abort(_('can only follow copies/renames for explicit ' |
8761
0289f384e1e5
Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents:
8731
diff
changeset
|
1177 'filenames')) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1178 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1179 # 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
|
1180 # 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
|
1181 class lazywantedset(object): |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1182 def __init__(self): |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1183 self.set = set() |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1184 self.revs = set(revs) |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1185 |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1186 # 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
|
1187 # 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
|
1188 def __contains__(self, value): |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1189 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
|
1190 return True |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1191 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
|
1192 return False |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1193 else: |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1194 self.revs.discard(value) |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1195 ctx = change(value) |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1196 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
|
1197 if matches: |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1198 fncache[value] = matches |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1199 self.set.add(value) |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1200 return True |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1201 return False |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1202 |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1203 def discard(self, value): |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1204 self.revs.discard(value) |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1205 self.set.discard(value) |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1206 |
d184bae667e4
log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents:
19511
diff
changeset
|
1207 wanted = lazywantedset() |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1208 |
8778
c5f36402daad
use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8761
diff
changeset
|
1209 class followfilter(object): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1210 def __init__(self, onlyfirst=False): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1211 self.startrev = nullrev |
10024
2b630e4c8f2f
log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10012
diff
changeset
|
1212 self.roots = set() |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1213 self.onlyfirst = onlyfirst |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1214 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1215 def match(self, rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1216 def realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1217 if self.onlyfirst: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1218 return repo.changelog.parentrevs(rev)[0:1] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1219 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1220 return filter(lambda x: x != nullrev, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1221 repo.changelog.parentrevs(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1222 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1223 if self.startrev == nullrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1224 self.startrev = rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1225 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1226 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1227 if rev > self.startrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1228 # forward: all descendants |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1229 if not self.roots: |
10024
2b630e4c8f2f
log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10012
diff
changeset
|
1230 self.roots.add(self.startrev) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1231 for parent in realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1232 if parent in self.roots: |
10024
2b630e4c8f2f
log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10012
diff
changeset
|
1233 self.roots.add(rev) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1234 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1235 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1236 # backwards: all parents |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1237 if not self.roots: |
10024
2b630e4c8f2f
log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10012
diff
changeset
|
1238 self.roots.update(realparents(self.startrev)) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1239 if rev in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1240 self.roots.remove(rev) |
10024
2b630e4c8f2f
log --follow: use a set instead of a list
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10012
diff
changeset
|
1241 self.roots.update(realparents(rev)) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1242 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1243 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1244 return False |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1245 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1246 # 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
|
1247 # 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
|
1248 for rev in opts.get('prune', ()): |
16380
84ba30e8c790
cmdutil: use context instead of lookup
Matt Mackall <mpm@selenic.com>
parents:
16304
diff
changeset
|
1249 rev = repo[rev].rev() |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1250 ff = followfilter() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1251 stop = min(revs[0], revs[-1]) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1252 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
|
1253 if ff.match(x): |
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
8119
diff
changeset
|
1254 wanted.discard(x) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1255 |
18710
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1256 # Choose a small initial window if we will probably only visit a |
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1257 # few commits. |
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1258 limit = loglimit(opts) |
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1259 windowsize = 8 |
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1260 if limit: |
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1261 windowsize = min(limit, windowsize) |
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1262 |
11632
f418d2570920
log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11631
diff
changeset
|
1263 # 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
|
1264 # revision range, yielding only revisions in wanted. |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1265 def iterate(): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1266 if follow and not match.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1267 ff = followfilter(onlyfirst=opts.get('follow_first')) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1268 def want(rev): |
8119
af44d0b953c6
cmdutil: return boolean result directly in want function
Martin Geisler <mg@lazybytes.net>
parents:
8117
diff
changeset
|
1269 return ff.match(rev) and rev in wanted |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1270 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1271 def want(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1272 return rev in wanted |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1273 |
18710
49ef9d0ca815
cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents:
18688
diff
changeset
|
1274 for i, window in increasingwindows(0, len(revs), windowsize): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1275 nrevs = [rev for rev in revs[i:i + window] if want(rev)] |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8189
diff
changeset
|
1276 for rev in sorted(nrevs): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1277 fns = fncache.get(rev) |
9654
96fe91be9c1e
walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents:
9653
diff
changeset
|
1278 ctx = change(rev) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1279 if not fns: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1280 def fns_generator(): |
9654
96fe91be9c1e
walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents:
9653
diff
changeset
|
1281 for f in ctx.files(): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1282 if match(f): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1283 yield f |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1284 fns = fns_generator() |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1285 prepare(ctx, fns) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1286 for rev in nrevs: |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1287 yield change(rev) |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1288 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
|
1289 |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1290 def _makegraphfilematcher(repo, pats, followfirst): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1291 # 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
|
1292 # 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
|
1293 # --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
|
1294 # 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
|
1295 # reproducing the graph traversal already done by --follow revset |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1296 # and relating linkrevs to file names (which is not "correct" but |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1297 # good enough). |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1298 fcache = {} |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1299 fcacheready = [False] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1300 pctx = repo['.'] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1301 wctx = repo[None] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1302 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1303 def populate(): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1304 for fn in pats: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1305 for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1306 for c in i: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1307 fcache.setdefault(c.linkrev(), set()).add(c.path()) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1308 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1309 def filematcher(rev): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1310 if not fcacheready[0]: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1311 # Lazy initialization |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1312 fcacheready[0] = True |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1313 populate() |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1314 return scmutil.match(wctx, fcache.get(rev, []), default='path') |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1315 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1316 return filematcher |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1317 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1318 def _makegraphlogrevset(repo, pats, opts, revs): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1319 """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
|
1320 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
|
1321 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
|
1322 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
|
1323 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
|
1324 """ |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1325 opt2revset = { |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1326 'no_merges': ('not merge()', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1327 'only_merges': ('merge()', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1328 '_ancestors': ('ancestors(%(val)s)', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1329 '_fancestors': ('_firstancestors(%(val)s)', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1330 '_descendants': ('descendants(%(val)s)', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1331 '_fdescendants': ('_firstdescendants(%(val)s)', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1332 '_matchfiles': ('_matchfiles(%(val)s)', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1333 'date': ('date(%(val)r)', None), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1334 'branch': ('branch(%(val)r)', ' or '), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1335 '_patslog': ('filelog(%(val)r)', ' or '), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1336 '_patsfollow': ('follow(%(val)r)', ' or '), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1337 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1338 'keyword': ('keyword(%(val)r)', ' or '), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1339 '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
|
1340 'user': ('user(%(val)r)', ' or '), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1341 } |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1342 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1343 opts = dict(opts) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1344 # follow or not follow? |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1345 follow = opts.get('follow') or opts.get('follow_first') |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1346 followfirst = opts.get('follow_first') and 1 or 0 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1347 # --follow with FILE behaviour depends on revs... |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1348 startrev = revs[0] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1349 followdescendants = (len(revs) > 1 and revs[0] < revs[1]) and 1 or 0 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1350 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1351 # 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
|
1352 # the same time |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1353 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
|
1354 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
|
1355 # 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
|
1356 # _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
|
1357 # 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
|
1358 # platforms without shell expansion (windows). |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1359 pctx = repo[None] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1360 match, pats = scmutil.matchandpats(pctx, pats, opts) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1361 slowpath = match.anypats() or (match.files() and opts.get('removed')) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1362 if not slowpath: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1363 for f in match.files(): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1364 if follow and f not in pctx: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1365 raise util.Abort(_('cannot follow file not in parent ' |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1366 'revision: "%s"') % f) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1367 filelog = repo.file(f) |
19293
446ab88d3f1c
filelog: switch 'not len(filerevlog)' to 'not filerevlog'
Durham Goode <durham@fb.com>
parents:
19290
diff
changeset
|
1368 if not filelog: |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1369 # 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
|
1370 # 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
|
1371 if follow: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1372 raise util.Abort( |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1373 _('cannot follow nonexistent file: "%s"') % f) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1374 slowpath = True |
17746
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1375 |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1376 # 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
|
1377 # 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
|
1378 # 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
|
1379 # slowpath; otherwise, we can turn off the slowpath |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1380 if slowpath: |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1381 for path in match.files(): |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1382 if path == '.' or path in repo.store: |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1383 break |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1384 else: |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1385 slowpath = False |
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1386 |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1387 if slowpath: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1388 # See walkchangerevs() slow path. |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1389 # |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1390 if follow: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1391 raise util.Abort(_('can only follow copies/renames for explicit ' |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1392 'filenames')) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1393 # 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
|
1394 # 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
|
1395 # 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
|
1396 # "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
|
1397 # 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
|
1398 # directory. |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1399 matchargs = ['r:', 'd:relpath'] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1400 for p in pats: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1401 matchargs.append('p:' + p) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1402 for p in opts.get('include', []): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1403 matchargs.append('i:' + p) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1404 for p in opts.get('exclude', []): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1405 matchargs.append('x:' + p) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1406 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
|
1407 opts['_matchfiles'] = matchargs |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1408 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1409 if follow: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1410 fpats = ('_patsfollow', '_patsfollowfirst') |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1411 fnopats = (('_ancestors', '_fancestors'), |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1412 ('_descendants', '_fdescendants')) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1413 if pats: |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17391
diff
changeset
|
1414 # 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
|
1415 # 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
|
1416 opts[fpats[followfirst]] = list(match.files()) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1417 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1418 opts[fnopats[followdescendants][followfirst]] = str(startrev) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1419 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1420 opts['_patslog'] = list(pats) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1421 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1422 filematcher = None |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1423 if opts.get('patch') or opts.get('stat'): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1424 if follow: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1425 filematcher = _makegraphfilematcher(repo, pats, followfirst) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1426 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1427 filematcher = lambda rev: match |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1428 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1429 expr = [] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1430 for op, val in opts.iteritems(): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1431 if not val: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1432 continue |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1433 if op not in opt2revset: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1434 continue |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1435 revop, andor = opt2revset[op] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1436 if '%(val)' not in revop: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1437 expr.append(revop) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1438 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1439 if not isinstance(val, list): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1440 e = revop % {'val': val} |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1441 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1442 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
|
1443 expr.append(e) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1444 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1445 if expr: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1446 expr = '(' + ' and '.join(expr) + ')' |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1447 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1448 expr = None |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1449 return expr, filematcher |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1450 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1451 def getgraphlogrevs(repo, pats, opts): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1452 """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
|
1453 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
|
1454 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
|
1455 --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
|
1456 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
|
1457 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
|
1458 """ |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1459 if not len(repo): |
18171
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1460 return [], None, None |
18172
e6c5e0092469
cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents:
18171
diff
changeset
|
1461 limit = loglimit(opts) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1462 # Default --rev value depends on --follow but --follow behaviour |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1463 # depends on revisions resolved from --rev... |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1464 follow = opts.get('follow') or opts.get('follow_first') |
18169
ae663cba9a8d
cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents:
18031
diff
changeset
|
1465 possiblyunsorted = False # whether revs might need sorting |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1466 if opts.get('rev'): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1467 revs = scmutil.revrange(repo, opts['rev']) |
18169
ae663cba9a8d
cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents:
18031
diff
changeset
|
1468 # Don't sort here because _makegraphlogrevset might depend on the |
ae663cba9a8d
cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents:
18031
diff
changeset
|
1469 # order of revs |
ae663cba9a8d
cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents:
18031
diff
changeset
|
1470 possiblyunsorted = True |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1471 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1472 if follow and len(repo) > 0: |
17676
f87683a1b02a
clfilter: remove any explicit revision number from default cmdutil range
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17675
diff
changeset
|
1473 revs = repo.revs('reverse(:.)') |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1474 else: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20072
diff
changeset
|
1475 revs = revset.baseset(repo.changelog) |
17675
8575f4a2126e
clfilter: remove usage of `range` in favor of iteration over changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17475
diff
changeset
|
1476 revs.reverse() |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1477 if not revs: |
18171
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1478 return [], None, None |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20072
diff
changeset
|
1479 revs = revset.baseset(revs) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1480 expr, filematcher = _makegraphlogrevset(repo, pats, opts, revs) |
18169
ae663cba9a8d
cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents:
18031
diff
changeset
|
1481 if possiblyunsorted: |
ae663cba9a8d
cmdutil: make getgraphlogrevs return revs in descending order
Siddharth Agarwal <sid0@fb.com>
parents:
18031
diff
changeset
|
1482 revs.sort(reverse=True) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1483 if expr: |
18171
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1484 # Revset matchers often operate faster on revisions in changelog |
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1485 # order, because most filters deal with the changelog. |
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1486 revs.reverse() |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1487 matcher = revset.match(repo.ui, expr) |
18171
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1488 # Revset matches can reorder revisions. "A or B" typically returns |
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1489 # returns the revision matching A then the revision matching B. Sort |
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1490 # again to fix that. |
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1491 revs = matcher(repo, revs) |
9d350f2d9458
cmdutil: stop pretending we can calculate revs for graphlog lazily
Siddharth Agarwal <sid0@fb.com>
parents:
18170
diff
changeset
|
1492 revs.sort(reverse=True) |
18243
b3b1b8e127e5
log: use "hidden" filtering instead of manual check at display time
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18235
diff
changeset
|
1493 if limit is not None: |
18172
e6c5e0092469
cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents:
18171
diff
changeset
|
1494 revs = revs[:limit] |
e6c5e0092469
cmdutil: make getgraphlogrevs limit-aware
Siddharth Agarwal <sid0@fb.com>
parents:
18171
diff
changeset
|
1495 |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1496 return revs, expr, filematcher |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1497 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1498 def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None, |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1499 filematcher=None): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1500 seen, state = [], graphmod.asciistate() |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1501 for rev, type, ctx, parents in dag: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1502 char = 'o' |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1503 if ctx.node() in showparents: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1504 char = '@' |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1505 elif ctx.obsolete(): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1506 char = 'x' |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1507 copies = None |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1508 if getrenamed and ctx.rev(): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1509 copies = [] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1510 for fn in ctx.files(): |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1511 rename = getrenamed(fn, ctx.rev()) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1512 if rename: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1513 copies.append((fn, rename[0])) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1514 revmatchfn = None |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1515 if filematcher is not None: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1516 revmatchfn = filematcher(ctx.rev()) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1517 displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1518 lines = displayer.hunk.pop(rev).split('\n') |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1519 if not lines[-1]: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1520 del lines[-1] |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1521 displayer.flush(rev) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1522 edges = edgefn(type, char, lines, seen, rev, parents) |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1523 for type, char, lines, coldata in edges: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1524 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
|
1525 displayer.close() |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1526 |
17181
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1527 def graphlog(ui, repo, *pats, **opts): |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1528 # Parameters are identical to log command ones |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1529 revs, expr, filematcher = getgraphlogrevs(repo, pats, opts) |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1530 revdag = graphmod.dagwalker(repo, revs) |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1531 |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1532 getrenamed = None |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1533 if opts.get('copies'): |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1534 endrev = None |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1535 if opts.get('rev'): |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1536 endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1537 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1538 displayer = show_changeset(ui, repo, opts, buffered=True) |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1539 showparents = [ctx.node() for ctx in repo[None].parents()] |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1540 displaygraph(ui, revdag, displayer, showparents, |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1541 graphmod.asciiedges, getrenamed, filematcher) |
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1542 |
17182
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1543 def checkunsupportedgraphflags(pats, opts): |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1544 for op in ["newest_first"]: |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1545 if op in opts and opts[op]: |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1546 raise util.Abort(_("-G/--graph option is incompatible with --%s") |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1547 % op.replace("_", "-")) |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1548 |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1549 def graphrevs(repo, nodes, opts): |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1550 limit = loglimit(opts) |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1551 nodes.reverse() |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1552 if limit is not None: |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1553 nodes = nodes[:limit] |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1554 return graphmod.nodes(repo, nodes) |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1555 |
15911
c654eac03452
add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15907
diff
changeset
|
1556 def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly): |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
1557 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
|
1558 bad = [] |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1559 oldbad = match.bad |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1560 match.bad = lambda x, y: bad.append(x) or oldbad(x, y) |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1561 names = [] |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
1562 wctx = repo[None] |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
1563 cca = None |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
1564 abort, warn = scmutil.checkportabilityalert(ui) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
1565 if abort or warn: |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17182
diff
changeset
|
1566 cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate) |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1567 for f in repo.walk(match): |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1568 exact = match.exact(f) |
15911
c654eac03452
add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15907
diff
changeset
|
1569 if exact or not explicitonly and f not in repo.dirstate: |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
1570 if cca: |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
1571 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
|
1572 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
|
1573 if ui.verbose or not exact: |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
1574 ui.status(_('adding %s\n') % match.rel(join(f))) |
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
1575 |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
1576 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
|
1577 sub = wctx.sub(subpath) |
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
1578 try: |
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
1579 submatch = matchmod.narrowmatcher(subpath, match) |
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
1580 if listsubrepos: |
15911
c654eac03452
add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15907
diff
changeset
|
1581 bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix, |
c654eac03452
add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15907
diff
changeset
|
1582 False)) |
15410
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
1583 else: |
15911
c654eac03452
add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15907
diff
changeset
|
1584 bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix, |
c654eac03452
add: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15907
diff
changeset
|
1585 True)) |
15410
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
1586 except error.LookupError: |
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
1587 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
|
1588 % join(subpath)) |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
1589 |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1590 if not dryrun: |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
1591 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
|
1592 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
|
1593 return bad |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
1594 |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1595 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
|
1596 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
|
1597 bad = [] |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1598 oldbad = match.bad |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1599 match.bad = lambda x, y: bad.append(x) or oldbad(x, y) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1600 wctx = repo[None] |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1601 forgot = [] |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1602 s = repo.status(match=match, clean=True) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1603 forget = sorted(s[0] + s[1] + s[3] + s[6]) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1604 if explicitonly: |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1605 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
|
1606 |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
1607 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
|
1608 sub = wctx.sub(subpath) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1609 try: |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1610 submatch = matchmod.narrowmatcher(subpath, match) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1611 subbad, subforgot = sub.forget(ui, submatch, prefix) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1612 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
|
1613 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
|
1614 except error.LookupError: |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1615 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
|
1616 % join(subpath)) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1617 |
16070
f11eee00c652
forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15912
diff
changeset
|
1618 if not explicitonly: |
f11eee00c652
forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15912
diff
changeset
|
1619 for f in match.files(): |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1620 if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))): |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1621 if f not in forgot: |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1622 if os.path.exists(match.rel(join(f))): |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1623 ui.warn(_('not removing %s: ' |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1624 'file is already untracked\n') |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1625 % match.rel(join(f))) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1626 bad.append(f) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1627 |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1628 for f in forget: |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1629 if ui.verbose or not match.exact(f): |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1630 ui.status(_('removing %s\n') % match.rel(join(f))) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1631 |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1632 rejected = wctx.forget(forget, prefix) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1633 bad.extend(f for f in rejected if f in match.files()) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1634 forgot.extend(forget) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1635 return bad, forgot |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
1636 |
18852
300844cb1a56
duplicatecopies: fix arg name and docstring
Siddharth Agarwal <sid0@fb.com>
parents:
18710
diff
changeset
|
1637 def duplicatecopies(repo, rev, fromrev): |
300844cb1a56
duplicatecopies: fix arg name and docstring
Siddharth Agarwal <sid0@fb.com>
parents:
18710
diff
changeset
|
1638 '''reproduce copies from fromrev to rev in the dirstate''' |
300844cb1a56
duplicatecopies: fix arg name and docstring
Siddharth Agarwal <sid0@fb.com>
parents:
18710
diff
changeset
|
1639 for dst, src in copies.pathcopies(repo[fromrev], repo[rev]).iteritems(): |
18853
78d760aa3607
duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents:
18852
diff
changeset
|
1640 # copies.pathcopies returns backward renames, so dst might not |
78d760aa3607
duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents:
18852
diff
changeset
|
1641 # actually be in the dirstate |
78d760aa3607
duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents:
18852
diff
changeset
|
1642 if repo.dirstate[dst] in "nma": |
78d760aa3607
duplicatecopies: do not mark items not in the dirstate as copies
Siddharth Agarwal <sid0@fb.com>
parents:
18852
diff
changeset
|
1643 repo.dirstate.copy(src, dst) |
15214
231aac5280ba
rebase: move updatedirstate into cmdutil so it can be shared
Matt Mackall <mpm@selenic.com>
parents:
14986
diff
changeset
|
1644 |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1645 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
|
1646 '''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
|
1647 date = opts.get('date') |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
1648 if date: |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
1649 opts['date'] = util.parsedate(date) |
14635
217b7d83afc3
cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents:
14518
diff
changeset
|
1650 message = logmessage(ui, opts) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1651 |
5829
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1652 # 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
|
1653 # that doesn't support addremove |
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1654 if opts.get('addremove'): |
14321
003d63bb4fa5
scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14320
diff
changeset
|
1655 scmutil.addremove(repo, pats, opts) |
5829
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1656 |
14671
35c2cc322ba8
scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents:
14638
diff
changeset
|
1657 return commitfunc(ui, repo, message, |
35c2cc322ba8
scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents:
14638
diff
changeset
|
1658 scmutil.match(repo[None], pats, opts), opts) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1659 |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1660 def amend(ui, repo, commitfunc, old, extra, pats, opts): |
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1661 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
|
1662 base = old.p1() |
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1663 |
18197
153659e86a5f
amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18006
diff
changeset
|
1664 wlock = lock = newid = None |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1665 try: |
17471
ad1561723dde
amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17468
diff
changeset
|
1666 wlock = repo.wlock() |
ad1561723dde
amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17468
diff
changeset
|
1667 lock = repo.lock() |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1668 tr = repo.transaction('amend') |
17049
2440822446ce
amend: disable hooks when creating intermediate commit (issue3501)
Idan Kamara <idankk86@gmail.com>
parents:
16678
diff
changeset
|
1669 try: |
17473
9732473aa24b
amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17472
diff
changeset
|
1670 # 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
|
1671 # 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
|
1672 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
|
1673 # 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
|
1674 # 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
|
1675 # `logmessage` anyway. |
034e55bbf7c0
amend: fix incompatibity between logfile and message option (issue3675)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17812
diff
changeset
|
1676 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
|
1677 # 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
|
1678 # 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
|
1679 ui.callhooks = False |
18198
9b4adaef0db9
amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18197
diff
changeset
|
1680 currentbookmark = repo._bookmarkcurrent |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1681 try: |
18198
9b4adaef0db9
amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18197
diff
changeset
|
1682 repo._bookmarkcurrent = None |
17473
9732473aa24b
amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17472
diff
changeset
|
1683 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
|
1684 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
|
1685 finally: |
18198
9b4adaef0db9
amend: prevent loss of bookmark on failed amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18197
diff
changeset
|
1686 repo._bookmarkcurrent = currentbookmark |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1687 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
|
1688 ctx = repo[node] |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1689 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1690 # 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
|
1691 # |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1692 # 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
|
1693 # | 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
|
1694 # | (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
|
1695 # | |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1696 # 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
|
1697 # | |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1698 # 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
|
1699 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1700 # 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
|
1701 # source) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1702 extra.update(old.extra()) |
16630
f30226b1a46a
amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents:
16553
diff
changeset
|
1703 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1704 # 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
|
1705 extra.update(ctx.extra()) |
16630
f30226b1a46a
amend: preserve extra dict (issue3430)
Idan Kamara <idankk86@gmail.com>
parents:
16553
diff
changeset
|
1706 |
18909
3a72c89a83ec
amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents:
18853
diff
changeset
|
1707 if len(old.parents()) > 1: |
3a72c89a83ec
amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents:
18853
diff
changeset
|
1708 # 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
|
1709 # slower repo.status() method |
3a72c89a83ec
amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents:
18853
diff
changeset
|
1710 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
|
1711 for fn in st]) |
3a72c89a83ec
amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents:
18853
diff
changeset
|
1712 else: |
3a72c89a83ec
amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents:
18853
diff
changeset
|
1713 files = set(old.files()) |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1714 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1715 # 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
|
1716 # 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
|
1717 # 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
|
1718 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
|
1719 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
|
1720 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1721 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
|
1722 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
|
1723 # 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
|
1724 copied = copies.pathcopies(base, ctx) |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1725 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1726 # 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
|
1727 # 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
|
1728 # 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
|
1729 # 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
|
1730 # 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
|
1731 files.update(ctx.files()) |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1732 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1733 def samefile(f): |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1734 if f in ctx.manifest(): |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1735 a = ctx.filectx(f) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1736 if f in base.manifest(): |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1737 b = base.filectx(f) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1738 return (not a.cmp(b) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1739 and a.flags() == b.flags()) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1740 else: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1741 return False |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1742 else: |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1743 return f not in base.manifest() |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1744 files = [f for f in files if not samefile(f)] |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1745 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1746 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
|
1747 try: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1748 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
|
1749 flags = fctx.flags() |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1750 mctx = context.memfilectx(fctx.path(), fctx.data(), |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1751 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
|
1752 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
|
1753 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
|
1754 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
|
1755 except KeyError: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1756 raise IOError |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1757 else: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1758 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
|
1759 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1760 # 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
|
1761 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
|
1762 try: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1763 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
|
1764 except KeyError: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1765 raise IOError |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1766 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1767 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
|
1768 date = opts.get('date') or old.date() |
17924
45bd0cd7ca04
amend: force editor only if old message is reused (issue3698)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17891
diff
changeset
|
1769 editmsg = False |
17473
9732473aa24b
amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17472
diff
changeset
|
1770 if not message: |
17924
45bd0cd7ca04
amend: force editor only if old message is reused (issue3698)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17891
diff
changeset
|
1771 editmsg = True |
17473
9732473aa24b
amend: use an explicit commit message for temporary amending commit
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17472
diff
changeset
|
1772 message = old.description() |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1773 |
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
|
1774 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
|
1775 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
|
1776 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1777 new = context.memctx(repo, |
18909
3a72c89a83ec
amend: support amending merge changesets (issue3778)
Brodie Rao <brodie@sf.io>
parents:
18853
diff
changeset
|
1778 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
|
1779 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
|
1780 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
|
1781 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
|
1782 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
|
1783 date=date, |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1784 extra=extra) |
17924
45bd0cd7ca04
amend: force editor only if old message is reused (issue3698)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17891
diff
changeset
|
1785 if editmsg: |
45bd0cd7ca04
amend: force editor only if old message is reused (issue3698)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17891
diff
changeset
|
1786 new._text = commitforceeditor(repo, new, []) |
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
|
1787 |
a8aba2921456
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17788
diff
changeset
|
1788 newdesc = changelog.stripdesc(new.description()) |
a8aba2921456
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17788
diff
changeset
|
1789 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
|
1790 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
|
1791 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
|
1792 and date == old.date() |
a8aba2921456
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17788
diff
changeset
|
1793 and pureextra == old.extra()): |
a8aba2921456
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17788
diff
changeset
|
1794 # 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
|
1795 # 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
|
1796 # |
a8aba2921456
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17788
diff
changeset
|
1797 # 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
|
1798 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
|
1799 |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1800 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
|
1801 try: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1802 repo.ui.setconfig('phases', 'new-commit', old.phase()) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1803 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
|
1804 finally: |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1805 repo.ui.setconfig('phases', 'new-commit', ph) |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1806 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
|
1807 # 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
|
1808 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
|
1809 |
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1810 # 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
|
1811 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
|
1812 if bms: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17891
diff
changeset
|
1813 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
|
1814 for bm in bms: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17891
diff
changeset
|
1815 marks[bm] = newid |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17891
diff
changeset
|
1816 marks.write() |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1817 #commit the whole amend process |
17475
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1818 if obsolete._enabled and newid != old.node(): |
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1819 # mark the new changeset as successor of the rewritten one |
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1820 new = repo[newid] |
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1821 obs = [(old, (new,))] |
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1822 if node: |
17812
578fcc22b469
amend: do a bare kill of temporary changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17811
diff
changeset
|
1823 obs.append((ctx, ())) |
17475
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1824 |
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1825 obsolete.createmarkers(repo, obs) |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1826 tr.close() |
17461
bacde764fba0
amend: preserve phase of amended revision (issue3602)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17391
diff
changeset
|
1827 finally: |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
1828 tr.release() |
17475
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1829 if (not obsolete._enabled) and newid != old.node(): |
63e45aee46d4
amend: add obsolete support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17473
diff
changeset
|
1830 # 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
|
1831 # commit |
17471
ad1561723dde
amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17468
diff
changeset
|
1832 if node: |
ad1561723dde
amend: lock the repository during the whole process
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17468
diff
changeset
|
1833 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
|
1834 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
|
1835 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
|
1836 finally: |
18197
153659e86a5f
amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18006
diff
changeset
|
1837 if newid is None: |
153659e86a5f
amend: invalidate dirstate in case of failure (issue3670)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18006
diff
changeset
|
1838 repo.dirstate.invalidate() |
19024
ab04e87a5f3b
amend: fix unlocking order - first lock then wlock
Mads Kiilerich <madski@unity3d.com>
parents:
18991
diff
changeset
|
1839 lockmod.release(lock, wlock) |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1840 return newid |
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
1841 |
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1842 def commiteditor(repo, ctx, subs): |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1843 if ctx.description(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1844 return ctx.description() |
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1845 return commitforceeditor(repo, ctx, subs) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1846 |
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1847 def commitforceeditor(repo, ctx, subs): |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1848 edittext = [] |
8707
0550dfe4fca1
commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents:
8680
diff
changeset
|
1849 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
|
1850 if ctx.description(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1851 edittext.append(ctx.description()) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1852 edittext.append("") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1853 edittext.append("") # Empty line between message and comments. |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1854 edittext.append(_("HG: Enter commit message." |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1855 " Lines beginning with 'HG:' are removed.")) |
8535
5b6a6ed4f185
cmdutil: mark string for translation
Martin Geisler <mg@lazybytes.net>
parents:
8497
diff
changeset
|
1856 edittext.append(_("HG: Leave message empty to abort commit.")) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1857 edittext.append("HG: --") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1858 edittext.append(_("HG: user: %s") % ctx.user()) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1859 if ctx.p2(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1860 edittext.append(_("HG: branch merge")) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1861 if ctx.branch(): |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12973
diff
changeset
|
1862 edittext.append(_("HG: branch '%s'") % ctx.branch()) |
18538
94317c2d53b8
commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents:
18364
diff
changeset
|
1863 if bookmarks.iscurrent(repo): |
94317c2d53b8
commit: show active bookmark in commit editor helper text
Antonio Zanardo <zanardo@gmail.com>
parents:
18364
diff
changeset
|
1864 edittext.append(_("HG: bookmark '%s'") % repo._bookmarkcurrent) |
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1865 edittext.extend([_("HG: subrepo %s") % s for s in subs]) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1866 edittext.extend([_("HG: added %s") % f for f in added]) |
8707
0550dfe4fca1
commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents:
8680
diff
changeset
|
1867 edittext.extend([_("HG: changed %s") % f for f in modified]) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1868 edittext.extend([_("HG: removed %s") % f for f in removed]) |
8707
0550dfe4fca1
commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents:
8680
diff
changeset
|
1869 if not added and not modified and not removed: |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1870 edittext.append(_("HG: no files changed")) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1871 edittext.append("") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1872 # run editor in the repository root |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1873 olddir = os.getcwd() |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1874 os.chdir(repo.root) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1875 text = repo.ui.edit("\n".join(edittext), ctx.user()) |
12900
4ff61287bde2
commit: handle missing newline on last commit comment
Matt Mackall <mpm@selenic.com>
parents:
12874
diff
changeset
|
1876 text = re.sub("(?m)^HG:.*(\n|$)", "", text) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1877 os.chdir(olddir) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1878 |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1879 if not text.strip(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1880 raise util.Abort(_("empty commit message")) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1881 |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1882 return text |
14297
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
1883 |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1884 def commitstatus(repo, node, branch, bheads=None, opts={}): |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1885 ctx = repo[node] |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1886 parents = ctx.parents() |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1887 |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1888 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
|
1889 [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
|
1890 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
|
1891 # 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
|
1892 # 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
|
1893 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1894 # 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
|
1895 # N: null or no parent |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1896 # 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
|
1897 # 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
|
1898 # 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
|
1899 # 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
|
1900 # 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
|
1901 # 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
|
1902 # printed anyway. |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1903 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1904 # Par Msg Comment |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1905 # 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
|
1906 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1907 # 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
|
1908 # 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
|
1909 # H N n usual case |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1910 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1911 # 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
|
1912 # C B y branch merge |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1913 # 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
|
1914 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1915 # 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
|
1916 # 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
|
1917 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1918 # 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
|
1919 |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1920 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
|
1921 for r in parents: |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1922 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
|
1923 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
|
1924 |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1925 if repo.ui.debugflag: |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1926 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
|
1927 elif repo.ui.verbose: |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
1928 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
|
1929 |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1930 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
|
1931 parent, p2 = parents |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1932 node = ctx.node() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1933 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1934 mf = ctx.manifest() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1935 if node == parent: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1936 pmf = mf |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1937 else: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1938 pmf = None |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1939 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1940 # 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
|
1941 # so have to walk both. do not print errors if files exist in one |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1942 # but not other. |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1943 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1944 names = {} |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1945 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1946 wlock = repo.wlock() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1947 try: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1948 # walk dirstate. |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1949 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1950 m = scmutil.match(repo[None], pats, opts) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1951 m.bad = lambda x, y: False |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1952 for abs in repo.walk(m): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1953 names[abs] = m.rel(abs), m.exact(abs) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1954 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1955 # walk target manifest. |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1956 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1957 def badfn(path, msg): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1958 if path in names: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1959 return |
16583
146a00c162a0
revert: don't re-create changeset context
Kevin Bullock <kbullock@ringworld.org>
parents:
16553
diff
changeset
|
1960 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
|
1961 return |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1962 path_ = path + '/' |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1963 for f in names: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1964 if f.startswith(path_): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1965 return |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1966 ui.warn("%s: %s\n" % (m.rel(path), msg)) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1967 |
16583
146a00c162a0
revert: don't re-create changeset context
Kevin Bullock <kbullock@ringworld.org>
parents:
16553
diff
changeset
|
1968 m = scmutil.match(ctx, pats, opts) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1969 m.bad = badfn |
16583
146a00c162a0
revert: don't re-create changeset context
Kevin Bullock <kbullock@ringworld.org>
parents:
16553
diff
changeset
|
1970 for abs in ctx.walk(m): |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1971 if abs not in names: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1972 names[abs] = m.rel(abs), m.exact(abs) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1973 |
16430
6883c2363f44
revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16429
diff
changeset
|
1974 # get the list of subrepos that must be reverted |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
1975 targetsubs = sorted(s for s in ctx.substate if m(s)) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1976 m = scmutil.matchfiles(repo, names) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1977 changes = repo.status(match=m)[:4] |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1978 modified, added, removed, deleted = map(set, changes) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1979 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1980 # if f is a rename, also revert the source |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1981 cwd = repo.getcwd() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1982 for f in added: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1983 src = repo.dirstate.copied(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1984 if src and src not in names and repo.dirstate[src] == 'r': |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1985 removed.add(src) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1986 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
|
1987 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1988 def removeforget(abs): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1989 if repo.dirstate[abs] == 'a': |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1990 return _('forgetting %s\n') |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1991 return _('removing %s\n') |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1992 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1993 revert = ([], _('reverting %s\n')) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1994 add = ([], _('adding %s\n')) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1995 remove = ([], removeforget) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1996 undelete = ([], _('undeleting %s\n')) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1997 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1998 disptable = ( |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
1999 # dispatch table: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2000 # file state |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2001 # action if in target manifest |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2002 # action if not in target manifest |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2003 # make backup if in target manifest |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2004 # make backup if not in target manifest |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2005 (modified, revert, remove, True, True), |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2006 (added, revert, remove, True, False), |
19510
8b190adb7ee3
revert: make backup when unforgetting a file (issue3423)
Matt Mackall <mpm@selenic.com>
parents:
19496
diff
changeset
|
2007 (removed, undelete, None, True, False), |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2008 (deleted, revert, remove, False, False), |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2009 ) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2010 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2011 for abs, (rel, exact) in sorted(names.items()): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2012 mfentry = mf.get(abs) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2013 target = repo.wjoin(abs) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2014 def handle(xlist, dobackup): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2015 xlist[0].append(abs) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2016 if (dobackup and not opts.get('no_backup') and |
19510
8b190adb7ee3
revert: make backup when unforgetting a file (issue3423)
Matt Mackall <mpm@selenic.com>
parents:
19496
diff
changeset
|
2017 os.path.lexists(target) and |
19511
ca2dfc2f63eb
revert: fix largefiles breakage
Matt Mackall <mpm@selenic.com>
parents:
19510
diff
changeset
|
2018 abs in ctx and repo[None][abs].cmp(ctx[abs])): |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2019 bakname = "%s.orig" % rel |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2020 ui.note(_('saving current version of %s as %s\n') % |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2021 (rel, bakname)) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2022 if not opts.get('dry_run'): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2023 util.rename(target, bakname) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2024 if ui.verbose or not exact: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2025 msg = xlist[1] |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2026 if not isinstance(msg, basestring): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2027 msg = msg(abs) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2028 ui.status(msg % rel) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2029 for table, hitlist, misslist, backuphit, backupmiss in disptable: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2030 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
|
2031 continue |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2032 # file has changed in dirstate |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2033 if mfentry: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2034 handle(hitlist, backuphit) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2035 elif misslist is not None: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2036 handle(misslist, backupmiss) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2037 break |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2038 else: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2039 if abs not in repo.dirstate: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2040 if mfentry: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2041 handle(add, True) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2042 elif exact: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2043 ui.warn(_('file not managed: %s\n') % rel) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2044 continue |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2045 # file has not changed in dirstate |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2046 if node == parent: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2047 if exact: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2048 ui.warn(_('no changes needed to %s\n') % rel) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2049 continue |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2050 if pmf is None: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2051 # only need parent manifest in this unlikely case, |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2052 # so do not read by default |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2053 pmf = repo[parent].manifest() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2054 if abs in pmf and mfentry: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2055 # if version of file is same in parent and target |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2056 # manifests, do nothing |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2057 if (pmf[abs] != mfentry or |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2058 pmf.flags(abs) != mf.flags(abs)): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2059 handle(revert, False) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2060 else: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2061 handle(remove, False) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2062 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2063 if not opts.get('dry_run'): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2064 def checkout(f): |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2065 fc = ctx[f] |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2066 repo.wwrite(f, fc.data(), fc.flags()) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2067 |
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
|
2068 audit_path = pathutil.pathauditor(repo.root) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2069 for f in remove[0]: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2070 if repo.dirstate[f] == 'a': |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2071 repo.dirstate.drop(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2072 continue |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2073 audit_path(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2074 try: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2075 util.unlinkpath(repo.wjoin(f)) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2076 except OSError: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2077 pass |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2078 repo.dirstate.remove(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2079 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2080 normal = None |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2081 if node == parent: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2082 # We're reverting to our parent. If possible, we'd like status |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2083 # to report the file as clean. We have to use normallookup for |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2084 # merges to avoid losing information about merged/dirty files. |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2085 if p2 != nullid: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2086 normal = repo.dirstate.normallookup |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2087 else: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2088 normal = repo.dirstate.normal |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2089 for f in revert[0]: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2090 checkout(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2091 if normal: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2092 normal(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2093 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2094 for f in add[0]: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2095 checkout(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2096 repo.dirstate.add(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2097 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2098 normal = repo.dirstate.normallookup |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2099 if node == parent and p2 == nullid: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2100 normal = repo.dirstate.normal |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2101 for f in undelete[0]: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2102 checkout(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2103 normal(f) |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2104 |
19129
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
2105 copied = copies.pathcopies(repo[parent], ctx) |
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
2106 |
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
2107 for f in add[0] + undelete[0] + revert[0]: |
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
2108 if f in copied: |
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
2109 repo.dirstate.copy(copied[f], f) |
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
2110 |
16429
71dcce391a44
revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16381
diff
changeset
|
2111 if targetsubs: |
71dcce391a44
revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16381
diff
changeset
|
2112 # Revert the subrepos on the revert list |
71dcce391a44
revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16381
diff
changeset
|
2113 for sub in targetsubs: |
71dcce391a44
revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16381
diff
changeset
|
2114 ctx.sub(sub).revert(ui, ctx.substate[sub], *pats, **opts) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2115 finally: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2116 wlock.release() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
2117 |
14297
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2118 def command(table): |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2119 '''returns a function object bound to table which can be used as |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2120 a decorator for populating table as a command table''' |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2121 |
18235
9807e7d596c3
cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18206
diff
changeset
|
2122 def cmd(name, options=(), synopsis=None): |
14297
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2123 def decorator(func): |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2124 if synopsis: |
18235
9807e7d596c3
cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18206
diff
changeset
|
2125 table[name] = func, list(options), synopsis |
14297
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2126 else: |
18235
9807e7d596c3
cmdutil: make options argument optional
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18206
diff
changeset
|
2127 table[name] = func, list(options) |
14297
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2128 return func |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2129 return decorator |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2130 |
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
2131 return cmd |
19211
3bfd7f1e7485
summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents:
19129
diff
changeset
|
2132 |
3bfd7f1e7485
summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents:
19129
diff
changeset
|
2133 # 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
|
2134 summaryhooks = util.hooks() |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2135 |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2136 # 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
|
2137 # 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
|
2138 # note: bisect is intentionally excluded |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2139 # (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
|
2140 unfinishedstates = [ |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2141 ('graftstate', True, False, _('graft in progress'), |
19482
499fc471296b
update: add tracking of interrupted updates (issue3113)
Matt Mackall <mpm@selenic.com>
parents:
19474
diff
changeset
|
2142 _("use 'hg graft --continue' or 'hg update' to abort")), |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2143 ('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
|
2144 _("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
|
2145 ] |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2146 |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2147 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
|
2148 '''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
|
2149 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
|
2150 bailifchanged(). |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2151 ''' |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2152 for f, clearable, allowcommit, msg, hint in unfinishedstates: |
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2153 if commit and allowcommit: |
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2154 continue |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2155 if repo.vfs.exists(f): |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2156 raise util.Abort(msg, hint=hint) |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2157 |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2158 def clearunfinished(repo): |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2159 '''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
|
2160 that are clearable. |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2161 ''' |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2162 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
|
2163 if not clearable and repo.vfs.exists(f): |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2164 raise util.Abort(msg, hint=hint) |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
2165 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
|
2166 if clearable and repo.vfs.exists(f): |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
2167 util.unlink(repo.join(f)) |