Mercurial > hg
annotate mercurial/cmdutil.py @ 7618:6c89dd0a7797
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
During 2.17, Bugzilla ditched the old 'processmail' script. With 2.18
contrib/sendbugmail.pl arrived in its place.
For notification emails to work properly, sendbugmail.pl requires as
its second parameter the Bugzilla user who made the commit. Otherwise
the user will not be recognised as the committer, and will receive
notification emails about the commit regardless of their preference
about being notified on their own commits. This parameter should be given
to processmail also, but wasn't for historical reasons.
Add new config with the local Bugzilla install directory, and provide
defaults for the notify string which should work for most setups.
Still permit notify string to be specified, and for backwards
compatibility with any extant notify strings try first interpolating
notify string with old-style single bug ID argument. Add new 2.18
support version to introduce sendbugmail.pl.
In other words, this update should be backwards-compatible with existing
installations, but offers simplified setup in most cases. And as a bonus
Bugzilla notification emails will be dispatched correctly; notifiers will
not receive an email unless configured to do so.
author | Jim Hague <jim.hague@acm.org> |
---|---|
date | Fri, 09 Jan 2009 22:15:08 +0000 |
parents | 07cb58b8c843 |
children | 9a1ea6587557 |
rev | line source |
---|---|
2957 | 1 # cmdutil.py - help for command processing in mercurial |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 # |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
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 _ |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
10 import os, sys, bisect, stat |
5976
9f1e6ab76069
templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents:
5915
diff
changeset
|
11 import mdiff, bdiff, util, templater, templatefilters, patch, errno |
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 |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
16 class UnknownCommand(Exception): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
17 """Exception raised if command is not in the command table.""" |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
18 class AmbiguousCommand(Exception): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
19 """Exception raised if command shortcut matches more than one command.""" |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
20 |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
21 def findpossible(cmd, table, strict=False): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
22 """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
23 Return cmd -> (aliases, command table entry) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
24 for each matching command. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
25 Return debug commands (or their aliases) only if no normal command matches. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
26 """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
27 choice = {} |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
28 debugchoice = {} |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
29 for e in table.keys(): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
30 aliases = e.lstrip("^").split("|") |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
31 found = None |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
32 if cmd in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
33 found = cmd |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
34 elif not strict: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
35 for a in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
36 if a.startswith(cmd): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
37 found = a |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
38 break |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
39 if found is not None: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
40 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
|
41 debugchoice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
42 else: |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
43 choice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
44 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
45 if not choice and debugchoice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
46 choice = debugchoice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
47 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
48 return choice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
49 |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
50 def findcmd(cmd, table, strict=True): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
51 """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
|
52 choice = findpossible(cmd, table, strict) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
53 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5843
diff
changeset
|
54 if cmd in choice: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
55 return choice[cmd] |
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 len(choice) > 1: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
58 clist = choice.keys() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
59 clist.sort() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
60 raise AmbiguousCommand(cmd, clist) |
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 if choice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
63 return choice.values()[0] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
64 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
65 raise UnknownCommand(cmd) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
66 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
67 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
|
68 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
|
69 raise util.Abort(_('outstanding uncommitted merge')) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
70 modified, added, removed, deleted = repo.status()[:4] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
71 if modified or added or removed or deleted: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
72 raise util.Abort(_("outstanding uncommitted changes")) |
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 def logmessage(opts): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
75 """ get the log message according to -m and -l option """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
76 message = opts['message'] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
77 logfile = opts['logfile'] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
78 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
79 if message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
80 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
|
81 'exclusive')) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
82 if not message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
83 try: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
84 if logfile == '-': |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
85 message = sys.stdin.read() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
86 else: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
87 message = open(logfile).read() |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
88 except IOError, inst: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
89 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
|
90 (logfile, inst.strerror)) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
91 return message |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
92 |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
93 def loglimit(opts): |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
94 """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
|
95 limit = opts.get('limit') |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
96 if limit: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
97 try: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
98 limit = int(limit) |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
99 except ValueError: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
100 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
|
101 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
|
102 else: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
103 limit = sys.maxint |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
104 return limit |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
105 |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
106 def setremoteconfig(ui, opts): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
107 "copy remote options to ui tree" |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
108 if opts.get('ssh'): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
109 ui.setconfig("ui", "ssh", opts['ssh']) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
110 if opts.get('remotecmd'): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
111 ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
112 |
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
113 def revpair(repo, revs): |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
114 '''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
|
115 be None, meaning use working dir.''' |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
116 |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
117 def revfix(repo, val, defval): |
3825
000d122071b5
fix hg diff -r ''
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3814
diff
changeset
|
118 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
|
119 val = defval |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
120 return repo.lookup(val) |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
121 |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
122 if not revs: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
123 return repo.dirstate.parents()[0], None |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
124 end = None |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
125 if len(revs) == 1: |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
126 if revrangesep in revs[0]: |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
127 start, end = revs[0].split(revrangesep, 1) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
128 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
|
129 end = revfix(repo, end, len(repo) - 1) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
130 else: |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
131 start = revfix(repo, revs[0], None) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
132 elif len(revs) == 2: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
133 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
|
134 raise util.Abort(_('too many revisions specified')) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
135 start = revfix(repo, revs[0], None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
136 end = revfix(repo, revs[1], None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
137 else: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
138 raise util.Abort(_('too many revisions specified')) |
3525
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
139 return start, end |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
140 |
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
141 def revrange(repo, revs): |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
142 """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
|
143 |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
144 def revfix(repo, val, defval): |
3718
7db88b094b14
fix hg log -r ''
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3707
diff
changeset
|
145 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
|
146 return defval |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
147 return repo.changelog.rev(repo.lookup(val)) |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3524
diff
changeset
|
148 |
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
|
149 seen, l = {}, [] |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
150 for spec in revs: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
151 if revrangesep in spec: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
152 start, end = spec.split(revrangesep, 1) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
153 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
|
154 end = revfix(repo, end, len(repo) - 1) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
155 step = start > end and -1 or 1 |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
156 for rev in xrange(start, end+step, step): |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
157 if rev in seen: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
158 continue |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
159 seen[rev] = 1 |
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
|
160 l.append(rev) |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
161 else: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
162 rev = revfix(repo, spec, None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
163 if rev in seen: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
164 continue |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
165 seen[rev] = 1 |
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
|
166 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
|
167 |
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 return l |
3090
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
169 |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
170 def make_filename(repo, pat, node, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
171 total=None, seqno=None, revwidth=None, pathname=None): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
172 node_expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
173 'H': lambda: hex(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
174 'R': lambda: str(repo.changelog.rev(node)), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
175 'h': lambda: short(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
176 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
177 expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
178 '%': lambda: '%', |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
179 'b': lambda: os.path.basename(repo.root), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
180 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
181 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
182 try: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
183 if node: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
184 expander.update(node_expander) |
4836
0e2d0a78f81a
archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4825
diff
changeset
|
185 if node: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
186 expander['r'] = (lambda: |
4836
0e2d0a78f81a
archive: make the %r escape work.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4825
diff
changeset
|
187 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
|
188 if total is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
189 expander['N'] = lambda: str(total) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
190 if seqno is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
191 expander['n'] = lambda: str(seqno) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
192 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
|
193 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
|
194 if pathname is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
195 expander['s'] = lambda: os.path.basename(pathname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
196 expander['d'] = lambda: os.path.dirname(pathname) or '.' |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
197 expander['p'] = lambda: pathname |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
198 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
199 newname = [] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
200 patlen = len(pat) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
201 i = 0 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
202 while i < patlen: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
203 c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
204 if c == '%': |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
205 i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
206 c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
207 c = expander[c]() |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
208 newname.append(c) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
209 i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
210 return ''.join(newname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
211 except KeyError, inst: |
3072
bc3fe3b5b785
Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2958
diff
changeset
|
212 raise util.Abort(_("invalid format spec '%%%s' in output file name") % |
bc3fe3b5b785
Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2958
diff
changeset
|
213 inst.args[0]) |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
214 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
215 def make_file(repo, pat, node=None, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
216 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
|
217 |
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
218 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
|
219 |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
220 if not pat or pat == '-': |
7319
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
221 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
|
222 if hasattr(pat, 'write') and writable: |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
223 return pat |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
224 if hasattr(pat, 'read') and 'r' in mode: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
225 return pat |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
226 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
|
227 pathname), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
228 mode) |
2882
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2874
diff
changeset
|
229 |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
230 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
|
231 if not globbed and default == 'relpath': |
e08e0367ba15
walk: kill util.cmdmatcher and _matcher
Matt Mackall <mpm@selenic.com>
parents:
6566
diff
changeset
|
232 pats = util.expand_glob(pats or []) |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
233 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
|
234 opts.get('include'), opts.get('exclude'), default) |
6578
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6577
diff
changeset
|
235 def badfn(f, msg): |
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6577
diff
changeset
|
236 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
|
237 return False |
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6577
diff
changeset
|
238 m.bad = badfn |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
239 return m |
2882
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2874
diff
changeset
|
240 |
6597
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
241 def matchall(repo): |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
242 return _match.always(repo.root, repo.getcwd()) |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
243 |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
244 def matchfiles(repo, files): |
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
245 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
|
246 |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
247 def findrenames(repo, added=None, removed=None, threshold=0.5): |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
248 '''find renamed files -- yields (before, after, score) tuples''' |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
249 if added is None or removed is None: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
250 added, removed = repo.status()[1:3] |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6739
diff
changeset
|
251 ctx = repo['.'] |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
252 for a in added: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
253 aa = repo.wread(a) |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
254 bestname, bestscore = None, threshold |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
255 for r in removed: |
3971
68a0fa81ad28
cmdutil.py: use contexts in findrenames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3891
diff
changeset
|
256 rr = ctx.filectx(r).data() |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
257 |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
258 # bdiff.blocks() returns blocks of matching lines |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
259 # count the number of bytes in each |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
260 equal = 0 |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
261 alines = mdiff.splitnewlines(aa) |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
262 matches = bdiff.blocks(aa, rr) |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
263 for x1,x2,y1,y2 in matches: |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
264 for line in alines[x1:x2]: |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
265 equal += len(line) |
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
266 |
4472
736e49292809
addremove: comparing two empty files caused ZeroDivisionError
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4380
diff
changeset
|
267 lengths = len(aa) + len(rr) |
736e49292809
addremove: comparing two empty files caused ZeroDivisionError
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4380
diff
changeset
|
268 if lengths: |
736e49292809
addremove: comparing two empty files caused ZeroDivisionError
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4380
diff
changeset
|
269 myscore = equal*2.0 / lengths |
736e49292809
addremove: comparing two empty files caused ZeroDivisionError
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4380
diff
changeset
|
270 if myscore >= bestscore: |
736e49292809
addremove: comparing two empty files caused ZeroDivisionError
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4380
diff
changeset
|
271 bestname, bestscore = r, myscore |
4135
6cb6cfe43c5d
Avoid some false positives for addremove -s
Erling Ellingsen <erlingalf@gmail.com>
parents:
4059
diff
changeset
|
272 if bestname: |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
273 yield bestname, a, bestscore |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
274 |
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4906
diff
changeset
|
275 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
|
276 if dry_run is None: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
277 dry_run = opts.get('dry_run') |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
278 if similarity is None: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
279 similarity = float(opts.get('similarity') or 0) |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
280 add, remove = [], [] |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
281 mapping = {} |
6651
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
282 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
|
283 m = match(repo, pats, opts) |
6586
d3463007d368
walk: return a single value
Matt Mackall <mpm@selenic.com>
parents:
6585
diff
changeset
|
284 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
|
285 target = repo.wjoin(abs) |
6651
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
286 good = True |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
287 try: |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
288 audit_path(abs) |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
289 except: |
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
290 good = False |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
291 rel = m.rel(abs) |
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
292 exact = m.exact(abs) |
6656 | 293 if good and abs not in repo.dirstate: |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
294 add.append(abs) |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
295 mapping[abs] = rel, m.exact(abs) |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
296 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
|
297 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
6651
7f0dd352fb4d
addremove: correctly handle intermediate symlinks
Maxim Dounin <mdounin@mdounin.ru>
parents:
6566
diff
changeset
|
298 if 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
|
299 or (os.path.isdir(target) and not os.path.islink(target))): |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
300 remove.append(abs) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
301 mapping[abs] = rel, exact |
2883
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
302 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
|
303 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2882
diff
changeset
|
304 if not dry_run: |
5487
7a64931e2d76
Fix file-changed-to-dir and dir-to-file commits (issue660).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5248
diff
changeset
|
305 repo.remove(remove) |
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4906
diff
changeset
|
306 repo.add(add) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
307 if similarity > 0: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
308 for old, new, score in findrenames(repo, add, remove, similarity): |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
309 oldrel, oldexact = mapping[old] |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
310 newrel, newexact = mapping[new] |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
311 if repo.ui.verbose or not oldexact or not newexact: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
312 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
|
313 '(%d%% similar)\n') % |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
314 (oldrel, newrel, score * 100)) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
315 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
|
316 repo.copy(old, new) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
317 |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
318 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
|
319 # called with the repo lock held |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
320 # |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
321 # hgsep => pathname that uses "/" to separate directories |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
322 # 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
|
323 cwd = repo.getcwd() |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
324 targets = {} |
5607 | 325 after = opts.get("after") |
326 dryrun = opts.get("dry_run") | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
327 |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
328 def walkpat(pat): |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
329 srcs = [] |
6579
0159b7a36184
walk: pass match object to cmdutil.walk
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
330 m = match(repo, [pat], opts, globbed=True) |
6586
d3463007d368
walk: return a single value
Matt Mackall <mpm@selenic.com>
parents:
6585
diff
changeset
|
331 for abs in repo.walk(m): |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
332 state = repo.dirstate[abs] |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
333 rel = m.rel(abs) |
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
334 exact = m.exact(abs) |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
335 if state in '?r': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
336 if exact and state == '?': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
337 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
|
338 if exact and state == 'r': |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
339 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
|
340 ' remove\n') % rel) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
341 continue |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
342 # abs: hgsep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
343 # rel: ossep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
344 srcs.append((abs, rel, exact)) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
345 return srcs |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
346 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
347 # abssrc: hgsep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
348 # relsrc: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
349 # otarget: ossep |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
350 def copyfile(abssrc, relsrc, otarget, exact): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
351 abstarget = util.canonpath(repo.root, cwd, otarget) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
352 reltarget = repo.pathto(abstarget, cwd) |
5607 | 353 target = repo.wjoin(abstarget) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
354 src = repo.wjoin(abssrc) |
5608 | 355 state = repo.dirstate[abstarget] |
5607 | 356 |
357 # check for collisions | |
358 prevsrc = targets.get(abstarget) | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
359 if prevsrc is not None: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
360 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
|
361 (reltarget, repo.pathto(abssrc, cwd), |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
362 repo.pathto(prevsrc, cwd))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
363 return |
5607 | 364 |
365 # check for overwrites | |
5608 | 366 exists = os.path.exists(target) |
367 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
|
368 if not opts['force']: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
369 ui.warn(_('%s: not overwriting - file exists\n') % |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
370 reltarget) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
371 return |
5607 | 372 |
373 if after: | |
5608 | 374 if not exists: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
375 return |
5608 | 376 elif not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
377 try: |
5608 | 378 if exists: |
379 os.unlink(target) | |
380 targetdir = os.path.dirname(target) or '.' | |
381 if not os.path.isdir(targetdir): | |
382 os.makedirs(targetdir) | |
383 util.copyfile(src, target) | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
384 except IOError, inst: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
385 if inst.errno == errno.ENOENT: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
386 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
|
387 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
388 ui.warn(_('%s: cannot copy - %s\n') % |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
389 (relsrc, inst.strerror)) |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
390 return True # report a failure |
5607 | 391 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
392 if ui.verbose or not exact: |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
393 action = rename and "moving" or "copying" |
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
394 ui.status(_('%s %s to %s\n') % (action, relsrc, reltarget)) |
5608 | 395 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
396 targets[abstarget] = abssrc |
5607 | 397 |
398 # fix up dirstate | |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
399 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
|
400 if abstarget == origsrc: # copying back a copy? |
5608 | 401 if state not in 'mn' and not dryrun: |
402 repo.dirstate.normallookup(abstarget) | |
5604
4b7b21acede0
copy: fix copying back with -A (issue836)
Matt Mackall <mpm@selenic.com>
parents:
5589
diff
changeset
|
403 else: |
7121
b801d6e5dc83
rename: handle renaming to a target marked removed
Matt Mackall <mpm@selenic.com>
parents:
6980
diff
changeset
|
404 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
|
405 if not ui.quiet: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
406 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
|
407 "data will be stored for %s.\n") |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
408 % (repo.pathto(origsrc, cwd), reltarget)) |
7121
b801d6e5dc83
rename: handle renaming to a target marked removed
Matt Mackall <mpm@selenic.com>
parents:
6980
diff
changeset
|
409 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
|
410 repo.add([abstarget]) |
5607 | 411 elif not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
412 repo.copy(origsrc, abstarget) |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
413 |
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
414 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
|
415 repo.remove([abssrc], not after) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
416 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
417 # pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
418 # dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
419 # srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
420 # return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
421 def targetpathfn(pat, dest, srcs): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
422 if os.path.isdir(pat): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
423 abspfx = util.canonpath(repo.root, cwd, pat) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
424 abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
425 if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
426 striplen = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
427 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
428 striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
429 if striplen: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
430 striplen += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
431 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
|
432 elif destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
433 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
434 os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
435 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
436 res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
437 return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
438 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
439 # pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
440 # dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
441 # srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
442 # return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
443 def targetpathafterfn(pat, dest, srcs): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
444 if util.patkind(pat, None)[0]: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
445 # a mercurial pattern |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
446 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
447 os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
448 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
449 abspfx = util.canonpath(repo.root, cwd, pat) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
450 if len(abspfx) < len(srcs[0][0]): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
451 # 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
|
452 # 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
|
453 def evalpath(striplen): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
454 score = 0 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
455 for s in srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
456 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
|
457 if os.path.exists(t): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
458 score += 1 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
459 return score |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
460 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
461 abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
462 striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
463 if striplen: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
464 striplen += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
465 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
|
466 score = evalpath(striplen) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
467 striplen1 = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
468 if striplen1: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
469 striplen1 += len(os.sep) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
470 if evalpath(striplen1) > score: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
471 striplen = striplen1 |
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 util.localpath(p)[striplen:]) |
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 # a file |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
476 if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
477 res = lambda p: os.path.join(dest, |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
478 os.path.basename(util.localpath(p))) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
479 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
480 res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
481 return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
482 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
483 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
484 pats = util.expand_glob(pats) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
485 if not pats: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
486 raise util.Abort(_('no source or destination specified')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
487 if len(pats) == 1: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
488 raise util.Abort(_('no destination specified')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
489 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
|
490 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
|
491 if not destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
492 if len(pats) > 1 or util.patkind(pats[0], None)[0]: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
493 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
|
494 '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
|
495 if util.endswithsep(dest): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
496 raise util.Abort(_('destination %s is not a directory') % dest) |
5607 | 497 |
498 tfn = targetpathfn | |
499 if after: | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
500 tfn = targetpathafterfn |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
501 copylist = [] |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
502 for pat in pats: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
503 srcs = walkpat(pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
504 if not srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
505 continue |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
506 copylist.append((tfn(pat, dest, srcs), srcs)) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
507 if not copylist: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
508 raise util.Abort(_('no files to copy')) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
509 |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
510 errors = 0 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
511 for targetpath, srcs in copylist: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
512 for abssrc, relsrc, exact in srcs: |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
513 if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
514 errors += 1 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
515 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
516 if errors: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
517 ui.warn(_('(consider using --after)\n')) |
5609 | 518 |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
519 return errors |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
520 |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
521 def service(opts, parentfn=None, initfn=None, runfn=None): |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
522 '''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
|
523 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
524 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
|
525 rfd, wfd = os.pipe() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
526 args = sys.argv[:] |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
527 args.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
|
528 # 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
|
529 # changed directory. |
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
|
530 for i in xrange(1,len(args)): |
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
|
531 if args[i].startswith('--cwd='): |
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
|
532 del args[i] |
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
|
533 break |
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
|
534 elif args[i].startswith('--cwd'): |
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
|
535 del args[i:i+2] |
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
|
536 break |
4380
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
537 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
538 args[0], args) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
539 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
|
540 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
|
541 if parentfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
542 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
|
543 else: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
544 os._exit(0) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
545 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
546 if initfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
547 initfn() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
548 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
549 if opts['pid_file']: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
550 fp = open(opts['pid_file'], 'w') |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
551 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
|
552 fp.close() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
553 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 try: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
558 os.setsid() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
559 except AttributeError: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
560 pass |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
561 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
|
562 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
|
563 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
|
564 sys.stderr.flush() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
565 fd = os.open(util.nulldev, os.O_RDWR) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
566 if fd != 0: os.dup2(fd, 0) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
567 if fd != 1: os.dup2(fd, 1) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
568 if fd != 2: os.dup2(fd, 2) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
569 if fd not in (0, 1, 2): os.close(fd) |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
570 |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
571 if runfn: |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
572 return runfn() |
e89f9afc462b
Refactor commands.serve to allow other commands to run as services.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4355
diff
changeset
|
573 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
574 class changeset_printer(object): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
575 '''show changeset information when templating not requested.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
576 |
3876
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
577 def __init__(self, ui, repo, patch, buffered): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
578 self.ui = ui |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
579 self.repo = repo |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
580 self.buffered = buffered |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
581 self.patch = patch |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
582 self.header = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
583 self.hunk = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
584 self.lastheader = None |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
585 |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
586 def flush(self, rev): |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
587 if rev in self.header: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
588 h = self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
589 if h != self.lastheader: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
590 self.lastheader = h |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
591 self.ui.write(h) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
592 del self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
593 if rev in self.hunk: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
594 self.ui.write(self.hunk[rev]) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
595 del self.hunk[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
596 return 1 |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
597 return 0 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
598 |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
599 def show(self, ctx, copies=(), **props): |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
600 if self.buffered: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
601 self.ui.pushbuffer() |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
602 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
|
603 self.hunk[ctx.rev()] = self.ui.popbuffer() |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
604 else: |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
605 self._show(ctx, copies, props) |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
606 |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
607 def _show(self, ctx, copies, props): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
608 '''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
|
609 changenode = ctx.node() |
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
610 rev = ctx.rev() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
611 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
612 if self.ui.quiet: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
613 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
|
614 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
615 |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
616 log = self.repo.changelog |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
617 changes = log.read(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
618 date = util.datestr(changes[2]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
619 extra = changes[5] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
620 branch = extra.get("branch") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
621 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
622 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
|
623 |
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
|
624 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
|
625 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
|
626 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
627 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
|
628 |
4176
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4055
diff
changeset
|
629 # 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
|
630 if branch != 'default': |
3827
3674ca805a5b
log: convert branch names to the local encoding
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3825
diff
changeset
|
631 branch = util.tolocal(branch) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
632 self.ui.write(_("branch: %s\n") % branch) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
633 for tag in self.repo.nodetags(changenode): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
634 self.ui.write(_("tag: %s\n") % tag) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
635 for parent in parents: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
636 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
|
637 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
638 if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
639 self.ui.write(_("manifest: %d:%s\n") % |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
640 (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
641 self.ui.write(_("user: %s\n") % changes[1]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
642 self.ui.write(_("date: %s\n") % date) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
643 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
644 if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
645 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
|
646 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
|
647 files): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
648 if value: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
649 self.ui.write("%-12s %s\n" % (key, " ".join(value))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
650 elif changes[3] and self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
651 self.ui.write(_("files: %s\n") % " ".join(changes[3])) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
652 if copies and self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
653 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
|
654 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
|
655 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
656 if extra and self.ui.debugflag: |
6762 | 657 for key, value in util.sort(extra.items()): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
658 self.ui.write(_("extra: %s=%s\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
659 % (key, value.encode('string_escape'))) |
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 description = changes[4].strip() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
662 if description: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
663 if self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
664 self.ui.write(_("description:\n")) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
665 self.ui.write(description) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
666 self.ui.write("\n\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
667 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
668 self.ui.write(_("summary: %s\n") % |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
669 description.splitlines()[0]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
670 self.ui.write("\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
671 |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
672 self.showpatch(changenode) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
673 |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
674 def showpatch(self, node): |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
675 if self.patch: |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
676 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
|
677 chunks = patch.diff(self.repo, prev, node, match=self.patch, |
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
678 opts=patch.diffopts(self.ui)) |
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
679 for chunk in chunks: |
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
680 self.ui.write(chunk) |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
681 self.ui.write("\n") |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
682 |
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
|
683 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
|
684 """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
|
685 |
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
|
686 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
|
687 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
|
688 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
|
689 """ |
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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 |
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
|
698 |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
699 class changeset_templater(changeset_printer): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
700 '''format changeset information.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
701 |
3876
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
702 def __init__(self, ui, repo, patch, mapfile, buffered): |
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
703 changeset_printer.__init__(self, ui, repo, patch, buffered) |
5976
9f1e6ab76069
templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents:
5915
diff
changeset
|
704 filters = templatefilters.filters.copy() |
4352
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
705 filters['formatnode'] = (ui.debugflag and (lambda x: x) |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
706 or (lambda x: x[:12])) |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
707 self.t = templater.templater(mapfile, filters, |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
708 cache={ |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
709 'parent': '{rev}:{node|formatnode} ', |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
710 'manifest': '{rev}:{node|formatnode}', |
051fb8c2567c
command line templates: add formatnode filter
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4351
diff
changeset
|
711 'filecopy': '{name} ({source})'}) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
712 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
713 def use_template(self, t): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
714 '''set template string to use''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
715 self.t.cache['changeset'] = t |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
716 |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
717 def _show(self, ctx, copies, props): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
718 '''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
|
719 changenode = ctx.node() |
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
720 rev = ctx.rev() |
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
721 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
722 log = self.repo.changelog |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
723 changes = log.read(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
724 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
725 def showlist(name, values, plural=None, **args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
726 '''expand set of values. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
727 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
|
728 values is list of strings or dicts. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
729 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
|
730 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
731 expansion works like this, given name 'foo'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
732 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
733 if values is empty, expand 'no_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
734 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
735 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
|
736 joined by space. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
737 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
738 expand 'start_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
739 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
740 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
|
741 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
|
742 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
743 expand 'end_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
744 ''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
745 if plural: names = plural |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
746 else: names = name + 's' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
747 if not values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
748 noname = 'no_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
749 if noname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
750 yield self.t(noname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
751 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
752 if name not in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
753 if isinstance(values[0], str): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
754 yield ' '.join(values) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
755 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
756 for v in values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
757 yield dict(v, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
758 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
759 startname = 'start_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
760 if startname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
761 yield self.t(startname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
762 vargs = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
763 def one(v, tag=name): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
764 try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
765 vargs.update(v) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
766 except (AttributeError, ValueError): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
767 try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
768 for a, b in v: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
769 vargs[a] = b |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
770 except ValueError: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
771 vargs[name] = v |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
772 return self.t(tag, **vargs) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
773 lastname = 'last_' + name |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
774 if lastname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
775 last = values.pop() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
776 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
777 last = None |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
778 for v in values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
779 yield one(v) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
780 if last is not None: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
781 yield one(last, tag=lastname) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
782 endname = 'end_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
783 if endname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
784 yield self.t(endname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
785 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
786 def showbranches(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
787 branch = changes[5].get("branch") |
4176
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4055
diff
changeset
|
788 if branch != 'default': |
3827
3674ca805a5b
log: convert branch names to the local encoding
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3825
diff
changeset
|
789 branch = util.tolocal(branch) |
3648
2801a3efc7c3
changeset templater: convert some unnecessary yields to returns
Matt Mackall <mpm@selenic.com>
parents:
3645
diff
changeset
|
790 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
|
791 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
792 def showparents(**args): |
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
|
793 parents = [[('rev', p), ('node', hex(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
|
794 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
|
795 return showlist('parent', parents, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
796 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
797 def showtags(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
798 return showlist('tag', self.repo.nodetags(changenode), **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
799 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
800 def showextras(**args): |
6762 | 801 for key, value in util.sort(changes[5].items()): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
802 args = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
803 args.update(dict(key=key, value=value)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
804 yield self.t('extra', **args) |
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 showcopies(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
807 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
|
808 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
|
809 |
5545
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
810 files = [] |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
811 def getfiles(): |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5716
diff
changeset
|
812 if not files: |
5545
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
813 files[:] = self.repo.status( |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
814 log.parents(changenode)[0], changenode)[:3] |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
815 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
|
816 def showfiles(**args): |
db6633f11d59
cmdutil: make "files" list all files, add "file_mods" for modified files
Patrick Mezard <pmezard@gmail.com>
parents:
5545
diff
changeset
|
817 return showlist('file', changes[3], **args) |
db6633f11d59
cmdutil: make "files" list all files, add "file_mods" for modified files
Patrick Mezard <pmezard@gmail.com>
parents:
5545
diff
changeset
|
818 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
|
819 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
|
820 def showadds(**args): |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
821 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
|
822 def showdels(**args): |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
823 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
|
824 def showmanifest(**args): |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
825 args = args.copy() |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
826 args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
827 node=hex(changes[0]))) |
5a124ce4602a
cmdutil: always expose "files_add", "files_del" and "manifest" templater properties
Patrick Mezard <pmezard@gmail.com>
parents:
5487
diff
changeset
|
828 return self.t('manifest', **args) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
829 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
830 defprops = { |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
831 'author': changes[1], |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
832 'branches': showbranches, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
833 'date': changes[2], |
4824
f3f84d5cd268
Strip whitespace from changeset description in changeset_templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4734
diff
changeset
|
834 'desc': changes[4].strip(), |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
835 'file_adds': showadds, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
836 '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
|
837 'file_mods': showmods, |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
838 'files': showfiles, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
839 'file_copies': showcopies, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
840 'manifest': showmanifest, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
841 'node': hex(changenode), |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
842 'parents': showparents, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
843 'rev': rev, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
844 'tags': showtags, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
845 'extras': showextras, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
846 } |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
847 props = props.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
848 props.update(defprops) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
849 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
850 try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
851 if self.ui.debugflag and 'header_debug' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
852 key = 'header_debug' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
853 elif self.ui.quiet and 'header_quiet' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
854 key = 'header_quiet' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
855 elif self.ui.verbose and 'header_verbose' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
856 key = 'header_verbose' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
857 elif 'header' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
858 key = 'header' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
859 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
860 key = '' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
861 if key: |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
862 h = templater.stringify(self.t(key, **props)) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
863 if self.buffered: |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
864 self.header[rev] = h |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
865 else: |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
866 self.ui.write(h) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
867 if self.ui.debugflag and 'changeset_debug' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
868 key = 'changeset_debug' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
869 elif self.ui.quiet and 'changeset_quiet' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
870 key = 'changeset_quiet' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
871 elif self.ui.verbose and 'changeset_verbose' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
872 key = 'changeset_verbose' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
873 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
874 key = 'changeset' |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
875 self.ui.write(templater.stringify(self.t(key, **props))) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
876 self.showpatch(changenode) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
877 except KeyError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
878 raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
879 inst.args[0])) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
880 except SyntaxError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
881 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
|
882 |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
883 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
|
884 """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
|
885 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
886 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
|
887 1. option 'template' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
888 2. option 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
889 3. [ui] setting 'logtemplate' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
890 4. [ui] setting 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
891 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
|
892 regular display via changeset_printer() is done. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
893 """ |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
894 # options |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
895 patch = False |
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
896 if opts.get('patch'): |
6597
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
897 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
|
898 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
899 tmpl = opts.get('template') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
900 mapfile = None |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
901 if tmpl: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
902 tmpl = templater.parsestring(tmpl, quoted=False) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
903 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
904 mapfile = opts.get('style') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
905 # ui settings |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
906 if not mapfile: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
907 tmpl = ui.config('ui', 'logtemplate') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
908 if tmpl: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
909 tmpl = templater.parsestring(tmpl) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
910 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
911 mapfile = ui.config('ui', 'style') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
912 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
913 if tmpl or mapfile: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
914 if mapfile: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
915 if not os.path.split(mapfile)[0]: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
916 mapname = (templater.templatepath('map-cmdline.' + mapfile) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
917 or templater.templatepath(mapfile)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
918 if mapname: mapfile = mapname |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
919 try: |
3876
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
920 t = changeset_templater(ui, repo, patch, mapfile, buffered) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
921 except SyntaxError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
922 raise util.Abort(inst.args[0]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
923 if tmpl: t.use_template(tmpl) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
924 return t |
3876
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
925 return changeset_printer(ui, repo, patch, buffered) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
926 |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
927 def finddate(ui, repo, date): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
928 """Find the tipmost changeset that matches the given date spec""" |
5836
c5c9a022bd9a
Tweak finddate to pass date directly.
mark.williamson@cl.cam.ac.uk
parents:
5829
diff
changeset
|
929 df = util.matchdate(date) |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6739
diff
changeset
|
930 get = util.cachefunc(lambda r: repo[r].changeset()) |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
931 changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None}) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
932 results = {} |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
933 for st, rev, fns in changeiter: |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
934 if st == 'add': |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
935 d = get(rev)[2] |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
936 if df(d[0]): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
937 results[rev] = d |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
938 elif st == 'iter': |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
939 if rev in results: |
6953
63b5f4c73c98
i18n: mark strings for translation in Mercurial
Martin Geisler <mg@daimi.au.dk>
parents:
6762
diff
changeset
|
940 ui.status(_("Found revision %s from %s\n") % |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
941 (rev, util.datestr(results[rev]))) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
942 return str(rev) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
943 |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
944 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
|
945 |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
946 def walkchangerevs(ui, repo, pats, change, opts): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
947 '''Iterate over files and the revs they changed in. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
948 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
949 Callers most commonly need to iterate backwards over the history |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
950 it is interested in. Doing so has awful (quadratic-looking) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
951 performance, so we use iterators in a "windowed" way. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
952 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
953 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
|
954 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
|
955 order (usually backwards) to display it. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
956 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
957 This function returns an (iterator, matchfn) tuple. The iterator |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
958 yields 3-tuples. They will be of one of the following forms: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
959 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
960 "window", incrementing, lastrev: stepping through a window, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
961 positive if walking forwards through revs, last rev in the |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
962 sequence iterated over - use to reset state for the current window |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
963 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
964 "add", rev, fns: out-of-order traversal of the given file names |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
965 fns, which changed during revision rev - use to gather data for |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
966 possible display |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
967 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
968 "iter", rev, None: in-order traversal of the revs earlier iterated |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
969 over with "add" - use to display data''' |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
970 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
971 def increasing_windows(start, end, windowsize=8, sizelimit=512): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
972 if start < end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
973 while start < end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
974 yield start, min(windowsize, end-start) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
975 start += windowsize |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
976 if windowsize < sizelimit: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
977 windowsize *= 2 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
978 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
979 while start > end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
980 yield start, min(windowsize, start-end-1) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
981 start -= windowsize |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
982 if windowsize < sizelimit: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
983 windowsize *= 2 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
984 |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
985 m = match(repo, pats, opts) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
986 follow = opts.get('follow') or opts.get('follow_first') |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
987 |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
988 if not len(repo): |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
989 return [], m |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
990 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
991 if follow: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6739
diff
changeset
|
992 defrange = '%s:0' % repo['.'].rev() |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
993 else: |
6145
154f8be6272b
cmdutil.walkchangerevs: use '-1:0' instead ot 'tip:0'
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6139
diff
changeset
|
994 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
|
995 revs = revrange(repo, opts['rev'] or [defrange]) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
996 wanted = {} |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
997 slowpath = m.anypats() or opts.get('removed') |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
998 fncache = {} |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
999 |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
1000 if not slowpath and not m.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1001 # No files, no patterns. Display all revs. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1002 wanted = dict.fromkeys(revs) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1003 copies = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1004 if not slowpath: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1005 # Only files, no patterns. Check the history of each file. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1006 def filerevgen(filelog, node): |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1007 cl_count = len(repo) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1008 if node is None: |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1009 last = len(filelog) - 1 |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1010 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1011 last = filelog.rev(node) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1012 for i, window in increasing_windows(last, nullrev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1013 revs = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1014 for j in xrange(i - window, i + 1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1015 n = filelog.node(j) |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7319
diff
changeset
|
1016 revs.append((filelog.linkrev(j), |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1017 follow and filelog.renamed(n))) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1018 revs.reverse() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1019 for rev in revs: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1020 # 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
|
1021 # happen while doing "hg log" during a pull or commit |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1022 if rev[0] < cl_count: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1023 yield rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1024 def iterfiles(): |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
1025 for filename in m.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1026 yield filename, None |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1027 for filename_node in copies: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1028 yield filename_node |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1029 minrev, maxrev = min(revs), max(revs) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1030 for file_, node in iterfiles(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1031 filelog = repo.file(file_) |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1032 if not len(filelog): |
6536
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1033 if node is None: |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1034 # 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
|
1035 # 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
|
1036 if follow: |
07cb58b8c843
Improved error message for log --follow
Brendan Cully <brendan@kublai.com>
parents:
7369
diff
changeset
|
1037 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
|
1038 slowpath = True |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1039 break |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1040 else: |
6553
0bb76d168437
remove trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6536
diff
changeset
|
1041 ui.warn(_('%s:%s copy source revision cannot be found!\n') |
6536
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1042 % (file_, short(node))) |
dfdef3d560a8
cmdutil: handle and warn about missing copy revisions
Patrick Mezard <pmezard@gmail.com>
parents:
6258
diff
changeset
|
1043 continue |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1044 for rev, copied in filerevgen(filelog, node): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1045 if rev <= maxrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1046 if rev < minrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1047 break |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1048 fncache.setdefault(rev, []) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1049 fncache[rev].append(file_) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1050 wanted[rev] = 1 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1051 if follow and copied: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1052 copies.append(copied) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1053 if slowpath: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1054 if follow: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1055 raise util.Abort(_('can only follow copies/renames for explicit ' |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1056 'file names')) |
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 # The slow path checks files modified in every changeset. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1059 def changerevgen(): |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
1060 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
|
1061 for j in xrange(i - window, i + 1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1062 yield j, change(j)[3] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1063 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1064 for rev, changefiles in changerevgen(): |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
1065 matches = filter(m, changefiles) |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1066 if matches: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1067 fncache[rev] = matches |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1068 wanted[rev] = 1 |
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 class followfilter: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1071 def __init__(self, onlyfirst=False): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1072 self.startrev = nullrev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1073 self.roots = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1074 self.onlyfirst = onlyfirst |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1075 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1076 def match(self, rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1077 def realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1078 if self.onlyfirst: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1079 return repo.changelog.parentrevs(rev)[0:1] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1080 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1081 return filter(lambda x: x != nullrev, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1082 repo.changelog.parentrevs(rev)) |
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 if self.startrev == nullrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1085 self.startrev = rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1086 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1087 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1088 if rev > self.startrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1089 # forward: all descendants |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1090 if not self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1091 self.roots.append(self.startrev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1092 for parent in realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1093 if parent in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1094 self.roots.append(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1095 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1096 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1097 # backwards: all parents |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1098 if not self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1099 self.roots.extend(realparents(self.startrev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1100 if rev in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1101 self.roots.remove(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1102 self.roots.extend(realparents(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1103 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1104 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1105 return False |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1106 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1107 # 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
|
1108 # 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
|
1109 for rev in opts.get('prune', ()): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1110 rev = repo.changelog.rev(repo.lookup(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1111 ff = followfilter() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1112 stop = min(revs[0], revs[-1]) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1113 for x in xrange(rev, stop-1, -1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1114 if ff.match(x) and x in wanted: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1115 del wanted[x] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1116 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1117 def iterate(): |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
1118 if follow and not m.files(): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1119 ff = followfilter(onlyfirst=opts.get('follow_first')) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1120 def want(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1121 if ff.match(rev) and rev in wanted: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1122 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1123 return False |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1124 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1125 def want(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1126 return rev in wanted |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1127 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1128 for i, window in increasing_windows(0, len(revs)): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1129 yield 'window', revs[0] < revs[-1], revs[-1] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1130 nrevs = [rev for rev in revs[i:i+window] if want(rev)] |
6762 | 1131 for rev in util.sort(list(nrevs)): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1132 fns = fncache.get(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1133 if not fns: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1134 def fns_generator(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1135 for f in change(rev)[3]: |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
1136 if m(f): |
3650
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1137 yield f |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1138 fns = fns_generator() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1139 yield 'add', rev, fns |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1140 for rev in nrevs: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3649
diff
changeset
|
1141 yield 'iter', rev, None |
6580
da2a20d2ba3d
walkchangerev: use new match objects
Matt Mackall <mpm@selenic.com>
parents:
6579
diff
changeset
|
1142 return iterate(), m |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1143 |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1144 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
|
1145 '''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
|
1146 date = opts.get('date') |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
1147 if date: |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
1148 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
|
1149 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
|
1150 |
5829
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1151 # 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
|
1152 # that doesn't support addremove |
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1153 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
|
1154 addremove(repo, pats, opts) |
5829
784073457a0f
cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5797
diff
changeset
|
1155 |
6581
1ae7cb678d24
cmdutil: switch commit to match
Matt Mackall <mpm@selenic.com>
parents:
6580
diff
changeset
|
1156 m = match(repo, pats, opts) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1157 if pats: |
6760
4faaa0535ea7
status: clean up all users for unknown files
Matt Mackall <mpm@selenic.com>
parents:
6750
diff
changeset
|
1158 modified, added, removed = repo.status(match=m)[:3] |
6762 | 1159 files = util.sort(modified + added + removed) |
6980
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1160 |
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1161 def is_dir(f): |
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1162 name = f + '/' |
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1163 i = bisect.bisect(files, name) |
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1164 return i < len(files) and files[i].startswith(name) |
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1165 |
6581
1ae7cb678d24
cmdutil: switch commit to match
Matt Mackall <mpm@selenic.com>
parents:
6580
diff
changeset
|
1166 for f in m.files(): |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1167 if f == '.': |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1168 continue |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1169 if f not in files: |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1170 rf = repo.wjoin(f) |
6112
5ffa962783c4
cmdutil.commit: use relative paths in the error messages
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5976
diff
changeset
|
1171 rel = repo.pathto(f) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1172 try: |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1173 mode = os.lstat(rf)[stat.ST_MODE] |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1174 except OSError: |
6980
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1175 if is_dir(f): # deleted directory ? |
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1176 continue |
6112
5ffa962783c4
cmdutil.commit: use relative paths in the error messages
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5976
diff
changeset
|
1177 raise util.Abort(_("file %s not found!") % rel) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1178 if stat.S_ISDIR(mode): |
6980
2268edff1bec
allow committing a removed directory
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6953
diff
changeset
|
1179 if not is_dir(f): |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1180 raise util.Abort(_("no match under directory %s!") |
6112
5ffa962783c4
cmdutil.commit: use relative paths in the error messages
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5976
diff
changeset
|
1181 % rel) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1182 elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)): |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1183 raise util.Abort(_("can't commit %s: " |
6112
5ffa962783c4
cmdutil.commit: use relative paths in the error messages
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5976
diff
changeset
|
1184 "unsupported file type!") % rel) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1185 elif f not in repo.dirstate: |
6112
5ffa962783c4
cmdutil.commit: use relative paths in the error messages
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5976
diff
changeset
|
1186 raise util.Abort(_("file %s not tracked!") % rel) |
6597
371415a2b959
match: use helpers for cmdutil
Matt Mackall <mpm@selenic.com>
parents:
6586
diff
changeset
|
1187 m = matchfiles(repo, files) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1188 try: |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6597
diff
changeset
|
1189 return commitfunc(ui, repo, message, m, opts) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1190 except ValueError, inst: |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
1191 raise util.Abort(str(inst)) |