(stable) merge stable
authorChristian Ebert <blacktrash@gmx.net>
Fri, 30 Apr 2010 15:21:59 +0200
branchstable
changeset 738 abd249e1db3c
parent 732 0ff5881bc04b (current diff)
parent 737 dc8fe24c628e (diff)
child 739 886e85e1a172
(stable) merge
--- 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':
--- 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 <<EOF >> $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<<EOF
+y
+y
+n
+EOF
+echo
+hg identify
+hg status
+echo % cat modified file
+cat a
+hg diff | grep -v 'b/a'
+hg rollback
+hg update -C
+
+echo % init --mq
+hg init --mq
 echo % qimport
 hg qimport -r tip -n mqtest.diff
-echo % qcommit
-hg qcommit -mqtest
+echo % commit --mq
+hg commit --mq -m mqtest
 echo % keywords should not be expanded in patch
 cat .hg/patches/mqtest.diff
 echo % qpop
@@ -153,6 +175,10 @@
 hg qgoto mqtest.diff
 echo % cat
 cat c
+echo % hg cat
+hg cat c
+echo % keyword should not be expanded in filelog
+hg --config 'extensions.keyword=!' cat c
 echo % qpop and move on
 hg qpop
 
--- a/tests/test-keyword.out	Thu Apr 22 10:24:49 2010 +0200
+++ b/tests/test-keyword.out	Fri Apr 30 15:21:59 2010 +0200
@@ -132,9 +132,42 @@
 xxx $
 $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $
 tests for different changenodes
-% qinit -c
+% record
+diff --git a/a b/a
+2 hunks, 2 lines changed
+examine changes to 'a'? [Ynsfdaq?] 
+@@ -1,3 +1,4 @@
+ expand $Id$
++foo
+ do not process $Id:
+ xxx $
+record change 1/2 to 'a'? [Ynsfdaq?] 
+@@ -2,2 +3,3 @@
+ do not process $Id:
+ xxx $
++bar
+record change 2/2 to 'a'? [Ynsfdaq?] 
+
+d17e03c92c97+ tip
+M a
+% cat modified file
+expand $Id: a,v d17e03c92c97 1970/01/01 00:00:01 test $
+foo
+do not process $Id:
+xxx $
+bar
+diff -r d17e03c92c97 a
+--- a/a	Wed Dec 31 23:59:51 1969 -0000
+@@ -2,3 +2,4 @@
+ foo
+ do not process $Id:
+ xxx $
++bar
+rolling back to revision 3 (undo commit)
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% init --mq
 % qimport
-% qcommit
+% commit --mq
 % keywords should not be expanded in patch
 # HG changeset patch
 # User User Name <user@example.com>
@@ -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]