Show More
@@ -69,12 +69,16 the risk of inadvertedly storing expande | |||||
69 | To force expansion after enabling it, or a configuration change, run |
|
69 | To force expansion after enabling it, or a configuration change, run | |
70 | "hg kwexpand". |
|
70 | "hg kwexpand". | |
71 |
|
71 | |||
|
72 | Also, when committing with the record extension or using mq's qrecord, be aware | |||
|
73 | that keywords cannot be updated. Again, run "hg kwexpand" on the files in | |||
|
74 | question to update keyword expansions after all changes have been checked in. | |||
|
75 | ||||
72 | Expansions spanning more than one line and incremental expansions, |
|
76 | Expansions spanning more than one line and incremental expansions, | |
73 | like CVS' $Log$, are not supported. A keyword template map |
|
77 | like CVS' $Log$, are not supported. A keyword template map | |
74 | "Log = {desc}" expands to the first line of the changeset description. |
|
78 | "Log = {desc}" expands to the first line of the changeset description. | |
75 | ''' |
|
79 | ''' | |
76 |
|
80 | |||
77 |
from mercurial import commands, cmdutil, context, |
|
81 | from mercurial import commands, cmdutil, context, dispatch, filelog | |
78 | from mercurial import patch, localrepo, revlog, templater, util |
|
82 | from mercurial import patch, localrepo, revlog, templater, util | |
79 | from mercurial.node import * |
|
83 | from mercurial.node import * | |
80 | from mercurial.i18n import _ |
|
84 | from mercurial.i18n import _ | |
@@ -86,6 +90,14 def utcdate(date): | |||||
86 | '''Returns hgdate in cvs-like UTC format.''' |
|
90 | '''Returns hgdate in cvs-like UTC format.''' | |
87 | return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) |
|
91 | return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) | |
88 |
|
92 | |||
|
93 | def _kwrestrict(cmd): | |||
|
94 | '''Returns True if cmd should trigger restricted expansion. | |||
|
95 | Keywords will only expanded when writing to working dir. | |||
|
96 | Crucial for mq as expanded keywords should not make it into patches.''' | |||
|
97 | return cmd in ('diff1', | |||
|
98 | 'qimport', 'qnew', 'qpush', 'qrefresh', 'record', 'qrecord') | |||
|
99 | ||||
|
100 | ||||
89 | _kwtemplater = None |
|
101 | _kwtemplater = None | |
90 |
|
102 | |||
91 | class kwtemplater(object): |
|
103 | class kwtemplater(object): | |
@@ -103,10 +115,11 class kwtemplater(object): | |||||
103 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
|
115 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', | |
104 | } |
|
116 | } | |
105 |
|
117 | |||
106 | def __init__(self, ui, repo, inc, exc): |
|
118 | def __init__(self, ui, repo, inc, exc, hgcmd): | |
107 | self.ui = ui |
|
119 | self.ui = ui | |
108 | self.repo = repo |
|
120 | self.repo = repo | |
109 | self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
|
121 | self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] | |
|
122 | self.hgcmd = hgcmd | |||
110 | self.commitnode = None |
|
123 | self.commitnode = None | |
111 | self.path = '' |
|
124 | self.path = '' | |
112 |
|
125 | |||
@@ -144,7 +157,7 class kwtemplater(object): | |||||
144 |
|
157 | |||
145 | def expand(self, node, data): |
|
158 | def expand(self, node, data): | |
146 | '''Returns data with keywords expanded.''' |
|
159 | '''Returns data with keywords expanded.''' | |
147 | if util.binary(data): |
|
160 | if util.binary(data) or _kwrestrict(self.hgcmd): | |
148 | return data |
|
161 | return data | |
149 | return self.substitute(node, data, self.re_kw.sub) |
|
162 | return self.substitute(node, data, self.re_kw.sub) | |
150 |
|
163 | |||
@@ -395,22 +408,27 def reposetup(ui, repo): | |||||
395 | This is done for local repos only, and only if there are |
|
408 | This is done for local repos only, and only if there are | |
396 | files configured at all for keyword substitution.''' |
|
409 | files configured at all for keyword substitution.''' | |
397 |
|
410 | |||
398 | def kwbailout(): |
|
411 | if not repo.local(): | |
399 | '''Obtains command via simplified cmdline parsing, |
|
412 | return | |
400 | returns True if keyword expansion not needed.''' |
|
|||
401 | nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', |
|
|||
402 | 'export', 'grep', 'identify', 'incoming', 'init', |
|
|||
403 | 'log', 'outgoing', 'push', 'remove', 'rename', |
|
|||
404 | 'rollback', 'tip', |
|
|||
405 | 'convert') |
|
|||
406 | args = fancyopts.fancyopts(sys.argv[1:], commands.globalopts, {}) |
|
|||
407 | if args: |
|
|||
408 | aliases, i = cmdutil.findcmd(ui, args[0], commands.table) |
|
|||
409 | return aliases[0] in nokwcommands |
|
|||
410 |
|
413 | |||
411 | if not repo.local() or kwbailout(): |
|
414 | nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', | |
|
415 | 'export', 'grep', 'identify', 'incoming', 'init', | |||
|
416 | 'log', 'outgoing', 'push', 'remove', 'rename', | |||
|
417 | 'rollback', 'tip', | |||
|
418 | 'convert') | |||
|
419 | hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) | |||
|
420 | if hgcmd in nokwcommands: | |||
412 | return |
|
421 | return | |
413 |
|
422 | |||
|
423 | if hgcmd == 'diff': | |||
|
424 | # only expand if comparing against working dir | |||
|
425 | node1, node2 = cmdutil.revpair(repo, cmdopts.get('rev')) | |||
|
426 | if node2 is not None: | |||
|
427 | return | |||
|
428 | # shrink if rev is not current node | |||
|
429 | if node1 is not None and node1 != repo.changectx().node(): | |||
|
430 | hgcmd = 'diff1' | |||
|
431 | ||||
414 | inc, exc = [], ['.hgtags'] |
|
432 | inc, exc = [], ['.hgtags'] | |
415 | for pat, opt in ui.configitems('keyword'): |
|
433 | for pat, opt in ui.configitems('keyword'): | |
416 | if opt != 'ignore': |
|
434 | if opt != 'ignore': | |
@@ -421,7 +439,7 def reposetup(ui, repo): | |||||
421 | return |
|
439 | return | |
422 |
|
440 | |||
423 | global _kwtemplater |
|
441 | global _kwtemplater | |
424 | _kwtemplater = kwtemplater(ui, repo, inc, exc) |
|
442 | _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd) | |
425 |
|
443 | |||
426 | class kwrepo(repo.__class__): |
|
444 | class kwrepo(repo.__class__): | |
427 | def file(self, f, kwmatch=False): |
|
445 | def file(self, f, kwmatch=False): | |
@@ -431,6 +449,12 def reposetup(ui, repo): | |||||
431 | return kwfilelog(self.sopener, f) |
|
449 | return kwfilelog(self.sopener, f) | |
432 | return filelog.filelog(self.sopener, f) |
|
450 | return filelog.filelog(self.sopener, f) | |
433 |
|
451 | |||
|
452 | def wread(self, filename): | |||
|
453 | data = super(kwrepo, self).wread(filename) | |||
|
454 | if _kwrestrict(hgcmd) and _kwtemplater.matcher(filename): | |||
|
455 | return _kwtemplater.shrink(data) | |||
|
456 | return data | |||
|
457 | ||||
434 | def commit(self, files=None, text='', user=None, date=None, |
|
458 | def commit(self, files=None, text='', user=None, date=None, | |
435 | match=util.always, force=False, force_editor=False, |
|
459 | match=util.always, force=False, force_editor=False, | |
436 | p1=None, p2=None, extra={}): |
|
460 | p1=None, p2=None, extra={}): |
@@ -36,6 +36,10 the risk of inadvertedly storing expande | |||||
36 | To force expansion after enabling it, or a configuration change, run |
|
36 | To force expansion after enabling it, or a configuration change, run | |
37 | "hg kwexpand". |
|
37 | "hg kwexpand". | |
38 |
|
38 | |||
|
39 | Also, when committing with the record extension or using mq's qrecord, be aware | |||
|
40 | that keywords cannot be updated. Again, run "hg kwexpand" on the files in | |||
|
41 | question to update keyword expansions after all changes have been checked in. | |||
|
42 | ||||
39 | Expansions spanning more than one line and incremental expansions, |
|
43 | Expansions spanning more than one line and incremental expansions, | |
40 | like CVS' $Log$, are not supported. A keyword template map |
|
44 | like CVS' $Log$, are not supported. A keyword template map | |
41 | "Log = {desc}" expands to the first line of the changeset description. |
|
45 | "Log = {desc}" expands to the first line of the changeset description. | |
@@ -184,7 +188,7 c | |||||
184 | diff -r f782df5f9602 c |
|
188 | diff -r f782df5f9602 c | |
185 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
189 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
186 | @@ -0,0 +1,3 @@ |
|
190 | @@ -0,0 +1,3 @@ | |
187 | +expand $Id: c,v 0ba462c0f077 1970/01/01 00:00:01 user $ |
|
191 | +expand $Id$ | |
188 | +do not process $Id: |
|
192 | +do not process $Id: | |
189 | +xxx $ |
|
193 | +xxx $ | |
190 | % rollback |
|
194 | % rollback |
General Comments 0
You need to be logged in to leave comments.
Login now