# HG changeset patch # User Christian Ebert # Date 1201084702 -3600 # Node ID 63ebc698d06b7bee70583997a315d269af5a4cc6 # Parent f5927e5574e6b297c4c332f4c2054287965a2d9c Get changes from default branch; update test output diff -r f5927e5574e6 -r 63ebc698d06b hgkw/keyword.py --- a/hgkw/keyword.py Sat Jan 19 18:26:17 2008 +0100 +++ b/hgkw/keyword.py Wed Jan 23 11:38:22 2008 +0100 @@ -189,17 +189,15 @@ commands.optionalrepo += ' kwdemo' +# hg commands that trigger expansion only when writing to working dir, +# not when reading filelog, and unexpand when reading from working dir +restricted = ('diff1', 'record', + 'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord') + def utcdate(date): '''Returns hgdate in cvs-like UTC format.''' return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) -def _kwrestrict(cmd): - '''Returns True if cmd should trigger restricted expansion. - Keywords will only expanded when writing to working dir. - Crucial for mq as expanded keywords should not make it into patches.''' - return cmd in ('diff1', - 'qimport', 'qnew', 'qpush', 'qrefresh', 'record', 'qrecord') - _kwtemplater = None @@ -269,7 +267,7 @@ def expand(self, node, data): '''Returns data with keywords expanded.''' - if util.binary(data) or _kwrestrict(self.hgcmd): + if util.binary(data) or self.hgcmd in restricted: return data return self.substitute(node, data, self.re_kw.sub) @@ -340,7 +338,7 @@ mf = ctx.manifest() if node is not None: # commit _kwtemplater.commitnode = node - files = [f for f in ctx.files() if mf.has_key(f)] + files = [f for f in ctx.files() if f in mf] notify = ui.debug else: # kwexpand/kwshrink notify = ui.note @@ -409,7 +407,7 @@ kwmaps = kwtemplater.templates if ui.configitems('keywordmaps'): # override maps from optional rcfile - for k, v in kwmaps.items(): + for k, v in kwmaps.iteritems(): ui.setconfig('keywordmaps', k, v) elif args: # simulate hgrc parsing @@ -428,7 +426,7 @@ demostatus('config using %s keyword template maps' % kwstatus) ui.write('[extensions]\n%s\n' % extension) demoitems('keyword', ui.configitems('keyword')) - demoitems('keywordmaps', kwmaps.items()) + demoitems('keywordmaps', kwmaps.iteritems()) keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n' repo.wopener(fn, 'w').write(keywords) repo.add([fn]) @@ -552,7 +550,7 @@ def wread(self, filename): data = super(kwrepo, self).wread(filename) - if _kwrestrict(hgcmd) and _kwtemplater.matcher(filename): + if hgcmd in restricted and _kwtemplater.matcher(filename): return _kwtemplater.shrink(data) return data @@ -589,10 +587,10 @@ if not _lock: _lock = self.lock() # store and postpone commit hooks - commithooks = [] + commithooks = {} for name, cmd in ui.configitems('hooks'): if name.split('.', 1)[0] == 'commit': - commithooks.append((name, cmd)) + commithooks[name] = cmd ui.setconfig('hooks', name, '') if commithooks: # store parents for commit hook environment @@ -610,7 +608,7 @@ _lock, _wlock, force_editor, p1, p2, extra) # restore commit hooks - for name, cmd in commithooks: + for name, cmd in commithooks.iteritems(): ui.setconfig('hooks', name, cmd) if node is not None: _overwrite(ui, self, node=node) diff -r f5927e5574e6 -r 63ebc698d06b tests/test-keyword.out --- a/tests/test-keyword.out Sat Jan 19 18:26:17 2008 +0100 +++ b/tests/test-keyword.out Wed Jan 23 11:38:22 2008 +0100 @@ -24,6 +24,9 @@ the risk of inadvertedly storing expanded keywords in the change history. To force expansion after enabling it, or a configuration change, run "hg kwexpand". +Also, when committing with the record extension or using mq's qrecord, be aware +that keywords cannot be updated. Again, run "hg kwexpand" on the files in +question to update keyword expansions after all changes have been checked in. Expansions spanning more than one line and incremental expansions, like CVS' $Log$, are not supported. A keyword template map "Log = {desc}" expands to the first line of the changeset description. @@ -121,8 +124,31 @@ xxx $ $Id: c,v 7fefeeacf359 1970/01/01 00:00:01 user $ tests for different changenodes -% rollback and remove c -rolling back last transaction +% qimport +% keywords should not be expanded in patch +# HG changeset patch +# User User Name +# Date 1 0 +# Node ID 7fefeeacf3596ca401a248c183c2314cbf4661ee +# Parent 7f0665a496fd37c3627191bd02e26a1e230f2aa2 +cndiff + +diff -r 7f0665a496fd -r 7fefeeacf359 c +--- /dev/null Thu Jan 01 00:00:00 1970 +0000 ++++ b/c Thu Jan 01 00:00:01 1970 +0000 +@@ -0,0 +1,2 @@ ++$Id$ ++tests for different changenodes +% qpop +Patch queue now empty +% qpush +applying mqtest.diff +Now at: mqtest.diff +% cat +$Id: c,v 7fefeeacf359 1970/01/01 00:00:01 user $ +tests for different changenodes +% qpop and move on +Patch queue now empty % copy % kwfiles added a @@ -147,7 +173,7 @@ diff -r 7f0665a496fd c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -0,0 +1,3 @@ -+expand $Id: c,v 6a127771f5db 1970/01/01 00:00:01 user $ ++expand $Id$ +do not process $Id: +xxx $ % rollback