# HG changeset patch # User Christian Ebert # Date 1272633719 -7200 # Node ID abd249e1db3c1ff66cc5c57bc9d5a71fe97ec317 # Parent 0ff5881bc04b830180f1c1dffab241e5e412f4ad# Parent dc8fe24c628e700bf214c49632df8b3dd6d02ca1 (stable) merge diff -r 0ff5881bc04b -r abd249e1db3c hgkw/keyword.py --- a/hgkw/keyword.py Thu Apr 22 10:24:49 2010 +0200 +++ b/hgkw/keyword.py Fri Apr 30 15:21:59 2010 +0200 @@ -66,11 +66,6 @@ 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. @@ -92,8 +87,10 @@ # hg commands that trigger expansion only when writing to working dir, # not when reading filelog, and unexpand when reading from working dir -restricted = ('merge record resolve qfold qimport qnew qpush qrefresh qrecord' - ' transplant') +restricted = 'merge record qrecord resolve transplant' + +# commands using dorecord +recordcommands = 'record qrecord' # provide cvs-like UTC date filter utcdate = lambda x: util.datestr((x[0], 0), '%Y/%m/%d %H:%M:%S') @@ -125,6 +122,7 @@ self.match = match.match(repo.root, '', [], kwtools['inc'], kwtools['exc']) self.restrict = kwtools['hgcmd'] in restricted.split() + self.record = kwtools['hgcmd'] in recordcommands.split() kwmaps = self.ui.configitems('keywordmaps') if kwmaps: # override default templates @@ -162,11 +160,14 @@ Caveat: localrepository._link fails on Windows.''' return self.match(path) and not 'l' in flagfunc(path) - def overwrite(self, node, expand, candidates): + def overwrite(self, node, expand, candidates, recctx=None): '''Overwrites selected files expanding/shrinking keywords.''' - ctx = self.repo[node] + if recctx is None: + ctx = self.repo[node] + else: + ctx = recctx mf = ctx.manifest() - if node is not None: # commit + if node is not None: # commit, record candidates = [f for f in ctx.files() if f in mf] candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)] if candidates: @@ -174,8 +175,10 @@ msg = (expand and _('overwriting %s expanding keywords\n') or _('overwriting %s shrinking keywords\n')) for f in candidates: - fp = self.repo.file(f) - data = fp.read(mf[f]) + if recctx is None: + data = self.repo.file(f).read(mf[f]) + else: + data = self.repo.wread(f) if util.binary(data): continue if expand: @@ -466,7 +469,8 @@ def kwcommitctx(self, ctx, error=False): n = super(kwrepo, self).commitctx(ctx, error) # no lock needed, only called from repo.commit() which already locks - kwt.overwrite(n, True, None) + if not kwt.record: + kwt.overwrite(n, True, None) return n # monkeypatches @@ -493,6 +497,21 @@ kwt.match = util.never return orig(web, req, tmpl) + def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts): + '''Wraps record.dorecord expanding keywords after recording.''' + wlock = repo.wlock() + try: + # record returns 0 even when nothing has changed + # therefore compare nodes before and after + ctx = repo['.'] + ret = orig(ui, repo, commitfunc, *pats, **opts) + recctx = repo['.'] + if ctx != recctx: + kwt.overwrite('.', True, None, recctx) + return ret + finally: + wlock.release() + repo.__class__ = kwrepo extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) @@ -500,6 +519,11 @@ extensions.wrapfunction(patch, 'diff', kw_diff) for c in 'annotate changeset rev filediff diff'.split(): extensions.wrapfunction(webcommands, c, kwweb_skip) + try: + record = extensions.find('record') + extensions.wrapfunction(record, 'dorecord', kw_dorecord) + except KeyError: + pass cmdtable = { 'kwdemo': diff -r 0ff5881bc04b -r abd249e1db3c tests/test-keyword --- a/tests/test-keyword Thu Apr 22 10:24:49 2010 +0200 +++ b/tests/test-keyword Fri Apr 30 15:21:59 2010 +0200 @@ -5,7 +5,10 @@ keyword = mq = notify = +record = transplant = +[ui] +interactive = true EOF # demo before [keyword] files are set up @@ -21,7 +24,7 @@ cat <> $HGRCPATH [keyword] -* = +** = b = ignore [hooks] commit= @@ -139,12 +142,31 @@ echo % compare changenodes in a c cat a c -echo % qinit -c -hg qinit -c +echo % record +cp "$HGRCPATH" $HGRCPATH.bak +sed -e '1 a \foo' a > a.tmp +mv a.tmp a +echo bar >> a +hg record -d '1 10' -m rectest< @@ -158,6 +191,12 @@ % cat $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $ tests for different changenodes +% hg cat +$Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $ +tests for different changenodes +% keyword should not be expanded in filelog +$Id$ +tests for different changenodes % qpop and move on popping mqtest.diff patch queue now empty @@ -208,7 +247,7 @@ [extensions] keyword = [keyword] -* = +** = b = ignore demo.txt = [keywordmaps]