author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
Sat, 28 Nov 2009 10:25:09 +0900 | |
changeset 9959 | b37b060d84c7 |
parent 9958 | 777c1df76ef4 |
child 9963 | a68fb6f4ae4b |
permissions | -rw-r--r-- |
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 |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
6 |
# GNU General Public License version 2, incorporated herein by reference. |
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 _ |
8731
f037187a6f68
cleanup: removed unused imports
Henri Wiechers <hwiechers@gmail.com>
parents:
8709
diff
changeset
|
10 |
import os, sys, errno, re, glob |
8390
beae42f3d93b
drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8368
diff
changeset
|
11 |
import mdiff, bdiff, util, templater, patch, error, encoding |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
12 |
import match as _match |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
13 |
|
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
14 |
revrangesep = ':' |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
15 |
|
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
16 |
def findpossible(cmd, table, strict=False): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
17 |
""" |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
18 |
Return cmd -> (aliases, command table entry) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
19 |
for each matching command. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
20 |
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
|
21 |
""" |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
22 |
choice = {} |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
23 |
debugchoice = {} |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
24 |
for e in table.keys(): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
25 |
aliases = e.lstrip("^").split("|") |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
26 |
found = None |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
27 |
if cmd in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
28 |
found = cmd |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
29 |
elif not strict: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
30 |
for a in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
31 |
if a.startswith(cmd): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
32 |
found = a |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
33 |
break |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
34 |
if found is not None: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
35 |
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
|
36 |
debugchoice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
37 |
else: |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
38 |
choice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
39 |
|
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
40 |
if not choice and debugchoice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
41 |
choice = debugchoice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
42 |
|
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
43 |
return choice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
44 |
|
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
45 |
def findcmd(cmd, table, strict=True): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
46 |
"""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
|
47 |
choice = findpossible(cmd, table, strict) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
48 |
|
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5843
diff
changeset
|
49 |
if cmd in choice: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
50 |
return choice[cmd] |
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 len(choice) > 1: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
53 |
clist = choice.keys() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
54 |
clist.sort() |
7643
9a1ea6587557
error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents:
7404
diff
changeset
|
55 |
raise error.AmbiguousCommand(cmd, clist) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
56 |
|
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
57 |
if choice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
58 |
return choice.values()[0] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
59 |
|
7643
9a1ea6587557
error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents:
7404
diff
changeset
|
60 |
raise error.UnknownCommand(cmd) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
61 |
|
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
62 |
def bail_if_changed(repo): |
5716
be367cbafe70
cmdutil: make bail_if_changed bail on uncommitted merge
Matt Mackall <mpm@selenic.com>
parents:
5610
diff
changeset
|
63 |
if repo.dirstate.parents()[1] != nullid: |
be367cbafe70
cmdutil: make bail_if_changed bail on uncommitted merge
Matt Mackall <mpm@selenic.com>
parents:
5610
diff
changeset
|
64 |
raise util.Abort(_('outstanding uncommitted merge')) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
65 |
modified, added, removed, deleted = repo.status()[:4] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
66 |
if modified or added or removed or deleted: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
67 |
raise util.Abort(_("outstanding uncommitted changes")) |
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 |
def logmessage(opts): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
70 |
""" 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
|
71 |
message = opts.get('message') |
bd5c37d792e6
cmdutil.logmessage: options should be optional
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7643
diff
changeset
|
72 |
logfile = opts.get('logfile') |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
73 |
|
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
74 |
if message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
75 |
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
|
76 |
'exclusive')) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
77 |
if not message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
78 |
try: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
79 |
if logfile == '-': |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
80 |
message = sys.stdin.read() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
81 |
else: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
82 |
message = open(logfile).read() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
83 |
except IOError, inst: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
84 |
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
|
85 |
(logfile, inst.strerror)) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
86 |
return message |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
87 |
|
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
88 |
def loglimit(opts): |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
89 |
"""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
|
90 |
limit = opts.get('limit') |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
91 |
if limit: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
92 |
try: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
93 |
limit = int(limit) |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
94 |
except ValueError: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
95 |
raise util.Abort(_('limit must be a positive integer')) |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
96 |
if limit <= 0: raise util.Abort(_('limit must be positive')) |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
97 |
else: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
98 |
limit = sys.maxint |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
99 |
return limit |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
100 |
|
8188 | 101 |
def remoteui(src, opts): |
102 |
'build a remote ui from ui or repo and opts' |
|
8189
d2899a856f9f
ui: replace parentui mechanism with repo.baseui
Matt Mackall <mpm@selenic.com>
parents:
8188
diff
changeset
|
103 |
if hasattr(src, 'baseui'): # looks like a repository |
8798
92fc57c9f9d1
remoteui: properly create dst with copy()
Matt Mackall <mpm@selenic.com>
parents:
8789
diff
changeset
|
104 |
dst = src.baseui.copy() # drop repo-specific config |
8188 | 105 |
src = src.ui # copy target options from repo |
8189
d2899a856f9f
ui: replace parentui mechanism with repo.baseui
Matt Mackall <mpm@selenic.com>
parents:
8188
diff
changeset
|
106 |
else: # assume it's a global ui object |
8798
92fc57c9f9d1
remoteui: properly create dst with copy()
Matt Mackall <mpm@selenic.com>
parents:
8789
diff
changeset
|
107 |
dst = src.copy() # keep all global options |
8188 | 108 |
|
109 |
# copy ssh-specific options |
|
110 |
for o in 'ssh', 'remotecmd': |
|
111 |
v = opts.get(o) or src.config('ui', o) |
|
112 |
if v: |
|
113 |
dst.setconfig("ui", o, v) |
|
114 |
# copy bundle-specific options |
|
115 |
r = src.config('bundle', 'mainreporoot') |
|
116 |
if r: |
|
117 |
dst.setconfig('bundle', 'mainreporoot', r) |
|
118 |
||
119 |
return dst |
|
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
120 |
|
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
121 |
def revpair(repo, revs): |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
122 |
'''return pair of nodes, given list of revisions. second item can |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
123 |
be None, meaning use working dir.''' |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
124 |
|
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
125 |
def revfix(repo, val, defval): |
3825
000d122071b5
fix hg diff -r ''
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3814
diff
changeset
|
126 |
if not val and val != 0 and defval is not None: |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
127 |
val = defval |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
128 |
return repo.lookup(val) |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
129 |
|
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
130 |
if not revs: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
131 |
return repo.dirstate.parents()[0], None |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
132 |
end = None |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
133 |
if len(revs) == 1: |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
134 |
if revrangesep in revs[0]: |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
135 |
start, end = revs[0].split(revrangesep, 1) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
136 |
start = revfix(repo, start, 0) |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
137 |
end = revfix(repo, end, len(repo) - 1) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
138 |
else: |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
139 |
start = revfix(repo, revs[0], None) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
140 |
elif len(revs) == 2: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
141 |
if revrangesep in revs[0] or revrangesep in revs[1]: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
142 |
raise util.Abort(_('too many revisions specified')) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
143 |
start = revfix(repo, revs[0], None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
144 |
end = revfix(repo, revs[1], None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
145 |
else: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
146 |
raise util.Abort(_('too many revisions specified')) |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
147 |
return start, end |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
148 |
|
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
149 |
def revrange(repo, revs): |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
150 |
"""Yield revision as strings from a list of revision specifications.""" |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
151 |
|
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
152 |
def revfix(repo, val, defval): |
3718
7db88b094b14
fix hg log -r ''
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3707
diff
changeset
|
153 |
if not val and val != 0 and defval is not None: |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
154 |
return defval |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
155 |
return repo.changelog.rev(repo.lookup(val)) |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
156 |
|
8368
52e6117a9940
cmdutil: replace pseudo-set by real set
Martin Geisler <mg@lazybytes.net>
parents:
8360
diff
changeset
|
157 |
seen, l = set(), [] |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
158 |
for spec in revs: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
159 |
if revrangesep in spec: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
160 |
start, end = spec.split(revrangesep, 1) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
161 |
start = revfix(repo, start, 0) |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
162 |
end = revfix(repo, end, len(repo) - 1) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
163 |
step = start > end and -1 or 1 |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
164 |
for rev in xrange(start, end+step, step): |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
165 |
if rev in seen: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
166 |
continue |
8368
52e6117a9940
cmdutil: replace pseudo-set by real set
Martin Geisler <mg@lazybytes.net>
parents:
8360
diff
changeset
|
167 |
seen.add(rev) |
3526
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3525
diff
changeset
|
168 |
l.append(rev) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
169 |
else: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
170 |
rev = revfix(repo, spec, None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
171 |
if rev in seen: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
172 |
continue |
8368
52e6117a9940
cmdutil: replace pseudo-set by real set
Martin Geisler <mg@lazybytes.net>
parents:
8360
diff
changeset
|
173 |
seen.add(rev) |
3526
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3525
diff
changeset
|
174 |
l.append(rev) |
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3525
diff
changeset
|
175 |
|
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3525
diff
changeset
|
176 |
return l |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
177 |
|
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
178 |
def make_filename(repo, pat, node, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
179 |
total=None, seqno=None, revwidth=None, pathname=None): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
180 |
node_expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
181 |
'H': lambda: hex(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
182 |
'R': lambda: str(repo.changelog.rev(node)), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
183 |
'h': lambda: short(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
184 |
} |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
185 |
expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
186 |
'%': lambda: '%', |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
187 |
'b': lambda: os.path.basename(repo.root), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
188 |
} |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
189 |
|
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
190 |
try: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
191 |
if node: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
192 |
expander.update(node_expander) |
4836
0e2d0a78f81a
archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4825
diff
changeset
|
193 |
if node: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
194 |
expander['r'] = (lambda: |
4836
0e2d0a78f81a
archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4825
diff
changeset
|
195 |
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
|
196 |
if total is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
197 |
expander['N'] = lambda: str(total) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
198 |
if seqno is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
199 |
expander['n'] = lambda: str(seqno) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
if pathname is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
203 |
expander['s'] = lambda: os.path.basename(pathname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
204 |
expander['d'] = lambda: os.path.dirname(pathname) or '.' |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
205 |
expander['p'] = lambda: pathname |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
206 |
|
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
207 |
newname = [] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
208 |
patlen = len(pat) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
209 |
i = 0 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
210 |
while i < patlen: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
211 |
c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
212 |
if c == '%': |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
213 |
i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
214 |
c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
215 |
c = expander[c]() |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
216 |
newname.append(c) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
217 |
i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
218 |
return ''.join(newname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
219 |
except KeyError, inst: |
8761
0289f384e1e5
Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents:
8731
diff
changeset
|
220 |
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
|
221 |
inst.args[0]) |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
222 |
|
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
223 |
def make_file(repo, pat, node=None, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
224 |
total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
7319
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
225 |
|
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
226 |
writable = 'w' in mode or 'a' in mode |
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
227 |
|
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
228 |
if not pat or pat == '-': |
7319
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
229 |
return writable and sys.stdout or sys.stdin |
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
230 |
if hasattr(pat, 'write') and writable: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
231 |
return pat |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
232 |
if hasattr(pat, 'read') and 'r' in mode: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
233 |
return pat |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
234 |
return open(make_filename(repo, pat, node, total, seqno, revwidth, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
235 |
pathname), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
236 |
mode) |
2882
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2874
diff
changeset
|
237 |
|
8614
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
238 |
def expandpats(pats): |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
239 |
if not util.expandglobs: |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
240 |
return list(pats) |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
241 |
ret = [] |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
242 |
for p in pats: |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
243 |
kind, name = _match._patsplit(p, None) |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
244 |
if kind is None: |
9118
78e54b9f3a62
cmdutil: fall back to filename if glob expand has errors
Steve Borho <steve@borho.org>
parents:
8994
diff
changeset
|
245 |
try: |
78e54b9f3a62
cmdutil: fall back to filename if glob expand has errors
Steve Borho <steve@borho.org>
parents:
8994
diff
changeset
|
246 |
globbed = glob.glob(name) |
78e54b9f3a62
cmdutil: fall back to filename if glob expand has errors
Steve Borho <steve@borho.org>
parents:
8994
diff
changeset
|
247 |
except re.error: |
78e54b9f3a62
cmdutil: fall back to filename if glob expand has errors
Steve Borho <steve@borho.org>
parents:
8994
diff
changeset
|
248 |
globbed = [name] |
8614
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
249 |
if globbed: |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
250 |
ret.extend(globbed) |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
251 |
continue |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
252 |
ret.append(p) |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
253 |
return ret |
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
254 |
|
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
255 |
def match(repo, pats=[], opts={}, globbed=False, default='relpath'): |
6575
e08e0367ba15
walk: kill util.cmdmatcher and _matcher
Matt Mackall <mpm@selenic.com>
parents:
6566
diff
changeset
|
256 |
if not globbed and default == 'relpath': |
8614
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
257 |
pats = expandpats(pats or []) |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
258 |
m = _match.match(repo.root, repo.getcwd(), pats, |
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
259 |
opts.get('include'), opts.get('exclude'), default) |
6578
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6577
diff
changeset
|
260 |
def badfn(f, msg): |
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6577
diff
changeset
|
261 |
repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) |
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6577
diff
changeset
|
262 |
m.bad = badfn |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
263 |
return m |
2882
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2874
diff
changeset
|
264 |
|
6597
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
265 |
def matchall(repo): |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
266 |
return _match.always(repo.root, repo.getcwd()) |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
267 |
|
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
268 |
def matchfiles(repo, files): |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
269 |
return _match.exact(repo.root, repo.getcwd(), files) |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
270 |
|
8989
85b81cac9613
addremove: pass unknown and deleted to findrenames directly again
Matt Mackall <mpm@selenic.com>
parents:
8988
diff
changeset
|
271 |
def findrenames(repo, added, removed, threshold): |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
272 |
'''find renamed files -- yields (before, after, score) tuples''' |
9925
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
273 |
copies = {} |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6739
diff
changeset
|
274 |
ctx = repo['.'] |
9925
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
275 |
for r in removed: |
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
276 |
if r not in ctx: |
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
277 |
continue |
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
278 |
fctx = ctx.filectx(r) |
9926
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
279 |
|
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
280 |
def score(text): |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
281 |
if not len(text): |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
282 |
return 0.0 |
9927
2ae4d0865629
findrenames: speedup exact match
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9926
diff
changeset
|
283 |
if not fctx.cmp(text): |
2ae4d0865629
findrenames: speedup exact match
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9926
diff
changeset
|
284 |
return 1.0 |
2ae4d0865629
findrenames: speedup exact match
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9926
diff
changeset
|
285 |
if threshold == 1.0: |
2ae4d0865629
findrenames: speedup exact match
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9926
diff
changeset
|
286 |
return 0.0 |
2ae4d0865629
findrenames: speedup exact match
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9926
diff
changeset
|
287 |
orig = fctx.data() |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
288 |
# bdiff.blocks() returns blocks of matching lines |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
289 |
# count the number of bytes in each |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
290 |
equal = 0 |
9926
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
291 |
alines = mdiff.splitnewlines(text) |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
292 |
matches = bdiff.blocks(text, orig) |
9928
a92539567ef3
findrenames: improve coding-style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9927
diff
changeset
|
293 |
for x1, x2, y1, y2 in matches: |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
294 |
for line in alines[x1:x2]: |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
295 |
equal += len(line) |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
296 |
|
9926
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
297 |
lengths = len(text) + len(orig) |
9928
a92539567ef3
findrenames: improve coding-style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9927
diff
changeset
|
298 |
return equal * 2.0 / lengths |
9926
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
299 |
|
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
300 |
for a in added: |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
301 |
bestscore = copies.get(a, (None, threshold))[1] |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
302 |
myscore = score(repo.wread(a)) |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
303 |
if myscore >= bestscore: |
4b044b81cb54
findrenames: refactor the score computation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9925
diff
changeset
|
304 |
copies[a] = (r, myscore) |
9928
a92539567ef3
findrenames: improve coding-style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9927
diff
changeset
|
305 |
|
9925
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
306 |
for dest, v in copies.iteritems(): |
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
307 |
source, score = v |
9dfe34bf42c7
findrenames: first loop over the removed files, it's faster
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9896
diff
changeset
|
308 |
yield source, dest, score |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
309 |
|
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4906
diff
changeset
|
310 |
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
311 |
if dry_run is None: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
312 |
dry_run = opts.get('dry_run') |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
313 |
if similarity is None: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
314 |
similarity = float(opts.get('similarity') or 0) |
8990
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
315 |
# we'd use status here, except handling of symlinks and ignore is tricky |
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
316 |
added, unknown, deleted, removed = [], [], [], [] |
6651
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
317 |
audit_path = util.path_auditor(repo.root) |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
318 |
m = match(repo, pats, opts) |
6586
d3463007d368
walk: return a single value
Matt Mackall <mpm@selenic.com>
parents:
6585
diff
changeset
|
319 |
for abs in repo.walk(m): |
4522
591322269fed
Use absolute paths in addremove.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4478
diff
changeset
|
320 |
target = repo.wjoin(abs) |
6651
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
321 |
good = True |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
322 |
try: |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
323 |
audit_path(abs) |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
324 |
except: |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
325 |
good = False |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
326 |
rel = m.rel(abs) |
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
327 |
exact = m.exact(abs) |
6656 | 328 |
if good and abs not in repo.dirstate: |
8988
1247751d9bf8
addremove: normalize some variable names
Matt Mackall <mpm@selenic.com>
parents:
8987
diff
changeset
|
329 |
unknown.append(abs) |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
330 |
if repo.ui.verbose or not exact: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
331 |
repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
8990
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
332 |
elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) |
5487
7a64931e2d76
Fix file-changed-to-dir and dir-to-file commits (issue660).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5248
diff
changeset
|
333 |
or (os.path.isdir(target) and not os.path.islink(target))): |
8988
1247751d9bf8
addremove: normalize some variable names
Matt Mackall <mpm@selenic.com>
parents:
8987
diff
changeset
|
334 |
deleted.append(abs) |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
335 |
if repo.ui.verbose or not exact: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
336 |
repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
8990
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
337 |
# for finding renames |
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
338 |
elif repo.dirstate[abs] == 'r': |
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
339 |
removed.append(abs) |
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
340 |
elif repo.dirstate[abs] == 'a': |
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
341 |
added.append(abs) |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
342 |
if not dry_run: |
8988
1247751d9bf8
addremove: normalize some variable names
Matt Mackall <mpm@selenic.com>
parents:
8987
diff
changeset
|
343 |
repo.remove(deleted) |
1247751d9bf8
addremove: normalize some variable names
Matt Mackall <mpm@selenic.com>
parents:
8987
diff
changeset
|
344 |
repo.add(unknown) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
345 |
if similarity > 0: |
8990
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
346 |
for old, new, score in findrenames(repo, added + unknown, |
627399330c7d
addremove: build lists of already added and removed files too (issue1696)
Matt Mackall <mpm@selenic.com>
parents:
8989
diff
changeset
|
347 |
removed + deleted, similarity): |
8941
37a9d551346c
addremove: drop some silly variable assignments
Matt Mackall <mpm@selenic.com>
parents:
8798
diff
changeset
|
348 |
if repo.ui.verbose or not m.exact(old) or not m.exact(new): |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
349 |
repo.ui.status(_('recording removal of %s as rename to %s ' |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
350 |
'(%d%% similar)\n') % |
8941
37a9d551346c
addremove: drop some silly variable assignments
Matt Mackall <mpm@selenic.com>
parents:
8798
diff
changeset
|
351 |
(m.rel(old), m.rel(new), score * 100)) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
352 |
if not dry_run: |
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4906
diff
changeset
|
353 |
repo.copy(old, new) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
354 |
|
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
355 |
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
|
356 |
# called with the repo lock held |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
357 |
# |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
358 |
# hgsep => pathname that uses "/" to separate directories |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
359 |
# 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
|
360 |
cwd = repo.getcwd() |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
361 |
targets = {} |
5607 | 362 |
after = opts.get("after") |
363 |
dryrun = opts.get("dry_run") |
|
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
364 |
|
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
365 |
def walkpat(pat): |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
366 |
srcs = [] |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
367 |
m = match(repo, [pat], opts, globbed=True) |
6586
d3463007d368
walk: return a single value
Matt Mackall <mpm@selenic.com>
parents:
6585
diff
changeset
|
368 |
for abs in repo.walk(m): |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
369 |
state = repo.dirstate[abs] |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
370 |
rel = m.rel(abs) |
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
371 |
exact = m.exact(abs) |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
372 |
if state in '?r': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
373 |
if exact and state == '?': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
374 |
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
|
375 |
if exact and state == 'r': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
376 |
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
|
377 |
' remove\n') % rel) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
378 |
continue |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
379 |
# abs: hgsep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
380 |
# rel: ossep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
381 |
srcs.append((abs, rel, exact)) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
382 |
return srcs |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
383 |
|
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
384 |
# abssrc: hgsep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
385 |
# relsrc: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
386 |
# otarget: ossep |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
387 |
def copyfile(abssrc, relsrc, otarget, exact): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
388 |
abstarget = util.canonpath(repo.root, cwd, otarget) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
389 |
reltarget = repo.pathto(abstarget, cwd) |
5607 | 390 |
target = repo.wjoin(abstarget) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
391 |
src = repo.wjoin(abssrc) |
5608 | 392 |
state = repo.dirstate[abstarget] |
5607 | 393 |
|
394 |
# check for collisions |
|
395 |
prevsrc = targets.get(abstarget) |
|
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
396 |
if prevsrc is not None: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
397 |
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
|
398 |
(reltarget, repo.pathto(abssrc, cwd), |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
399 |
repo.pathto(prevsrc, cwd))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
400 |
return |
5607 | 401 |
|
402 |
# check for overwrites |
|
5608 | 403 |
exists = os.path.exists(target) |
8117
2b30d8488819
remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents:
8013
diff
changeset
|
404 |
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
|
405 |
if not opts['force']: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
406 |
ui.warn(_('%s: not overwriting - file exists\n') % |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
407 |
reltarget) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
408 |
return |
5607 | 409 |
|
410 |
if after: |
|
5608 | 411 |
if not exists: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
412 |
return |
5608 | 413 |
elif not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
414 |
try: |
5608 | 415 |
if exists: |
416 |
os.unlink(target) |
|
417 |
targetdir = os.path.dirname(target) or '.' |
|
418 |
if not os.path.isdir(targetdir): |
|
419 |
os.makedirs(targetdir) |
|
420 |
util.copyfile(src, target) |
|
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
421 |
except IOError, inst: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
422 |
if inst.errno == errno.ENOENT: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
423 |
ui.warn(_('%s: deleted in working copy\n') % relsrc) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
424 |
else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
425 |
ui.warn(_('%s: cannot copy - %s\n') % |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
426 |
(relsrc, inst.strerror)) |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
427 |
return True # report a failure |
5607 | 428 |
|
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
429 |
if ui.verbose or not exact: |
7894
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
430 |
if rename: |
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
431 |
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
|
432 |
else: |
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
433 |
ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
5608 | 434 |
|
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
435 |
targets[abstarget] = abssrc |
5607 | 436 |
|
437 |
# fix up dirstate |
|
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
438 |
origsrc = repo.dirstate.copied(abssrc) or abssrc |
5604
4b7b21acede0
copy: fix copying back with -A (issue836)
Matt Mackall <mpm@selenic.com>
parents:
5589
diff
changeset
|
439 |
if abstarget == origsrc: # copying back a copy? |
5608 | 440 |
if state not in 'mn' and not dryrun: |
441 |
repo.dirstate.normallookup(abstarget) |
|
5604
4b7b21acede0
copy: fix copying back with -A (issue836)
Matt Mackall <mpm@selenic.com>
parents:
5589
diff
changeset
|
442 |
else: |
7121
b801d6e5dc83
rename: handle renaming to a target marked removed
Matt Mackall <mpm@selenic.com>
parents:
6980
diff
changeset
|
443 |
if repo.dirstate[origsrc] == 'a' and origsrc == abssrc: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
444 |
if not ui.quiet: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
445 |
ui.warn(_("%s has not been committed yet, so no copy " |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
446 |
"data will be stored for %s.\n") |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
447 |
% (repo.pathto(origsrc, cwd), reltarget)) |
7121
b801d6e5dc83
rename: handle renaming to a target marked removed
Matt Mackall <mpm@selenic.com>
parents:
6980
diff
changeset
|
448 |
if repo.dirstate[abstarget] in '?r' and not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
449 |
repo.add([abstarget]) |
5607 | 450 |
elif not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
451 |
repo.copy(origsrc, abstarget) |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
452 |
|
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
453 |
if rename and not dryrun: |
6566
30d3d531e11a
rename --after: do not unlink source file (issue910)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6553
diff
changeset
|
454 |
repo.remove([abssrc], not after) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
455 |
|
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
456 |
# pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
457 |
# dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
458 |
# srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
459 |
# return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
460 |
def targetpathfn(pat, dest, srcs): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
461 |
if os.path.isdir(pat): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
462 |
abspfx = util.canonpath(repo.root, cwd, pat) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
463 |
abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
464 |
if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
465 |
striplen = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
466 |
else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
467 |
striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
468 |
if striplen: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
469 |
striplen += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
470 |
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
|
471 |
elif destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
472 |
res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
473 |
os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
474 |
else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
475 |
res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
476 |
return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
477 |
|
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
478 |
# pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
479 |
# dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
480 |
# srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
481 |
# return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
482 |
def targetpathafterfn(pat, dest, srcs): |
8568 | 483 |
if _match.patkind(pat): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
484 |
# a mercurial pattern |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
485 |
res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
486 |
os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
487 |
else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
488 |
abspfx = util.canonpath(repo.root, cwd, pat) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
489 |
if len(abspfx) < len(srcs[0][0]): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
490 |
# 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
|
491 |
# 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
|
492 |
def evalpath(striplen): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
493 |
score = 0 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
494 |
for s in srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
495 |
t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
496 |
if os.path.exists(t): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
497 |
score += 1 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
498 |
return score |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
499 |
|
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
500 |
abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
501 |
striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
502 |
if striplen: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
503 |
striplen += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
504 |
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
|
505 |
score = evalpath(striplen) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
506 |
striplen1 = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
507 |
if striplen1: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
508 |
striplen1 += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
509 |
if evalpath(striplen1) > score: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
510 |
striplen = striplen1 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
511 |
res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
512 |
util.localpath(p)[striplen:]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
513 |
else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
514 |
# a file |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
515 |
if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
516 |
res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
517 |
os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
518 |
else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
519 |
res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
520 |
return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
521 |
|
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
522 |
|
8614
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8568
diff
changeset
|
523 |
pats = expandpats(pats) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
524 |
if not pats: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
525 |
raise util.Abort(_('no source or destination specified')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
526 |
if len(pats) == 1: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
527 |
raise util.Abort(_('no destination specified')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
528 |
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
|
529 |
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
|
530 |
if not destdirexists: |
8568 | 531 |
if len(pats) > 1 or _match.patkind(pats[0]): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
532 |
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
|
533 |
'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
|
534 |
if util.endswithsep(dest): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
535 |
raise util.Abort(_('destination %s is not a directory') % dest) |
5607 | 536 |
|
537 |
tfn = targetpathfn |
|
538 |
if after: |
|
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
539 |
tfn = targetpathafterfn |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
540 |
copylist = [] |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
541 |
for pat in pats: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
542 |
srcs = walkpat(pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
543 |
if not srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
544 |
continue |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
545 |
copylist.append((tfn(pat, dest, srcs), srcs)) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
546 |
if not copylist: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
547 |
raise util.Abort(_('no files to copy')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
548 |
|
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
549 |
errors = 0 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
550 |
for targetpath, srcs in copylist: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
551 |
for abssrc, relsrc, exact in srcs: |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
552 |
if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
553 |
errors += 1 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
554 |
|
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
555 |
if errors: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
556 |
ui.warn(_('(consider using --after)\n')) |
5609 | 557 |
|
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
558 |
return errors |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
559 |
|
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
|
560 |
def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
561 |
runargs=None): |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
562 |
'''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
|
563 |
|
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
564 |
if opts['daemon'] and not opts['daemon_pipefds']: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
565 |
rfd, wfd = os.pipe() |
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
|
566 |
if not runargs: |
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
567 |
runargs = sys.argv[:] |
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
568 |
runargs.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
5797
7b7f03c7dfa5
serve: Don't change directory in the child if invoked with -d and --cwd
Bryan O'Sullivan <bos@serpentine.com>
parents:
5760
diff
changeset
|
569 |
# Don't pass --cwd to the child process, because we've already |
7b7f03c7dfa5
serve: Don't change directory in the child if invoked with -d and --cwd
Bryan O'Sullivan <bos@serpentine.com>
parents:
5760
diff
changeset
|
570 |
# changed directory. |
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
|
571 |
for i in xrange(1,len(runargs)): |
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
572 |
if runargs[i].startswith('--cwd='): |
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
573 |
del runargs[i] |
5797
7b7f03c7dfa5
serve: Don't change directory in the child if invoked with -d and --cwd
Bryan O'Sullivan <bos@serpentine.com>
parents:
5760
diff
changeset
|
574 |
break |
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
|
575 |
elif runargs[i].startswith('--cwd'): |
ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9367
diff
changeset
|
576 |
del runargs[i:i+2] |
5797
7b7f03c7dfa5
serve: Don't change directory in the child if invoked with -d and --cwd
Bryan O'Sullivan <bos@serpentine.com>
parents:
5760
diff
changeset
|
577 |
break |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
578 |
pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
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
|
579 |
runargs[0], runargs) |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
580 |
os.close(wfd) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
581 |
os.read(rfd, 1) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
582 |
if parentfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
583 |
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
|
584 |
else: |
9896
2c2f7593ffc4
cmdutil.service: do not _exit(0) in the parent process
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9668
diff
changeset
|
585 |
return |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
586 |
|
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
587 |
if initfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
588 |
initfn() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
589 |
|
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
590 |
if opts['pid_file']: |
9958
777c1df76ef4
run-tests: add --inotify option to test runner
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9928
diff
changeset
|
591 |
fp = open(opts['pid_file'], 'a') |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
592 |
fp.write(str(os.getpid()) + '\n') |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
593 |
fp.close() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
594 |
|
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
595 |
if opts['daemon_pipefds']: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
596 |
rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
597 |
os.close(rfd) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
598 |
try: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
599 |
os.setsid() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
600 |
except AttributeError: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
601 |
pass |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
602 |
os.write(wfd, 'y') |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
603 |
os.close(wfd) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
604 |
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
|
605 |
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
|
606 |
|
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
607 |
nullfd = os.open(util.nulldev, os.O_RDWR) |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
608 |
logfilefd = nullfd |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
609 |
if logfile: |
e0ed17984a48
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8778
diff
changeset
|
610 |
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
|
611 |
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
|
612 |
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
|
613 |
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
|
614 |
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
|
615 |
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
|
616 |
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
|
617 |
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
|
618 |
|
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
619 |
if runfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
620 |
return runfn() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
621 |
|
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
622 |
class changeset_printer(object): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
623 |
'''show changeset information when templating not requested.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
624 |
|
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
625 |
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
|
626 |
self.ui = ui |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
627 |
self.repo = repo |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
628 |
self.buffered = buffered |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
629 |
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
|
630 |
self.diffopts = diffopts |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
631 |
self.header = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
632 |
self.hunk = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
633 |
self.lastheader = None |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
634 |
|
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
635 |
def flush(self, rev): |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
636 |
if rev in self.header: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
637 |
h = self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
638 |
if h != self.lastheader: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
639 |
self.lastheader = h |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
640 |
self.ui.write(h) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
641 |
del self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
642 |
if rev in self.hunk: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
643 |
self.ui.write(self.hunk[rev]) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
644 |
del self.hunk[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
645 |
return 1 |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
646 |
return 0 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
647 |
|
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
648 |
def show(self, ctx, copies=(), **props): |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
649 |
if self.buffered: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
650 |
self.ui.pushbuffer() |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
651 |
self._show(ctx, copies, props) |
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
652 |
self.hunk[ctx.rev()] = self.ui.popbuffer() |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
653 |
else: |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
654 |
self._show(ctx, copies, props) |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
655 |
|
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
656 |
def _show(self, ctx, copies, props): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
657 |
'''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
|
658 |
changenode = ctx.node() |
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
659 |
rev = ctx.rev() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
660 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
661 |
if self.ui.quiet: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
662 |
self.ui.write("%d:%s\n" % (rev, short(changenode))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
663 |
return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
664 |
|
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
665 |
log = self.repo.changelog |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
666 |
date = util.datestr(ctx.date()) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
667 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
668 |
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
|
669 |
|
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
|
670 |
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
|
671 |
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
|
672 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
673 |
self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
674 |
|
9637
64425c5a9257
cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents:
9547
diff
changeset
|
675 |
branch = ctx.branch() |
4176
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4055
diff
changeset
|
676 |
# 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
|
677 |
if branch != 'default': |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7894
diff
changeset
|
678 |
branch = encoding.tolocal(branch) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
679 |
self.ui.write(_("branch: %s\n") % branch) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
680 |
for tag in self.repo.nodetags(changenode): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
681 |
self.ui.write(_("tag: %s\n") % tag) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
682 |
for parent in parents: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
683 |
self.ui.write(_("parent: %d:%s\n") % parent) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
684 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
685 |
if self.ui.debugflag: |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
686 |
mnode = ctx.manifestnode() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
687 |
self.ui.write(_("manifest: %d:%s\n") % |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
688 |
(self.repo.manifest.rev(mnode), hex(mnode))) |
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
689 |
self.ui.write(_("user: %s\n") % ctx.user()) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
690 |
self.ui.write(_("date: %s\n") % date) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
691 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
692 |
if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
693 |
files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
694 |
for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
695 |
files): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
696 |
if value: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
697 |
self.ui.write("%-12s %s\n" % (key, " ".join(value))) |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
698 |
elif ctx.files() and self.ui.verbose: |
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
699 |
self.ui.write(_("files: %s\n") % " ".join(ctx.files())) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
700 |
if copies and self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
701 |
copies = ['%s (%s)' % c for c in copies] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
702 |
self.ui.write(_("copies: %s\n") % ' '.join(copies)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
703 |
|
9637
64425c5a9257
cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents:
9547
diff
changeset
|
704 |
extra = ctx.extra() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
705 |
if extra and self.ui.debugflag: |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8189
diff
changeset
|
706 |
for key, value in sorted(extra.items()): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
707 |
self.ui.write(_("extra: %s=%s\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
708 |
% (key, value.encode('string_escape'))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
709 |
|
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
710 |
description = ctx.description().strip() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
711 |
if description: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
712 |
if self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
713 |
self.ui.write(_("description:\n")) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
714 |
self.ui.write(description) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
715 |
self.ui.write("\n\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
716 |
else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
717 |
self.ui.write(_("summary: %s\n") % |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
718 |
description.splitlines()[0]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
719 |
self.ui.write("\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
720 |
|
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
721 |
self.showpatch(changenode) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
722 |
|
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
723 |
def showpatch(self, node): |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
724 |
if self.patch: |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
725 |
prev = self.repo.changelog.parents(node)[0] |
7308
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
726 |
chunks = patch.diff(self.repo, prev, node, match=self.patch, |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
727 |
opts=patch.diffopts(self.ui, self.diffopts)) |
7308
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
728 |
for chunk in chunks: |
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
729 |
self.ui.write(chunk) |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
730 |
self.ui.write("\n") |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
731 |
|
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
|
732 |
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
|
733 |
"""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
|
734 |
|
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
|
735 |
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
|
736 |
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
|
737 |
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
|
738 |
""" |
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
|
739 |
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
|
740 |
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
|
741 |
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
|
742 |
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
|
743 |
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
|
744 |
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
|
745 |
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
|
746 |
|
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
|
747 |
|
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
748 |
class changeset_templater(changeset_printer): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
749 |
'''format changeset information.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
750 |
|
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7667
diff
changeset
|
751 |
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
|
752 |
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
|
753 |
formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
acc202b71619
templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8312
diff
changeset
|
754 |
self.t = templater.templater(mapfile, {'formatnode': formatnode}, |
4352
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
755 |
cache={ |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
756 |
'parent': '{rev}:{node|formatnode} ', |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
757 |
'manifest': '{rev}:{node|formatnode}', |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
758 |
'filecopy': '{name} ({source})'}) |
9536
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
759 |
# Cache mapping from rev to a tuple with tag date, tag |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
760 |
# distance and tag name |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
761 |
self._latesttagcache = {-1: (0, 0, 'null')} |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
762 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
763 |
def use_template(self, t): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
764 |
'''set template string to use''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
765 |
self.t.cache['changeset'] = t |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
766 |
|
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
767 |
def _meaningful_parentrevs(self, ctx): |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
768 |
"""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
|
769 |
""" |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
770 |
parents = ctx.parents() |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
771 |
if len(parents) > 1: |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
772 |
return parents |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
773 |
if self.ui.debugflag: |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
774 |
return [parents[0], self.repo['null']] |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
775 |
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
|
776 |
return [] |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
777 |
return parents |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
778 |
|
9536
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
779 |
def _latesttaginfo(self, rev): |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
780 |
'''return date, distance and name for the latest tag of rev''' |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
781 |
todo = [rev] |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
782 |
while todo: |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
783 |
rev = todo.pop() |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
784 |
if rev in self._latesttagcache: |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
785 |
continue |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
786 |
ctx = self.repo[rev] |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
787 |
tags = [t for t in ctx.tags() if self.repo.tagtype(t) == 'global'] |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
788 |
if tags: |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
789 |
self._latesttagcache[rev] = ctx.date()[0], 0, ':'.join(sorted(tags)) |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
790 |
continue |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
791 |
try: |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
792 |
# The tuples are laid out so the right one can be found by comparison. |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
793 |
pdate, pdist, ptag = max( |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
794 |
self._latesttagcache[p.rev()] for p in ctx.parents()) |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
795 |
except KeyError: |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
796 |
# Cache miss - recurse |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
797 |
todo.append(rev) |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
798 |
todo.extend(p.rev() for p in ctx.parents()) |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
799 |
continue |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
800 |
self._latesttagcache[rev] = pdate, pdist + 1, ptag |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
801 |
return self._latesttagcache[rev] |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
802 |
|
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
803 |
def _show(self, ctx, copies, props): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
804 |
'''show a single changeset or file revision''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
805 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
806 |
def showlist(name, values, plural=None, **args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
807 |
'''expand set of values. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
808 |
name is name of key in template map. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
809 |
values is list of strings or dicts. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
810 |
plural is plural of name, if not simply name + 's'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
811 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
812 |
expansion works like this, given name 'foo'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
813 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
814 |
if values is empty, expand 'no_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
815 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
816 |
if 'foo' not in template map, return values as a string, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
817 |
joined by space. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
818 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
819 |
expand 'start_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
820 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
821 |
for each value, expand 'foo'. if 'last_foo' in template |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
822 |
map, expand it instead of 'foo' for last key. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
823 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
824 |
expand 'end_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
825 |
''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
826 |
if plural: names = plural |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
827 |
else: names = name + 's' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
828 |
if not values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
829 |
noname = 'no_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
830 |
if noname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
831 |
yield self.t(noname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
832 |
return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
833 |
if name not in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
834 |
if isinstance(values[0], str): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
835 |
yield ' '.join(values) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
836 |
else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
837 |
for v in values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
838 |
yield dict(v, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
839 |
return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
840 |
startname = 'start_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
841 |
if startname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
842 |
yield self.t(startname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
843 |
vargs = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
844 |
def one(v, tag=name): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
845 |
try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
846 |
vargs.update(v) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
847 |
except (AttributeError, ValueError): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
848 |
try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
849 |
for a, b in v: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
850 |
vargs[a] = b |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
851 |
except ValueError: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
852 |
vargs[name] = v |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
853 |
return self.t(tag, **vargs) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
854 |
lastname = 'last_' + name |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
855 |
if lastname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
856 |
last = values.pop() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
857 |
else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
858 |
last = None |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
859 |
for v in values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
860 |
yield one(v) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
861 |
if last is not None: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
862 |
yield one(last, tag=lastname) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
863 |
endname = 'end_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
864 |
if endname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
865 |
yield self.t(endname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
866 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
867 |
def showbranches(**args): |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
868 |
branch = ctx.branch() |
4176
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4055
diff
changeset
|
869 |
if branch != 'default': |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7894
diff
changeset
|
870 |
branch = encoding.tolocal(branch) |
3648
2801a3efc7c3
changeset templater: convert some unnecessary yields to returns
Matt Mackall <mpm@selenic.com>
parents:
3645
diff
changeset
|
871 |
return showlist('branch', [branch], plural='branches', **args) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
872 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
873 |
def showparents(**args): |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
874 |
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
|
875 |
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
|
876 |
return showlist('parent', parents, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
877 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
878 |
def showtags(**args): |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
879 |
return showlist('tag', ctx.tags(), **args) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
880 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
881 |
def showextras(**args): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8189
diff
changeset
|
882 |
for key, value in sorted(ctx.extra().items()): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
883 |
args = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
884 |
args.update(dict(key=key, value=value)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
885 |
yield self.t('extra', **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
886 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
887 |
def showcopies(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
888 |
c = [{'name': x[0], 'source': x[1]} for x in copies] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
889 |
return showlist('file_copy', c, plural='file_copies', **args) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5716
diff
changeset
|
890 |
|
5545
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
891 |
files = [] |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
892 |
def getfiles(): |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5716
diff
changeset
|
893 |
if not files: |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
894 |
files[:] = self.repo.status(ctx.parents()[0].node(), |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
895 |
ctx.node())[:3] |
5545
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
896 |
return files |
5550
db6633f11d59
cmdutil: make "files" list all files, add "file_mods" for modified files
Patrick Mezard <pmezard@gmail.com>
parents:
5545
diff
changeset
|
897 |
def showfiles(**args): |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
898 |
return showlist('file', ctx.files(), **args) |
5550
db6633f11d59
cmdutil: make "files" list all files, add "file_mods" for modified files
Patrick Mezard <pmezard@gmail.com>
parents:
5545
diff
changeset
|
899 |
def showmods(**args): |
db6633f11d59
cmdutil: make "files" list all files, add "file_mods" for modified files
Patrick Mezard <pmezard@gmail.com>
parents:
5545
diff
changeset
|
900 |
return showlist('file_mod', getfiles()[0], **args) |
5545
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
901 |
def showadds(**args): |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
902 |
return showlist('file_add', getfiles()[1], **args) |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
903 |
def showdels(**args): |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
904 |
return showlist('file_del', getfiles()[2], **args) |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
905 |
def showmanifest(**args): |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
906 |
args = args.copy() |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
907 |
args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]), |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
908 |
node=hex(ctx.changeset()[0]))) |
5545
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
909 |
return self.t('manifest', **args) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
910 |
|
7879
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
911 |
def showdiffstat(**args): |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
912 |
diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node()) |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
913 |
files, adds, removes = 0, 0, 0 |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
914 |
for i in patch.diffstatdata(util.iterlines(diff)): |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
915 |
files += 1 |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
916 |
adds += i[1] |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
917 |
removes += i[2] |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
918 |
return '%s: +%s/-%s' % (files, adds, removes) |
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
919 |
|
9536
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
920 |
def showlatesttag(**args): |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
921 |
return self._latesttaginfo(ctx.rev())[2] |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
922 |
def showlatesttagdistance(**args): |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
923 |
return self._latesttaginfo(ctx.rev())[1] |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
924 |
|
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
925 |
defprops = { |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
926 |
'author': ctx.user(), |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
927 |
'branches': showbranches, |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
928 |
'date': ctx.date(), |
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
929 |
'desc': ctx.description().strip(), |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
930 |
'file_adds': showadds, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
931 |
'file_dels': showdels, |
5550
db6633f11d59
cmdutil: make "files" list all files, add "file_mods" for modified files
Patrick Mezard <pmezard@gmail.com>
parents:
5545
diff
changeset
|
932 |
'file_mods': showmods, |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
933 |
'files': showfiles, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
934 |
'file_copies': showcopies, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
935 |
'manifest': showmanifest, |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
936 |
'node': ctx.hex(), |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
937 |
'parents': showparents, |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
938 |
'rev': ctx.rev(), |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
939 |
'tags': showtags, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
940 |
'extras': showextras, |
7879
5c4026a289a4
templater: ability to display diffstat for log-like commands
Alexander Solovyov <piranha at piranha.org.ua>
parents:
7878
diff
changeset
|
941 |
'diffstat': showdiffstat, |
9536
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
942 |
'latesttag': showlatesttag, |
f04d17912441
cmdutil: templating keywords latesttag and latesttagdistance
Mads Kiilerich <mads@kiilerich.com>
parents:
9513
diff
changeset
|
943 |
'latesttagdistance': showlatesttagdistance, |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
944 |
} |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
945 |
props = props.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
946 |
props.update(defprops) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
947 |
|
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
948 |
# 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
|
949 |
|
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
950 |
tmplmodes = [ |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
951 |
(True, None), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
952 |
(self.ui.verbose, 'verbose'), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
953 |
(self.ui.quiet, 'quiet'), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
954 |
(self.ui.debugflag, 'debug'), |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
955 |
] |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
956 |
|
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
957 |
types = {'header': '', 'changeset': 'changeset'} |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
958 |
for mode, postfix in tmplmodes: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
959 |
for type in types: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
960 |
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
|
961 |
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
|
962 |
types[type] = cur |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
963 |
|
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
964 |
try: |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
965 |
|
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
966 |
# write header |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
967 |
if types['header']: |
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
968 |
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
|
969 |
if self.buffered: |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
970 |
self.header[ctx.rev()] = h |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
971 |
else: |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
972 |
self.ui.write(h) |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
973 |
|
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
974 |
# 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
|
975 |
key = types['changeset'] |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
976 |
self.ui.write(templater.stringify(self.t(key, **props))) |
7878
8c09952cd39a
templater: use contexts consistently throughout changeset_templater
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7807
diff
changeset
|
977 |
self.showpatch(ctx.node()) |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
978 |
|
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
979 |
except KeyError, inst: |
8013
9ec25db32b4e
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7967
diff
changeset
|
980 |
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
|
981 |
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
|
982 |
except SyntaxError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
983 |
raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
984 |
|
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
985 |
def show_changeset(ui, repo, opts, buffered=False, matchfn=False): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
986 |
"""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
|
987 |
|
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
988 |
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
|
989 |
1. option 'template' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
990 |
2. option 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
991 |
3. [ui] setting 'logtemplate' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
992 |
4. [ui] setting 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
993 |
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
|
994 |
regular display via changeset_printer() is done. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
995 |
""" |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
996 |
# options |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
997 |
patch = False |
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
998 |
if opts.get('patch'): |
6597
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
999 |
patch = matchfn or 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
|
1000 |
|
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
1001 |
tmpl = opts.get('template') |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1002 |
style = None |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
1003 |
if tmpl: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
1004 |
tmpl = templater.parsestring(tmpl, quoted=False) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
1005 |
else: |
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1006 |
style = opts.get('style') |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1007 |
|
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1008 |
# ui settings |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1009 |
if not (tmpl or style): |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1010 |
tmpl = ui.config('ui', 'logtemplate') |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1011 |
if tmpl: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1012 |
tmpl = templater.parsestring(tmpl) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1013 |
else: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1014 |
style = ui.config('ui', 'style') |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1015 |
|
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1016 |
if not (tmpl or style): |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1017 |
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
|
1018 |
|
7967
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1019 |
mapfile = None |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1020 |
if style and not tmpl: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1021 |
mapfile = style |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1022 |
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
|
1023 |
mapname = (templater.templatepath('map-cmdline.' + mapfile) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1024 |
or templater.templatepath(mapfile)) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1025 |
if mapname: mapfile = mapname |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1026 |
|
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1027 |
try: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1028 |
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
|
1029 |
except SyntaxError, inst: |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1030 |
raise util.Abort(inst.args[0]) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1031 |
if tmpl: t.use_template(tmpl) |
c03f42159afa
cmdutil: refactor handling of templating in show_changeset()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7948
diff
changeset
|
1032 |
return t |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
1033 |
|
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
1034 |
def finddate(ui, repo, date): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
1035 |
"""Find the tipmost changeset that matches the given date spec""" |
9667 | 1036 |
|
5836
c5c9a022bd9a
Tweak finddate to pass date directly.
mark.williamson@cl.cam.ac.uk
parents:
5829
diff
changeset
|
1037 |
df = util.matchdate(date) |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1038 |
m = matchall(repo) |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
1039 |
results = {} |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1040 |
|
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1041 |
def prep(ctx, fns): |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1042 |
d = ctx.date() |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1043 |
if df(d[0]): |
9668
2c24471d478c
cmdutil: fix bug in finddate() implementation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9667
diff
changeset
|
1044 |
results[ctx.rev()] = d |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1045 |
|
9667 | 1046 |
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
|
1047 |
rev = ctx.rev() |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1048 |
if rev in results: |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1049 |
ui.status(_("Found revision %s from %s\n") % |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1050 |
(rev, util.datestr(results[rev]))) |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1051 |
return str(rev) |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
1052 |
|
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
1053 |
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
|
1054 |
|
9665
1de5ebfa5585
walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents:
9664
diff
changeset
|
1055 |
def walkchangerevs(repo, match, opts, prepare): |
7807
bd8f44638847
help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents:
7779
diff
changeset
|
1056 |
'''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
|
1057 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1058 |
Callers most commonly need to iterate backwards over the history |
7807
bd8f44638847
help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents:
7779
diff
changeset
|
1059 |
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
|
1060 |
performance, so we use iterators in a "windowed" way. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1061 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1062 |
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
|
1063 |
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
|
1064 |
order (usually backwards) to display it. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1065 |
|
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1066 |
This function returns an iterator yielding contexts. Before |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1067 |
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
|
1068 |
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
|
1069 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1070 |
def increasing_windows(start, end, windowsize=8, sizelimit=512): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1071 |
if start < end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1072 |
while start < end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1073 |
yield start, min(windowsize, end-start) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1074 |
start += windowsize |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1075 |
if windowsize < sizelimit: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1076 |
windowsize *= 2 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1077 |
else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1078 |
while start > end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1079 |
yield start, min(windowsize, start-end-1) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1080 |
start -= windowsize |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1081 |
if windowsize < sizelimit: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1082 |
windowsize *= 2 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1083 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1084 |
follow = opts.get('follow') or opts.get('follow_first') |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1085 |
|
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1086 |
if not len(repo): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1087 |
return [] |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1088 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1089 |
if follow: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6739
diff
changeset
|
1090 |
defrange = '%s:0' % repo['.'].rev() |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1091 |
else: |
6145
154f8be6272b
cmdutil.walkchangerevs: use '-1:0' instead ot 'tip:0'
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6139
diff
changeset
|
1092 |
defrange = '-1:0' |
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
1093 |
revs = revrange(repo, opts['rev'] or [defrange]) |
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
8119
diff
changeset
|
1094 |
wanted = set() |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1095 |
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
|
1096 |
fncache = {} |
9655
6d7d3f849062
walkchangerevs: internalize ctx caching
Matt Mackall <mpm@selenic.com>
parents:
9654
diff
changeset
|
1097 |
change = util.cachefunc(repo.changectx) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1098 |
|
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1099 |
if not slowpath and not match.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1100 |
# 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
|
1101 |
wanted = set(revs) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1102 |
copies = [] |
9665
1de5ebfa5585
walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents:
9664
diff
changeset
|
1103 |
|
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1104 |
if not slowpath: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1105 |
# Only files, no patterns. Check the history of each file. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1106 |
def filerevgen(filelog, node): |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1107 |
cl_count = len(repo) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1108 |
if node is None: |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1109 |
last = len(filelog) - 1 |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1110 |
else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1111 |
last = filelog.rev(node) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1112 |
for i, window in increasing_windows(last, nullrev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1113 |
revs = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1114 |
for j in xrange(i - window, i + 1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1115 |
n = filelog.node(j) |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7319
diff
changeset
|
1116 |
revs.append((filelog.linkrev(j), |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1117 |
follow and filelog.renamed(n))) |
8210
344751cd8cb8
replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents:
8209
diff
changeset
|
1118 |
for rev in reversed(revs): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1119 |
# only yield rev for which we have the changelog, it can |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1120 |
# happen while doing "hg log" during a pull or commit |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1121 |
if rev[0] < cl_count: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1122 |
yield rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1123 |
def iterfiles(): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1124 |
for filename in match.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1125 |
yield filename, None |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1126 |
for filename_node in copies: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1127 |
yield filename_node |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1128 |
minrev, maxrev = min(revs), max(revs) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1129 |
for file_, node in iterfiles(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1130 |
filelog = repo.file(file_) |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1131 |
if not len(filelog): |
6536
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1132 |
if node is None: |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1133 |
# A zero count may be a directory or deleted file, so |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1134 |
# try to find matching entries on the slow path. |
7404
07cb58b8c843
Improved error message for log --follow
Brendan Cully <brendan@kublai.com>
parents:
7369
diff
changeset
|
1135 |
if follow: |
07cb58b8c843
Improved error message for log --follow
Brendan Cully <brendan@kublai.com>
parents:
7369
diff
changeset
|
1136 |
raise util.Abort(_('cannot follow nonexistent file: "%s"') % file_) |
6536
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1137 |
slowpath = True |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1138 |
break |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1139 |
else: |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1140 |
continue |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1141 |
for rev, copied in filerevgen(filelog, node): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1142 |
if rev <= maxrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1143 |
if rev < minrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1144 |
break |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1145 |
fncache.setdefault(rev, []) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1146 |
fncache[rev].append(file_) |
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
8119
diff
changeset
|
1147 |
wanted.add(rev) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1148 |
if follow and copied: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1149 |
copies.append(copied) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1150 |
if slowpath: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1151 |
if follow: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1152 |
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
|
1153 |
'filenames')) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1154 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1155 |
# The slow path checks files modified in every changeset. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1156 |
def changerevgen(): |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1157 |
for i, window in increasing_windows(len(repo) - 1, nullrev): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1158 |
for j in xrange(i - window, i + 1): |
9367
1ef630452e0b
cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9118
diff
changeset
|
1159 |
yield change(j) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1160 |
|
9367
1ef630452e0b
cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9118
diff
changeset
|
1161 |
for ctx in changerevgen(): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1162 |
matches = filter(match, ctx.files()) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1163 |
if matches: |
9367
1ef630452e0b
cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9118
diff
changeset
|
1164 |
fncache[ctx.rev()] = matches |
1ef630452e0b
cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9118
diff
changeset
|
1165 |
wanted.add(ctx.rev()) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1166 |
|
8778
c5f36402daad
use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8761
diff
changeset
|
1167 |
class followfilter(object): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1168 |
def __init__(self, onlyfirst=False): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1169 |
self.startrev = nullrev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1170 |
self.roots = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1171 |
self.onlyfirst = onlyfirst |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1172 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1173 |
def match(self, rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1174 |
def realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1175 |
if self.onlyfirst: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1176 |
return repo.changelog.parentrevs(rev)[0:1] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1177 |
else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1178 |
return filter(lambda x: x != nullrev, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1179 |
repo.changelog.parentrevs(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1180 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1181 |
if self.startrev == nullrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1182 |
self.startrev = rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1183 |
return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1184 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1185 |
if rev > self.startrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1186 |
# forward: all descendants |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1187 |
if not self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1188 |
self.roots.append(self.startrev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1189 |
for parent in realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1190 |
if parent in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1191 |
self.roots.append(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1192 |
return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1193 |
else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1194 |
# backwards: all parents |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1195 |
if not self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1196 |
self.roots.extend(realparents(self.startrev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1197 |
if rev in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1198 |
self.roots.remove(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1199 |
self.roots.extend(realparents(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1200 |
return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1201 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1202 |
return False |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1203 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1204 |
# 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
|
1205 |
# 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
|
1206 |
for rev in opts.get('prune', ()): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1207 |
rev = repo.changelog.rev(repo.lookup(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1208 |
ff = followfilter() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1209 |
stop = min(revs[0], revs[-1]) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1210 |
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
|
1211 |
if ff.match(x): |
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
8119
diff
changeset
|
1212 |
wanted.discard(x) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1213 |
|
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1214 |
def iterate(): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1215 |
if follow and not match.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1216 |
ff = followfilter(onlyfirst=opts.get('follow_first')) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1217 |
def want(rev): |
8119
af44d0b953c6
cmdutil: return boolean result directly in want function
Martin Geisler <mg@lazybytes.net>
parents:
8117
diff
changeset
|
1218 |
return ff.match(rev) and rev in wanted |
3650
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 |
def want(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1221 |
return rev in wanted |
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 |
for i, window in increasing_windows(0, len(revs)): |
9664
2a4a0dc4fb85
walkchangerevs: reset cache between windows
Matt Mackall <mpm@selenic.com>
parents:
9662
diff
changeset
|
1224 |
change = util.cachefunc(repo.changectx) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1225 |
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
|
1226 |
for rev in sorted(nrevs): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1227 |
fns = fncache.get(rev) |
9654
96fe91be9c1e
walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents:
9653
diff
changeset
|
1228 |
ctx = change(rev) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1229 |
if not fns: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1230 |
def fns_generator(): |
9654
96fe91be9c1e
walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents:
9653
diff
changeset
|
1231 |
for f in ctx.files(): |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1232 |
if match(f): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1233 |
yield f |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1234 |
fns = fns_generator() |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1235 |
prepare(ctx, fns) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1236 |
for rev in nrevs: |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9656
diff
changeset
|
1237 |
yield change(rev) |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
1238 |
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
|
1239 |
|
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1240 |
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
|
1241 |
'''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
|
1242 |
date = opts.get('date') |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
1243 |
if date: |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
1244 |
opts['date'] = util.parsedate(date) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1245 |
message = logmessage(opts) |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1246 |
|
5829
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1247 |
# 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
|
1248 |
# that doesn't support addremove |
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1249 |
if opts.get('addremove'): |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1250 |
addremove(repo, pats, opts) |
5829
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1251 |
|
8709
b9e0ddb04c5c
commit: move explicit file checking into repo.commit
Matt Mackall <mpm@selenic.com>
parents:
8707
diff
changeset
|
1252 |
return commitfunc(ui, repo, message, match(repo, pats, opts), opts) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1253 |
|
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1254 |
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
|
1255 |
if ctx.description(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1256 |
return ctx.description() |
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1257 |
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
|
1258 |
|
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1259 |
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
|
1260 |
edittext = [] |
8707
0550dfe4fca1
commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents:
8680
diff
changeset
|
1261 |
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
|
1262 |
if ctx.description(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1263 |
edittext.append(ctx.description()) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1264 |
edittext.append("") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1265 |
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
|
1266 |
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
|
1267 |
" Lines beginning with 'HG:' are removed.")) |
8535
5b6a6ed4f185
cmdutil: mark string for translation
Martin Geisler <mg@lazybytes.net>
parents:
8497
diff
changeset
|
1268 |
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
|
1269 |
edittext.append("HG: --") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1270 |
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
|
1271 |
if ctx.p2(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1272 |
edittext.append(_("HG: branch merge")) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1273 |
if ctx.branch(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1274 |
edittext.append(_("HG: branch '%s'") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1275 |
% encoding.tolocal(ctx.branch())) |
8994
4a1187d3cb00
commit: report modified subrepos in commit editor
Matt Mackall <mpm@selenic.com>
parents:
8990
diff
changeset
|
1276 |
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
|
1277 |
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
|
1278 |
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
|
1279 |
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
|
1280 |
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
|
1281 |
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
|
1282 |
edittext.append("") |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1283 |
# 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
|
1284 |
olddir = os.getcwd() |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1285 |
os.chdir(repo.root) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1286 |
text = repo.ui.edit("\n".join(edittext), ctx.user()) |
8409
e84a8482c6f2
editor: move HG: filtering from ui to commiteditor
Matt Mackall <mpm@selenic.com>
parents:
8407
diff
changeset
|
1287 |
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
|
1288 |
os.chdir(olddir) |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1289 |
|
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1290 |
if not text.strip(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1291 |
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
|
1292 |
|
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
1293 |
return text |