(stable) merge stable
authorChristian Ebert <blacktrash@gmx.net>
Wed, 09 Jun 2010 22:50:30 +0100
branchstable
changeset 766 1b077329846e
parent 761 81d8da31c542 (current diff)
parent 765 c5badbf855db (diff)
child 767 0492a5acf652
(stable) merge
--- a/hgkw/keyword.py	Mon Jun 07 20:03:32 2010 +0200
+++ b/hgkw/keyword.py	Wed Jun 09 22:50:30 2010 +0100
@@ -189,15 +189,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, ctx, candidates, iswctx, expand):
         '''Overwrites selected files expanding/shrinking keywords.'''
-        ctx = self.repo[node]
         mf = ctx.manifest()
-        if node is not None:     # commit, record
+        if self.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:
-            self.restrict = True # do not expand when reading
+            self.restrict = True        # do not expand when reading
             msg = (expand and _('overwriting %s expanding keywords\n')
                    or _('overwriting %s shrinking keywords\n'))
             for f in candidates:
@@ -208,7 +207,7 @@
                 if util.binary(data):
                     continue
                 if expand:
-                    if node is None:
+                    if iswctx:
                         ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
                     data, found = self.substitute(data, f, ctx,
                                                   self.re_kw.subn)
@@ -217,8 +216,10 @@
                 if found:
                     self.ui.note(msg % f)
                     self.repo.wwrite(f, data, mf.flags(f))
-                    if node is None:
+                    if iswctx:
                         self.repo.dirstate.normal(f)
+                    elif self.record:
+                        self.repo.dirstate.normallookup(f)
             self.restrict = False
 
     def shrinktext(self, text):
@@ -284,7 +285,8 @@
 
 def _kwfwrite(ui, repo, expand, *pats, **opts):
     '''Selects files and passes them to kwtemplater.overwrite.'''
-    if len(repo[None].parents()) > 1:
+    wctx = repo[None]
+    if len(wctx.parents()) > 1:
         raise util.Abort(_('outstanding uncommitted merge'))
     kwt = kwtools['templater']
     wlock = repo.wlock()
@@ -293,7 +295,7 @@
         modified, added, removed, deleted, unknown, ignored, clean = status
         if modified or added or removed or deleted:
             raise util.Abort(_('outstanding uncommitted changes'))
-        kwt.overwrite(None, expand, clean)
+        kwt.overwrite(wctx, clean, True, expand)
     finally:
         wlock.release()
 
@@ -496,7 +498,8 @@
             n = super(kwrepo, self).commitctx(ctx, error)
             # no lock needed, only called from repo.commit() which already locks
             if not kwt.record:
-                kwt.overwrite(n, True, None)
+                kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()),
+                              False, True)
             return n
 
     # monkeypatches
@@ -531,8 +534,9 @@
             # therefore compare nodes before and after
             ctx = repo['.']
             ret = orig(ui, repo, commitfunc, *pats, **opts)
-            if ctx != repo['.']:
-                kwt.overwrite('.',  True, None)
+            recordctx = repo['.']
+            if ctx != recordctx:
+                kwt.overwrite(recordctx, None, False, True)
             return ret
         finally:
             wlock.release()
--- a/tests/test-keyword	Mon Jun 07 20:03:32 2010 +0200
+++ b/tests/test-keyword	Wed Jun 09 22:50:30 2010 +0100
@@ -142,7 +142,7 @@
 echo % compare changenodes in a c
 cat a c
 
-echo % record
+echo % record chunk
 python -c \
 'l=open("a").readlines();l.insert(1,"foo\n");l.append("bar\n");open("a","w").writelines(l);'
 hg record -d '1 10' -m rectest<<EOF
@@ -157,6 +157,19 @@
 cat a
 hg diff | grep -v 'b/a'
 hg rollback
+
+echo % record file
+echo foo > msg
+# do not use "hg record -m" here!
+hg record -l msg -d '1 11'<<EOF
+y
+y
+y
+EOF
+echo % a should be clean
+hg status -A a
+rm msg
+hg rollback
 hg update -C
 
 echo % init --mq
--- a/tests/test-keyword.out	Mon Jun 07 20:03:32 2010 +0200
+++ b/tests/test-keyword.out	Wed Jun 09 22:50:30 2010 +0100
@@ -132,7 +132,7 @@
 xxx $
 $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $
 tests for different changenodes
-% record
+% record chunk
 diff --git a/a b/a
 2 hunks, 2 lines changed
 examine changes to 'a'? [Ynsfdaq?] 
@@ -164,6 +164,24 @@
  xxx $
 +bar
 rolling back to revision 2 (undo commit)
+% record file
+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?] 
+% a should be clean
+C a
+rolling back to revision 2 (undo commit)
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % init --mq
 % qimport