Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/cmdutil.py @ 3892:2eec996f2fb9
Fix demandload bits of setup.py py2exe support
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 14 Dec 2006 20:23:25 -0600 |
parents | abaee83ce0a6 |
children | 6b4127c7d52a |
rev | line source |
---|---|
2957 | 1 # cmdutil.py - help for command processing in mercurial |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
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 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
8 from node import * |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
9 from i18n import gettext as _ |
3886
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3885
diff
changeset
|
10 import os, sys, mdiff, util, templater, patch |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
11 |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
12 revrangesep = ':' |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
13 |
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
14 def revpair(repo, revs): |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
15 '''return pair of nodes, given list of revisions. second item can |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
16 be None, meaning use working dir.''' |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
17 |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
18 def revfix(repo, val, defval): |
3822
000d122071b5
fix hg diff -r ''
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3818
diff
changeset
|
19 if not val and val != 0 and defval is not None: |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
20 val = defval |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
21 return repo.lookup(val) |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
22 |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
23 if not revs: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
24 return repo.dirstate.parents()[0], None |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
25 end = None |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
26 if len(revs) == 1: |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
27 if revrangesep in revs[0]: |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
28 start, end = revs[0].split(revrangesep, 1) |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
29 start = revfix(repo, start, 0) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
30 end = revfix(repo, end, repo.changelog.count() - 1) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
31 else: |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
32 start = revfix(repo, revs[0], None) |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
33 elif len(revs) == 2: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
34 if revrangesep in revs[0] or revrangesep in revs[1]: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
35 raise util.Abort(_('too many revisions specified')) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
36 start = revfix(repo, revs[0], None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
37 end = revfix(repo, revs[1], None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
38 else: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
39 raise util.Abort(_('too many revisions specified')) |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
40 return start, end |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
41 |
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
42 def revrange(repo, revs): |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
43 """Yield revision as strings from a list of revision specifications.""" |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
44 |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
45 def revfix(repo, val, defval): |
3718
7db88b094b14
fix hg log -r ''
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3707
diff
changeset
|
46 if not val and val != 0 and defval is not None: |
3556
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
47 return defval |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
48 return repo.changelog.rev(repo.lookup(val)) |
cf0f8d9256c7
simplify revrange and revpair
Matt Mackall <mpm@selenic.com>
parents:
3555
diff
changeset
|
49 |
3557
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3556
diff
changeset
|
50 seen, l = {}, [] |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
51 for spec in revs: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
52 if revrangesep in spec: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
53 start, end = spec.split(revrangesep, 1) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
54 start = revfix(repo, start, 0) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
55 end = revfix(repo, end, repo.changelog.count() - 1) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
56 step = start > end and -1 or 1 |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
57 for rev in xrange(start, end+step, step): |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
58 if rev in seen: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
59 continue |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
60 seen[rev] = 1 |
3557
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3556
diff
changeset
|
61 l.append(rev) |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
62 else: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
63 rev = revfix(repo, spec, None) |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
64 if rev in seen: |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
65 continue |
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
66 seen[rev] = 1 |
3557
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3556
diff
changeset
|
67 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:
3556
diff
changeset
|
68 |
68341c06bc61
Make revrange return a list of ints so that callers don't have to convert
Matt Mackall <mpm@selenic.com>
parents:
3556
diff
changeset
|
69 return l |
3087
eeaf9bcdfa25
Move revision parsing into cmdutil.
Brendan Cully <brendan@kublai.com>
parents:
3069
diff
changeset
|
70 |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
71 def make_filename(repo, pat, node, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
72 total=None, seqno=None, revwidth=None, pathname=None): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
73 node_expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
74 'H': lambda: hex(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
75 'R': lambda: str(repo.changelog.rev(node)), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
76 'h': lambda: short(node), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
77 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
78 expander = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
79 '%': lambda: '%', |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
80 'b': lambda: os.path.basename(repo.root), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
81 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
82 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
83 try: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
84 if node: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
85 expander.update(node_expander) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
86 if node and revwidth is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
87 expander['r'] = (lambda: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
88 str(repo.changelog.rev(node)).zfill(revwidth)) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
89 if total is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
90 expander['N'] = lambda: str(total) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
91 if seqno is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
92 expander['n'] = lambda: str(seqno) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
93 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:
3664
diff
changeset
|
94 expander['n'] = lambda: str(seqno).zfill(len(str(total))) |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
95 if pathname is not None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
96 expander['s'] = lambda: os.path.basename(pathname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
97 expander['d'] = lambda: os.path.dirname(pathname) or '.' |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
98 expander['p'] = lambda: pathname |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
99 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
100 newname = [] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
101 patlen = len(pat) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
102 i = 0 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
103 while i < patlen: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
104 c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
105 if c == '%': |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
106 i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
107 c = pat[i] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
108 c = expander[c]() |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
109 newname.append(c) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
110 i += 1 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
111 return ''.join(newname) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
112 except KeyError, inst: |
3069
bc3fe3b5b785
Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2958
diff
changeset
|
113 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
|
114 inst.args[0]) |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
115 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
116 def make_file(repo, pat, node=None, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
117 total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
118 if not pat or pat == '-': |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
119 return 'w' in mode and sys.stdout or sys.stdin |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
120 if hasattr(pat, 'write') and 'w' in mode: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
121 return pat |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
122 if hasattr(pat, 'read') and 'r' in mode: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
123 return pat |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
124 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
|
125 pathname), |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
126 mode) |
2881
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
127 |
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
128 def matchpats(repo, pats=[], opts={}, head=''): |
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
129 cwd = repo.getcwd() |
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
130 if not pats and cwd: |
2884
bd29a3067b97
cmdutil.matchpats: allow include/exclude to be optional.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2883
diff
changeset
|
131 opts['include'] = [os.path.join(cwd, i) |
bd29a3067b97
cmdutil.matchpats: allow include/exclude to be optional.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2883
diff
changeset
|
132 for i in opts.get('include', [])] |
bd29a3067b97
cmdutil.matchpats: allow include/exclude to be optional.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2883
diff
changeset
|
133 opts['exclude'] = [os.path.join(cwd, x) |
bd29a3067b97
cmdutil.matchpats: allow include/exclude to be optional.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2883
diff
changeset
|
134 for x in opts.get('exclude', [])] |
2881
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
135 cwd = '' |
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
136 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
137 opts.get('exclude'), head) |
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
138 |
3559 | 139 def walk(repo, pats=[], opts={}, node=None, head='', badmatch=None): |
2881
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2873
diff
changeset
|
140 files, matchfn, anypats = matchpats(repo, pats, opts, head) |
3562
730ca93ed788
convert dict(zip(x,x)) to dict.fromkeys(x)
Matt Mackall <mpm@selenic.com>
parents:
3559
diff
changeset
|
141 exact = dict.fromkeys(files) |
3559 | 142 for src, fn in repo.walk(node=node, files=files, match=matchfn, |
143 badmatch=badmatch): | |
144 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
2882
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
145 |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
146 def findrenames(repo, added=None, removed=None, threshold=0.5): |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
147 if added is None or removed is None: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
148 added, removed = repo.status()[1:3] |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
149 changes = repo.changelog.read(repo.dirstate.parents()[0]) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
150 mf = repo.manifest.read(changes[0]) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
151 for a in added: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
152 aa = repo.wread(a) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
153 bestscore, bestname = None, None |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
154 for r in removed: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
155 rr = repo.file(r).read(mf[r]) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
156 delta = mdiff.textdiff(aa, rr) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
157 if len(delta) < len(aa): |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
158 myscore = 1.0 - (float(len(delta)) / len(aa)) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
159 if bestscore is None or myscore > bestscore: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
160 bestscore, bestname = myscore, r |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
161 if bestname and bestscore >= threshold: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
162 yield bestname, a, bestscore |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
163 |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
164 def addremove(repo, pats=[], opts={}, wlock=None, dry_run=None, |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
165 similarity=None): |
2882
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
166 if dry_run is None: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
167 dry_run = opts.get('dry_run') |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
168 if similarity is None: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
169 similarity = float(opts.get('similarity') or 0) |
2882
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
170 add, remove = [], [] |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
171 mapping = {} |
2882
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
172 for src, abs, rel, exact in walk(repo, pats, opts): |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
173 if src == 'f' and repo.dirstate.state(abs) == '?': |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
174 add.append(abs) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
175 mapping[abs] = rel, exact |
2882
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
176 if repo.ui.verbose or not exact: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
177 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
178 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
179 remove.append(abs) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
180 mapping[abs] = rel, exact |
2882
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
181 if repo.ui.verbose or not exact: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
182 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:
2881
diff
changeset
|
183 if not dry_run: |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
184 repo.add(add, wlock=wlock) |
c2932ad5476a
move commands.addremove_lock to cmdutil.addremove
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2881
diff
changeset
|
185 repo.remove(remove, wlock=wlock) |
2958
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
186 if similarity > 0: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
187 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
|
188 oldrel, oldexact = mapping[old] |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
189 newrel, newexact = mapping[new] |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
190 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
|
191 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
|
192 '(%d%% similar)\n') % |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
193 (oldrel, newrel, score * 100)) |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
194 if not dry_run: |
ff3ea21a981a
addremove: add -s/--similarity option
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2957
diff
changeset
|
195 repo.copy(old, new, wlock=wlock) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
196 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
197 class changeset_printer(object): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
198 '''show changeset information when templating not requested.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
199 |
3885
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
200 def __init__(self, ui, repo, patch, buffered): |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
201 self.ui = ui |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
202 self.repo = repo |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
203 self.buffered = buffered |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
204 self.patch = patch |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
205 self.header = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
206 self.hunk = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
207 self.lastheader = None |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
208 |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
209 def flush(self, rev): |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
210 if rev in self.header: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
211 h = self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
212 if h != self.lastheader: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
213 self.lastheader = h |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
214 self.ui.write(h) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
215 del self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
216 if rev in self.hunk: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
217 self.ui.write(self.hunk[rev]) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
218 del self.hunk[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
219 return 1 |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
220 return 0 |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
221 |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
222 def show(self, rev=0, changenode=None, copies=None, **props): |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
223 if self.buffered: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
224 self.ui.pushbuffer() |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
225 self._show(rev, changenode, copies, props) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
226 self.hunk[rev] = self.ui.popbuffer() |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
227 else: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
228 self._show(rev, changenode, copies, props) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
229 |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
230 def _show(self, rev, changenode, copies, props): |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
231 '''show a single changeset or file revision''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
232 log = self.repo.changelog |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
233 if changenode is None: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
234 changenode = log.node(rev) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
235 elif not rev: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
236 rev = log.rev(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
237 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
238 if self.ui.quiet: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
239 self.ui.write("%d:%s\n" % (rev, short(changenode))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
240 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
241 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
242 changes = log.read(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
243 date = util.datestr(changes[2]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
244 extra = changes[5] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
245 branch = extra.get("branch") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
246 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
247 hexfunc = self.ui.debugflag and hex or short |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
248 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
249 parents = log.parentrevs(rev) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
250 if not self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
251 if parents[1] == nullrev: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
252 if parents[0] >= rev - 1: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
253 parents = [] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
254 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
255 parents = [parents[0]] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
256 parents = [(p, hexfunc(log.node(p))) for p in parents] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
257 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
258 self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
259 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
260 if branch: |
3824
3674ca805a5b
log: convert branch names to the local encoding
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3822
diff
changeset
|
261 branch = util.tolocal(branch) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
262 self.ui.write(_("branch: %s\n") % branch) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
263 for tag in self.repo.nodetags(changenode): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
264 self.ui.write(_("tag: %s\n") % tag) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
265 for parent in parents: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
266 self.ui.write(_("parent: %d:%s\n") % parent) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
267 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
268 if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
269 self.ui.write(_("manifest: %d:%s\n") % |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
270 (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
271 self.ui.write(_("user: %s\n") % changes[1]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
272 self.ui.write(_("date: %s\n") % date) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
273 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
274 if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
275 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
276 for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
277 files): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
278 if value: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
279 self.ui.write("%-12s %s\n" % (key, " ".join(value))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
280 elif changes[3] and self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
281 self.ui.write(_("files: %s\n") % " ".join(changes[3])) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
282 if copies and self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
283 copies = ['%s (%s)' % c for c in copies] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
284 self.ui.write(_("copies: %s\n") % ' '.join(copies)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
285 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
286 if extra and self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
287 extraitems = extra.items() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
288 extraitems.sort() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
289 for key, value in extraitems: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
290 self.ui.write(_("extra: %s=%s\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
291 % (key, value.encode('string_escape'))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
292 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
293 description = changes[4].strip() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
294 if description: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
295 if self.ui.verbose: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
296 self.ui.write(_("description:\n")) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
297 self.ui.write(description) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
298 self.ui.write("\n\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
299 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
300 self.ui.write(_("summary: %s\n") % |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
301 description.splitlines()[0]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
302 self.ui.write("\n") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
303 |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
304 self.showpatch(changenode) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
305 |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
306 def showpatch(self, node): |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
307 if self.patch: |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
308 prev = self.repo.changelog.parents(node)[0] |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3824
diff
changeset
|
309 patch.diff(self.repo, prev, node, match=self.patch, fp=self.ui) |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
310 self.ui.write("\n") |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
311 |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
312 class changeset_templater(changeset_printer): |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
313 '''format changeset information.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
314 |
3885
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
315 def __init__(self, ui, repo, patch, mapfile, buffered): |
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
316 changeset_printer.__init__(self, ui, repo, patch, buffered) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
317 self.t = templater.templater(mapfile, templater.common_filters, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
318 cache={'parent': '{rev}:{node|short} ', |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
319 'manifest': '{rev}:{node|short}', |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
320 'filecopy': '{name} ({source})'}) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
321 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
322 def use_template(self, t): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
323 '''set template string to use''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
324 self.t.cache['changeset'] = t |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
325 |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
326 def _show(self, rev, changenode, copies, props): |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
327 '''show a single changeset or file revision''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
328 log = self.repo.changelog |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
329 if changenode is None: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
330 changenode = log.node(rev) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
331 elif not rev: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
332 rev = log.rev(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
333 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
334 changes = log.read(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
335 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
336 def showlist(name, values, plural=None, **args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
337 '''expand set of values. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
338 name is name of key in template map. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
339 values is list of strings or dicts. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
340 plural is plural of name, if not simply name + 's'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
341 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
342 expansion works like this, given name 'foo'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
343 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
344 if values is empty, expand 'no_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
345 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
346 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:
3562
diff
changeset
|
347 joined by space. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
348 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
349 expand 'start_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
350 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
351 for each value, expand 'foo'. if 'last_foo' in template |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
352 map, expand it instead of 'foo' for last key. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
353 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
354 expand 'end_foos'. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
355 ''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
356 if plural: names = plural |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
357 else: names = name + 's' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
358 if not values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
359 noname = 'no_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
360 if noname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
361 yield self.t(noname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
362 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
363 if name not in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
364 if isinstance(values[0], str): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
365 yield ' '.join(values) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
366 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
367 for v in values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
368 yield dict(v, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
369 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
370 startname = 'start_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
371 if startname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
372 yield self.t(startname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
373 vargs = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
374 def one(v, tag=name): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
375 try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
376 vargs.update(v) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
377 except (AttributeError, ValueError): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
378 try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
379 for a, b in v: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
380 vargs[a] = b |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
381 except ValueError: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
382 vargs[name] = v |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
383 return self.t(tag, **vargs) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
384 lastname = 'last_' + name |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
385 if lastname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
386 last = values.pop() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
387 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
388 last = None |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
389 for v in values: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
390 yield one(v) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
391 if last is not None: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
392 yield one(last, tag=lastname) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
393 endname = 'end_' + names |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
394 if endname in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
395 yield self.t(endname, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
396 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
397 def showbranches(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
398 branch = changes[5].get("branch") |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
399 if branch: |
3824
3674ca805a5b
log: convert branch names to the local encoding
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3822
diff
changeset
|
400 branch = util.tolocal(branch) |
3655
2801a3efc7c3
changeset templater: convert some unnecessary yields to returns
Matt Mackall <mpm@selenic.com>
parents:
3648
diff
changeset
|
401 return showlist('branch', [branch], plural='branches', **args) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
402 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
403 def showparents(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
404 parents = [[('rev', log.rev(p)), ('node', hex(p))] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
405 for p in log.parents(changenode) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
406 if self.ui.debugflag or p != nullid] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
407 if (not self.ui.debugflag and len(parents) == 1 and |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
408 parents[0][0][1] == rev - 1): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
409 return |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
410 return showlist('parent', parents, **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
411 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
412 def showtags(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
413 return showlist('tag', self.repo.nodetags(changenode), **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
414 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
415 def showextras(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
416 extras = changes[5].items() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
417 extras.sort() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
418 for key, value in extras: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
419 args = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
420 args.update(dict(key=key, value=value)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
421 yield self.t('extra', **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
422 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
423 def showcopies(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
424 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:
3562
diff
changeset
|
425 return showlist('file_copy', c, plural='file_copies', **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
426 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
427 if self.ui.debugflag: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
428 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
429 def showfiles(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
430 return showlist('file', files[0], **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
431 def showadds(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
432 return showlist('file_add', files[1], **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
433 def showdels(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
434 return showlist('file_del', files[2], **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
435 def showmanifest(**args): |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
436 args = args.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
437 args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
438 node=hex(changes[0]))) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
439 return self.t('manifest', **args) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
440 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
441 def showfiles(**args): |
3655
2801a3efc7c3
changeset templater: convert some unnecessary yields to returns
Matt Mackall <mpm@selenic.com>
parents:
3648
diff
changeset
|
442 return showlist('file', changes[3], **args) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
443 showadds = '' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
444 showdels = '' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
445 showmanifest = '' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
446 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
447 defprops = { |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
448 'author': changes[1], |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
449 'branches': showbranches, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
450 'date': changes[2], |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
451 'desc': changes[4], |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
452 'file_adds': showadds, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
453 'file_dels': showdels, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
454 'files': showfiles, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
455 'file_copies': showcopies, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
456 'manifest': showmanifest, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
457 'node': hex(changenode), |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
458 'parents': showparents, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
459 'rev': rev, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
460 'tags': showtags, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
461 'extras': showextras, |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
462 } |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
463 props = props.copy() |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
464 props.update(defprops) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
465 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
466 try: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
467 if self.ui.debugflag and 'header_debug' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
468 key = 'header_debug' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
469 elif self.ui.quiet and 'header_quiet' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
470 key = 'header_quiet' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
471 elif self.ui.verbose and 'header_verbose' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
472 key = 'header_verbose' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
473 elif 'header' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
474 key = 'header' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
475 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
476 key = '' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
477 if key: |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
478 h = templater.stringify(self.t(key, **props)) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
479 if self.buffered: |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
480 self.header[rev] = h |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
481 else: |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
482 self.ui.write(h) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
483 if self.ui.debugflag and 'changeset_debug' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
484 key = 'changeset_debug' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
485 elif self.ui.quiet and 'changeset_quiet' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
486 key = 'changeset_quiet' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
487 elif self.ui.verbose and 'changeset_verbose' in self.t: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
488 key = 'changeset_verbose' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
489 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
490 key = 'changeset' |
3648
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
491 self.ui.write(templater.stringify(self.t(key, **props))) |
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3646
diff
changeset
|
492 self.showpatch(changenode) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
493 except KeyError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
494 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:
3562
diff
changeset
|
495 inst.args[0])) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
496 except SyntaxError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
497 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:
3562
diff
changeset
|
498 |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3824
diff
changeset
|
499 def show_changeset(ui, repo, opts, buffered=False, matchfn=False): |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
500 """show one changeset using template or regular display. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
501 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
502 Display format will be the first non-empty hit of: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
503 1. option 'template' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
504 2. option 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
505 3. [ui] setting 'logtemplate' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
506 4. [ui] setting 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
507 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:
3562
diff
changeset
|
508 regular display via changeset_printer() is done. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
509 """ |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
510 # options |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3824
diff
changeset
|
511 patch = False |
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3824
diff
changeset
|
512 if opts.get('patch'): |
3838
dec4eba7ccad
Use util.always instead of creating a new lambda function in show_changeset
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3837
diff
changeset
|
513 patch = matchfn or util.always |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3824
diff
changeset
|
514 |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
515 tmpl = opts.get('template') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
516 mapfile = None |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
517 if tmpl: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
518 tmpl = templater.parsestring(tmpl, quoted=False) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
519 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
520 mapfile = opts.get('style') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
521 # ui settings |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
522 if not mapfile: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
523 tmpl = ui.config('ui', 'logtemplate') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
524 if tmpl: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
525 tmpl = templater.parsestring(tmpl) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
526 else: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
527 mapfile = ui.config('ui', 'style') |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
528 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
529 if tmpl or mapfile: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
530 if mapfile: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
531 if not os.path.split(mapfile)[0]: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
532 mapname = (templater.templatepath('map-cmdline.' + mapfile) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
533 or templater.templatepath(mapfile)) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
534 if mapname: mapfile = mapname |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
535 try: |
3885
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
536 t = changeset_templater(ui, repo, patch, mapfile, buffered) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
537 except SyntaxError, inst: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
538 raise util.Abort(inst.args[0]) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
539 if tmpl: t.use_template(tmpl) |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
540 return t |
3885
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3838
diff
changeset
|
541 return changeset_printer(ui, repo, patch, buffered) |
3646
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3562
diff
changeset
|
542 |
3818
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
543 def finddate(ui, repo, date): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
544 """Find the tipmost changeset that matches the given date spec""" |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
545 df = util.matchdate(date + " to " + date) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
546 get = util.cachefunc(lambda r: repo.changectx(r).changeset()) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
547 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
|
548 results = {} |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
549 for st, rev, fns in changeiter: |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
550 if st == 'add': |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
551 d = get(rev)[2] |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
552 if df(d[0]): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
553 results[rev] = d |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
554 elif st == 'iter': |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
555 if rev in results: |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
556 ui.status("Found revision %s from %s\n" % |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
557 (rev, util.datestr(results[rev]))) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
558 return str(rev) |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
559 |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
560 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
|
561 |
3657
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
562 def walkchangerevs(ui, repo, pats, change, opts): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
563 '''Iterate over files and the revs they changed in. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
564 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
565 Callers most commonly need to iterate backwards over the history |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
566 it is interested in. Doing so has awful (quadratic-looking) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
567 performance, so we use iterators in a "windowed" way. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
568 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
569 We walk a window of revisions in the desired order. Within the |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
570 window, we first walk forwards to gather data, then in the desired |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
571 order (usually backwards) to display it. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
572 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
573 This function returns an (iterator, matchfn) tuple. The iterator |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
574 yields 3-tuples. They will be of one of the following forms: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
575 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
576 "window", incrementing, lastrev: stepping through a window, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
577 positive if walking forwards through revs, last rev in the |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
578 sequence iterated over - use to reset state for the current window |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
579 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
580 "add", rev, fns: out-of-order traversal of the given file names |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
581 fns, which changed during revision rev - use to gather data for |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
582 possible display |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
583 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
584 "iter", rev, None: in-order traversal of the revs earlier iterated |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
585 over with "add" - use to display data''' |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
586 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
587 def increasing_windows(start, end, windowsize=8, sizelimit=512): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
588 if start < end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
589 while start < end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
590 yield start, min(windowsize, end-start) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
591 start += windowsize |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
592 if windowsize < sizelimit: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
593 windowsize *= 2 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
594 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
595 while start > end: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
596 yield start, min(windowsize, start-end-1) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
597 start -= windowsize |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
598 if windowsize < sizelimit: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
599 windowsize *= 2 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
600 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
601 files, matchfn, anypats = matchpats(repo, pats, opts) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
602 follow = opts.get('follow') or opts.get('follow_first') |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
603 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
604 if repo.changelog.count() == 0: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
605 return [], matchfn |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
606 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
607 if follow: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
608 defrange = '%s:0' % repo.changectx().rev() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
609 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
610 defrange = 'tip:0' |
3707
67f44b825784
Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3673
diff
changeset
|
611 revs = revrange(repo, opts['rev'] or [defrange]) |
3657
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
612 wanted = {} |
3664 | 613 slowpath = anypats or opts.get('removed') |
3657
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
614 fncache = {} |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
615 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
616 if not slowpath and not files: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
617 # No files, no patterns. Display all revs. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
618 wanted = dict.fromkeys(revs) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
619 copies = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
620 if not slowpath: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
621 # Only files, no patterns. Check the history of each file. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
622 def filerevgen(filelog, node): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
623 cl_count = repo.changelog.count() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
624 if node is None: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
625 last = filelog.count() - 1 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
626 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
627 last = filelog.rev(node) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
628 for i, window in increasing_windows(last, nullrev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
629 revs = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
630 for j in xrange(i - window, i + 1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
631 n = filelog.node(j) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
632 revs.append((filelog.linkrev(n), |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
633 follow and filelog.renamed(n))) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
634 revs.reverse() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
635 for rev in revs: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
636 # only yield rev for which we have the changelog, it can |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
637 # happen while doing "hg log" during a pull or commit |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
638 if rev[0] < cl_count: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
639 yield rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
640 def iterfiles(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
641 for filename in files: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
642 yield filename, None |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
643 for filename_node in copies: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
644 yield filename_node |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
645 minrev, maxrev = min(revs), max(revs) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
646 for file_, node in iterfiles(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
647 filelog = repo.file(file_) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
648 # A zero count may be a directory or deleted file, so |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
649 # try to find matching entries on the slow path. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
650 if filelog.count() == 0: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
651 slowpath = True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
652 break |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
653 for rev, copied in filerevgen(filelog, node): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
654 if rev <= maxrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
655 if rev < minrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
656 break |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
657 fncache.setdefault(rev, []) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
658 fncache[rev].append(file_) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
659 wanted[rev] = 1 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
660 if follow and copied: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
661 copies.append(copied) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
662 if slowpath: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
663 if follow: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
664 raise util.Abort(_('can only follow copies/renames for explicit ' |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
665 'file names')) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
666 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
667 # The slow path checks files modified in every changeset. |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
668 def changerevgen(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
669 for i, window in increasing_windows(repo.changelog.count()-1, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
670 nullrev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
671 for j in xrange(i - window, i + 1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
672 yield j, change(j)[3] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
673 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
674 for rev, changefiles in changerevgen(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
675 matches = filter(matchfn, changefiles) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
676 if matches: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
677 fncache[rev] = matches |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
678 wanted[rev] = 1 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
679 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
680 class followfilter: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
681 def __init__(self, onlyfirst=False): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
682 self.startrev = nullrev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
683 self.roots = [] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
684 self.onlyfirst = onlyfirst |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
685 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
686 def match(self, rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
687 def realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
688 if self.onlyfirst: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
689 return repo.changelog.parentrevs(rev)[0:1] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
690 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
691 return filter(lambda x: x != nullrev, |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
692 repo.changelog.parentrevs(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
693 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
694 if self.startrev == nullrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
695 self.startrev = rev |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
696 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
697 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
698 if rev > self.startrev: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
699 # forward: all descendants |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
700 if not self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
701 self.roots.append(self.startrev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
702 for parent in realparents(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
703 if parent in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
704 self.roots.append(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
705 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
706 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
707 # backwards: all parents |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
708 if not self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
709 self.roots.extend(realparents(self.startrev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
710 if rev in self.roots: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
711 self.roots.remove(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
712 self.roots.extend(realparents(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
713 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
714 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
715 return False |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
716 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
717 # 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:
3656
diff
changeset
|
718 # is descending and the prune args are all within that range |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
719 for rev in opts.get('prune', ()): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
720 rev = repo.changelog.rev(repo.lookup(rev)) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
721 ff = followfilter() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
722 stop = min(revs[0], revs[-1]) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
723 for x in xrange(rev, stop-1, -1): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
724 if ff.match(x) and x in wanted: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
725 del wanted[x] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
726 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
727 def iterate(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
728 if follow and not files: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
729 ff = followfilter(onlyfirst=opts.get('follow_first')) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
730 def want(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
731 if ff.match(rev) and rev in wanted: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
732 return True |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
733 return False |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
734 else: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
735 def want(rev): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
736 return rev in wanted |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
737 |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
738 for i, window in increasing_windows(0, len(revs)): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
739 yield 'window', revs[0] < revs[-1], revs[-1] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
740 nrevs = [rev for rev in revs[i:i+window] if want(rev)] |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
741 srevs = list(nrevs) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
742 srevs.sort() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
743 for rev in srevs: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
744 fns = fncache.get(rev) |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
745 if not fns: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
746 def fns_generator(): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
747 for f in change(rev)[3]: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
748 if matchfn(f): |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
749 yield f |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
750 fns = fns_generator() |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
751 yield 'add', rev, fns |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
752 for rev in nrevs: |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
753 yield 'iter', rev, None |
731e739b8659
move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3656
diff
changeset
|
754 return iterate(), matchfn |