hgext/keyword.py
changeset 12498 4846e8cd9327
parent 12497 5d00a35ea2ea
child 12604 415ab8911724
--- a/hgext/keyword.py	Sun Sep 26 19:18:41 2010 +0200
+++ b/hgext/keyword.py	Sun Sep 26 19:18:41 2010 +0200
@@ -92,8 +92,7 @@
 
 # hg commands that do not act on keywords
 nokwcommands = ('add addremove annotate bundle copy export grep incoming init'
-                ' log outgoing push rename rollback tip verify'
-                ' convert email glog')
+                ' log outgoing push rename tip verify convert email glog')
 
 # hg commands that trigger expansion only when writing to working dir,
 # not when reading filelog, and unexpand when reading from working dir
@@ -192,19 +191,20 @@
         Caveat: localrepository._link fails on Windows.'''
         return self.match(path) and not 'l' in flagfunc(path)
 
-    def overwrite(self, ctx, candidates, iswctx, expand):
+    def overwrite(self, ctx, candidates, iswctx, expand, cfiles):
         '''Overwrites selected files expanding/shrinking keywords.'''
-        if self.record:
-            candidates = [f for f in ctx.files() if f in ctx]
+        if cfiles is not None:
+            candidates = [f for f in candidates if f in cfiles]
         candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
         if candidates:
             restrict = self.restrict
             self.restrict = True        # do not expand when reading
+            rollback = kwtools['hgcmd'] == 'rollback'
             mf = ctx.manifest()
             msg = (expand and _('overwriting %s expanding keywords\n')
                    or _('overwriting %s shrinking keywords\n'))
             for f in candidates:
-                if not self.record:
+                if not self.record and not rollback:
                     data = self.repo.file(f).read(mf[f])
                 else:
                     data = self.repo.wread(f)
@@ -220,7 +220,7 @@
                 if found:
                     self.ui.note(msg % f)
                     self.repo.wwrite(f, data, mf.flags(f))
-                    if iswctx:
+                    if iswctx and not rollback:
                         self.repo.dirstate.normal(f)
                     elif self.record:
                         self.repo.dirstate.normallookup(f)
@@ -299,7 +299,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(wctx, clean, True, expand)
+        kwt.overwrite(wctx, clean, True, expand, None)
     finally:
         wlock.release()
 
@@ -503,9 +503,24 @@
             # no lock needed, only called from repo.commit() which already locks
             if not kwt.record:
                 kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()),
-                              False, True)
+                              False, True, None)
             return n
 
+        def rollback(self, dryrun=False):
+            wlock = repo.wlock()
+            try:
+                if not dryrun:
+                    cfiles = self['.'].files()
+                ret = super(kwrepo, self).rollback(dryrun)
+                if not dryrun:
+                    ctx = self['.']
+                    modified, added = super(kwrepo, self).status()[:2]
+                    kwt.overwrite(ctx, added, True, False, cfiles)
+                    kwt.overwrite(ctx, modified, True, True, cfiles)
+                return ret
+            finally:
+                wlock.release()
+
     # monkeypatches
     def kwpatchfile_init(orig, self, ui, fname, opener,
                          missing=False, eolmode=None):
@@ -536,7 +551,8 @@
             ret = orig(ui, repo, commitfunc, *pats, **opts)
             recordctx = repo['.']
             if ctx != recordctx:
-                kwt.overwrite(recordctx, None, False, True)
+                kwt.overwrite(recordctx, recordctx.files(),
+                              False, True, recordctx)
             return ret
         finally:
             wlock.release()