##// END OF EJS Templates
templatekw: change {file_copies} behaviour, add {file_copies_switch}...
Patrick Mezard -
r10060:f780b109 default
parent child Browse files
Show More
@@ -651,7 +651,7 b' class changeset_printer(object):'
651 651 return 1
652 652 return 0
653 653
654 def show(self, ctx, copies=(), **props):
654 def show(self, ctx, copies=None, **props):
655 655 if self.buffered:
656 656 self.ui.pushbuffer()
657 657 self._show(ctx, copies, props)
@@ -10,7 +10,7 b' from lock import release'
10 10 from i18n import _, gettext
11 11 import os, re, sys, difflib, time, tempfile
12 12 import hg, util, revlog, bundlerepo, extensions, copies, error
13 import patch, help, mdiff, url, encoding
13 import patch, help, mdiff, url, encoding, templatekw
14 14 import archival, changegroup, cmdutil, sshserver, hbisect
15 15 from hgweb import server
16 16 import merge as merge_
@@ -2018,34 +2018,9 b' def log(ui, repo, *pats, **opts):'
2018 2018 limit = cmdutil.loglimit(opts)
2019 2019 count = 0
2020 2020
2021 endrev = None
2021 2022 if opts.get('copies') and opts.get('rev'):
2022 2023 endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
2023 else:
2024 endrev = len(repo)
2025 rcache = {}
2026 def getrenamed(fn, rev):
2027 '''looks up all renames for a file (up to endrev) the first
2028 time the file is given. It indexes on the changerev and only
2029 parses the manifest if linkrev != changerev.
2030 Returns rename info for fn at changerev rev.'''
2031 if fn not in rcache:
2032 rcache[fn] = {}
2033 fl = repo.file(fn)
2034 for i in fl:
2035 lr = fl.linkrev(i)
2036 renamed = fl.renamed(fl.node(i))
2037 rcache[fn][lr] = renamed
2038 if lr >= endrev:
2039 break
2040 if rev in rcache[fn]:
2041 return rcache[fn][rev]
2042
2043 # If linkrev != rev (i.e. rev not found in rcache) fallback to
2044 # filectx logic.
2045 try:
2046 return repo[rev][fn].renamed()
2047 except error.LookupError:
2048 return None
2049 2024
2050 2025 df = False
2051 2026 if opts["date"]:
@@ -2075,8 +2050,10 b' def log(ui, repo, *pats, **opts):'
2075 2050 else:
2076 2051 return
2077 2052
2078 copies = []
2053 copies = None
2079 2054 if opts.get('copies') and rev:
2055 copies = []
2056 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
2080 2057 for fn in ctx.files():
2081 2058 rename = getrenamed(fn, rev)
2082 2059 if rename:
@@ -6,7 +6,7 b''
6 6 # GNU General Public License version 2, incorporated herein by reference.
7 7
8 8 from node import hex
9 import encoding, patch, util
9 import encoding, patch, util, error
10 10
11 11 def showlist(templ, name, values, plural=None, **args):
12 12 '''expand set of values.
@@ -108,6 +108,38 b' def getlatesttags(repo, ctx, cache):'
108 108 latesttags[rev] = pdate, pdist + 1, ptag
109 109 return latesttags[rev]
110 110
111 def getrenamedfn(repo, endrev=None):
112 rcache = {}
113 if endrev is None:
114 endrev = len(repo)
115
116 def getrenamed(fn, rev):
117 '''looks up all renames for a file (up to endrev) the first
118 time the file is given. It indexes on the changerev and only
119 parses the manifest if linkrev != changerev.
120 Returns rename info for fn at changerev rev.'''
121 if fn not in rcache:
122 rcache[fn] = {}
123 fl = repo.file(fn)
124 for i in fl:
125 lr = fl.linkrev(i)
126 renamed = fl.renamed(fl.node(i))
127 rcache[fn][lr] = renamed
128 if lr >= endrev:
129 break
130 if rev in rcache[fn]:
131 return rcache[fn][rev]
132
133 # If linkrev != rev (i.e. rev not found in rcache) fallback to
134 # filectx logic.
135 try:
136 return repo[rev][fn].renamed()
137 except error.LookupError:
138 return None
139
140 return getrenamed
141
142
111 143 def showauthor(repo, ctx, templ, **args):
112 144 return ctx.user()
113 145
@@ -141,8 +173,27 b' def showextras(repo, ctx, templ, **args)'
141 173 def showfileadds(repo, ctx, templ, revcache, **args):
142 174 return showlist(templ, 'file_add', getfiles(repo, ctx, revcache)[1], **args)
143 175
144 def showfilecopies(repo, ctx, templ, revcache, **args):
145 c = [{'name': x[0], 'source': x[1]} for x in revcache['copies']]
176 def showfilecopies(repo, ctx, templ, cache, revcache, **args):
177 copies = revcache.get('copies')
178 if copies is None:
179 if 'getrenamed' not in cache:
180 cache['getrenamed'] = getrenamedfn(repo)
181 copies = []
182 getrenamed = cache['getrenamed']
183 for fn in ctx.files():
184 rename = getrenamed(fn, ctx.rev())
185 if rename:
186 copies.append((fn, rename[0]))
187
188 c = [{'name': x[0], 'source': x[1]} for x in copies]
189 return showlist(templ, 'file_copy', c, plural='file_copies', **args)
190
191 # showfilecopiesswitch() displays file copies only if copy records are
192 # provided before calling the templater, usually with a --copies
193 # command line switch.
194 def showfilecopiesswitch(repo, ctx, templ, cache, revcache, **args):
195 copies = revcache.get('copies') or []
196 c = [{'name': x[0], 'source': x[1]} for x in copies]
146 197 return showlist(templ, 'file_copy', c, plural='file_copies', **args)
147 198
148 199 def showfiledels(repo, ctx, templ, revcache, **args):
@@ -184,6 +235,7 b' keywords = {'
184 235 'extras': showextras,
185 236 'file_adds': showfileadds,
186 237 'file_copies': showfilecopies,
238 'file_copies_switch': showfilecopiesswitch,
187 239 'file_dels': showfiledels,
188 240 'file_mods': showfilemods,
189 241 'files': showfiles,
@@ -1,7 +1,7 b''
1 1 changeset = 'changeset: {rev}:{node|short}\n{branches}{tags}{parents}user: {author}\ndate: {date|date}\nsummary: {desc|firstline}\n\n'
2 2 changeset_quiet = '{rev}:{node|short}\n'
3 changeset_verbose = 'changeset: {rev}:{node|short}\n{branches}{tags}{parents}user: {author}\ndate: {date|date}\n{files}{file_copies}description:\n{desc|strip}\n\n\n'
4 changeset_debug = 'changeset: {rev}:{node}\n{branches}{tags}{parents}{manifest}user: {author}\ndate: {date|date}\n{file_mods}{file_adds}{file_dels}{file_copies}{extras}description:\n{desc|strip}\n\n\n'
3 changeset_verbose = 'changeset: {rev}:{node|short}\n{branches}{tags}{parents}user: {author}\ndate: {date|date}\n{files}{file_copies_switch}description:\n{desc|strip}\n\n\n'
4 changeset_debug = 'changeset: {rev}:{node}\n{branches}{tags}{parents}{manifest}user: {author}\ndate: {date|date}\n{file_mods}{file_adds}{file_dels}{file_copies_switch}{extras}description:\n{desc|strip}\n\n\n'
5 5 start_files = 'files: '
6 6 file = ' {file}'
7 7 end_files = '\n'
@@ -14,9 +14,9 b" end_file_adds = '\\n'"
14 14 start_file_dels = 'files-: '
15 15 file_del = ' {file_del}'
16 16 end_file_dels = '\n'
17 start_file_copies = 'copies: '
17 start_file_copies_switch = 'copies: '
18 18 file_copy = ' {name} ({source})'
19 end_file_copies = '\n'
19 end_file_copies_switch = '\n'
20 20 parent = 'parent: {rev}:{node|formatnode}\n'
21 21 manifest = 'manifest: {rev}:{node}\n'
22 22 branch = 'branch: {branch}\n'
@@ -94,8 +94,8 b' cat changelog'
94 94
95 95 echo "# keys work"
96 96 for key in author branches date desc file_adds file_dels file_mods \
97 'file_copies%filecopy' files manifest node parents rev tags diffstat \
98 extras; do
97 'file_copies%filecopy' 'file_copies_switch%filecopy' files \
98 manifest node parents rev tags diffstat extras; do
99 99 for mode in '' --verbose --debug; do
100 100 hg log $mode --template "$key$mode: {$key}\n"
101 101 done
@@ -380,7 +380,7 b' file_mods--debug: c'
380 380 file_mods--debug:
381 381 file_mods--debug:
382 382 file_mods--debug:
383 file_copies%filecopy:
383 file_copies%filecopy: fourth (second)
384 384 file_copies%filecopy:
385 385 file_copies%filecopy:
386 386 file_copies%filecopy:
@@ -389,7 +389,7 b' file_copies%filecopy:'
389 389 file_copies%filecopy:
390 390 file_copies%filecopy:
391 391 file_copies%filecopy:
392 file_copies%filecopy--verbose:
392 file_copies%filecopy--verbose: fourth (second)
393 393 file_copies%filecopy--verbose:
394 394 file_copies%filecopy--verbose:
395 395 file_copies%filecopy--verbose:
@@ -398,6 +398,7 b' file_copies%filecopy--verbose:'
398 398 file_copies%filecopy--verbose:
399 399 file_copies%filecopy--verbose:
400 400 file_copies%filecopy--verbose:
401 file_copies%filecopy--debug: fourth (second)
401 402 file_copies%filecopy--debug:
402 403 file_copies%filecopy--debug:
403 404 file_copies%filecopy--debug:
@@ -406,7 +407,33 b' file_copies%filecopy--debug:'
406 407 file_copies%filecopy--debug:
407 408 file_copies%filecopy--debug:
408 409 file_copies%filecopy--debug:
409 file_copies%filecopy--debug:
410 file_copies_switch%filecopy:
411 file_copies_switch%filecopy:
412 file_copies_switch%filecopy:
413 file_copies_switch%filecopy:
414 file_copies_switch%filecopy:
415 file_copies_switch%filecopy:
416 file_copies_switch%filecopy:
417 file_copies_switch%filecopy:
418 file_copies_switch%filecopy:
419 file_copies_switch%filecopy--verbose:
420 file_copies_switch%filecopy--verbose:
421 file_copies_switch%filecopy--verbose:
422 file_copies_switch%filecopy--verbose:
423 file_copies_switch%filecopy--verbose:
424 file_copies_switch%filecopy--verbose:
425 file_copies_switch%filecopy--verbose:
426 file_copies_switch%filecopy--verbose:
427 file_copies_switch%filecopy--verbose:
428 file_copies_switch%filecopy--debug:
429 file_copies_switch%filecopy--debug:
430 file_copies_switch%filecopy--debug:
431 file_copies_switch%filecopy--debug:
432 file_copies_switch%filecopy--debug:
433 file_copies_switch%filecopy--debug:
434 file_copies_switch%filecopy--debug:
435 file_copies_switch%filecopy--debug:
436 file_copies_switch%filecopy--debug:
410 437 files: fourth second third
411 438 files: second
412 439 files:
@@ -141,7 +141,7 b' diff --git a/rename2 b/rename3-2'
141 141 rename from rename2
142 142 rename to rename3-2
143 143 EOF
144 hg log -vCr. --template '{rev} {files} / {file_copies%filecopy}\n'
144 hg log -vr. --template '{rev} {files} / {file_copies%filecopy}\n'
145 145
146 146 hg locate rename2 rename3 rename3-2
147 147 hg cat rename3
@@ -31,20 +31,24 b' hg log -vf a'
31 31 echo % many renames
32 32 hg log -vf e
33 33
34 echo % log copies
34 echo '% log copies with --copies'
35 35 hg log -vC --template '{rev} {file_copies%filecopy}\n'
36 echo '% log copies switch without --copies'
37 hg log -v --template '{rev} {file_copies_switch%filecopy}\n'
38 echo '% log copies switch with --copies'
39 hg log -vC --template '{rev} {file_copies_switch%filecopy}\n'
36 40
37 41 echo % log copies, non-linear manifest
38 42 hg up -C 3
39 43 hg mv dir/b e
40 44 echo foo > foo
41 45 hg ci -Ame2 -d '6 0'
42 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r 5
46 hg log -v --template '{rev} {file_copies%filecopy}\n' -r 5
43 47
44 48 echo % log copies, execute bit set
45 49 chmod +x e
46 50 hg ci -me3 -d '7 0'
47 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r 6
51 hg log -v --template '{rev} {file_copies%filecopy}\n' -r 6
48 52
49 53 echo '% log -p d'
50 54 hg log -pv d
@@ -76,7 +76,19 b' description:'
76 76 a
77 77
78 78
79 % log copies
79 % log copies with --copies
80 4 e (dir/b)
81 3 b (a)
82 2 dir/b (b)
83 1 b (a)
84 0
85 % log copies switch without --copies
86 4
87 3
88 2
89 1
90 0
91 % log copies switch with --copies
80 92 4 e (dir/b)
81 93 3 b (a)
82 94 2 dir/b (b)
@@ -387,10 +387,10 b" hg ci -m 'change foo'"
387 387 hg up -C 1
388 388 hg qrefresh --git 2>&1 | grep -v 'saving bundle'
389 389 cat .hg/patches/bar
390 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r .
390 hg log -v --template '{rev} {file_copies%filecopy}\n' -r .
391 391 hg qrefresh --git
392 392 cat .hg/patches/bar
393 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r .
393 hg log -v --template '{rev} {file_copies%filecopy}\n' -r .
394 394 hg qrefresh
395 395 grep 'diff --git' .hg/patches/bar
396 396
@@ -403,12 +403,12 b' hg mv bar quux'
403 403 hg mv baz bleh
404 404 hg qrefresh --git 2>&1 | grep -v 'saving bundle'
405 405 cat .hg/patches/bar
406 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r .
406 hg log -v --template '{rev} {file_copies%filecopy}\n' -r .
407 407 hg mv quux fred
408 408 hg mv bleh barney
409 409 hg qrefresh --git
410 410 cat .hg/patches/bar
411 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r .
411 hg log -v --template '{rev} {file_copies%filecopy}\n' -r .
412 412
413 413 echo % refresh omitting an added file
414 414 hg qnew baz
General Comments 0
You need to be logged in to leave comments. Login now