##// END OF EJS Templates
keyword: support mq; handle (q)record more gracefully...
Christian Ebert -
r5884:a139f141 default
parent child Browse files
Show More
@@ -69,12 +69,16 b' 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, fancyopts, filelog
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,13 b' 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 ('qimport', 'qnew', 'qpush', 'qrefresh', 'record', 'qrecord')
98
99
89 _kwtemplater = None
100 _kwtemplater = None
90
101
91 class kwtemplater(object):
102 class kwtemplater(object):
@@ -103,10 +114,11 b' class kwtemplater(object):'
103 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}',
114 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}',
104 }
115 }
105
116
106 def __init__(self, ui, repo, inc, exc):
117 def __init__(self, ui, repo, inc, exc, hgcmd):
107 self.ui = ui
118 self.ui = ui
108 self.repo = repo
119 self.repo = repo
109 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
120 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
121 self.hgcmd = hgcmd
110 self.commitnode = None
122 self.commitnode = None
111 self.path = ''
123 self.path = ''
112
124
@@ -144,7 +156,7 b' class kwtemplater(object):'
144
156
145 def expand(self, node, data):
157 def expand(self, node, data):
146 '''Returns data with keywords expanded.'''
158 '''Returns data with keywords expanded.'''
147 if util.binary(data):
159 if util.binary(data) or _kwrestrict(self.hgcmd):
148 return data
160 return data
149 return self.substitute(node, data, self.re_kw.sub)
161 return self.substitute(node, data, self.re_kw.sub)
150
162
@@ -395,20 +407,16 b' def reposetup(ui, repo):'
395 This is done for local repos only, and only if there are
407 This is done for local repos only, and only if there are
396 files configured at all for keyword substitution.'''
408 files configured at all for keyword substitution.'''
397
409
398 def kwbailout():
410 if not repo.local():
399 '''Obtains command via simplified cmdline parsing,
411 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
412
411 if not repo.local() or kwbailout():
413 nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy',
414 'export', 'grep', 'identify', 'incoming', 'init',
415 'log', 'outgoing', 'push', 'remove', 'rename',
416 'rollback', 'tip',
417 'convert')
418 hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
419 if hgcmd in nokwcommands:
412 return
420 return
413
421
414 inc, exc = [], ['.hgtags']
422 inc, exc = [], ['.hgtags']
@@ -421,7 +429,7 b' def reposetup(ui, repo):'
421 return
429 return
422
430
423 global _kwtemplater
431 global _kwtemplater
424 _kwtemplater = kwtemplater(ui, repo, inc, exc)
432 _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd)
425
433
426 class kwrepo(repo.__class__):
434 class kwrepo(repo.__class__):
427 def file(self, f, kwmatch=False):
435 def file(self, f, kwmatch=False):
@@ -431,6 +439,12 b' def reposetup(ui, repo):'
431 return kwfilelog(self.sopener, f)
439 return kwfilelog(self.sopener, f)
432 return filelog.filelog(self.sopener, f)
440 return filelog.filelog(self.sopener, f)
433
441
442 def wread(self, filename):
443 data = super(kwrepo, self).wread(filename)
444 if _kwrestrict(hgcmd) and _kwtemplater.matcher(filename):
445 return _kwtemplater.shrink(data)
446 return data
447
434 def commit(self, files=None, text='', user=None, date=None,
448 def commit(self, files=None, text='', user=None, date=None,
435 match=util.always, force=False, force_editor=False,
449 match=util.always, force=False, force_editor=False,
436 p1=None, p2=None, extra={}):
450 p1=None, p2=None, extra={}):
@@ -36,6 +36,10 b' 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.
General Comments 0
You need to be logged in to leave comments. Login now