commit: hoist up dirstate invalidate
authorMatt Mackall <mpm@selenic.com>
Thu, 14 May 2009 13:24:39 -0500
changeset 8415 221a18019b2b
parent 8414 2348ce25849b
child 8416 9dfee83c93c8
commit: hoist up dirstate invalidate
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu May 14 13:24:26 2009 -0500
+++ b/mercurial/localrepo.py	Thu May 14 13:24:39 2009 -0500
@@ -775,6 +775,7 @@
         if files:
             files = list(set(files))
 
+        ret = None
         wlock = self.wlock()
         try:
             p1, p2 = self.dirstate.parents()
@@ -811,11 +812,13 @@
                                                     "(see hg resolve)"))
             wctx = context.workingctx(self, (p1, p2), text, user, date,
                                       extra, changes)
-            r = self.commitctx(wctx, editor, True)
+            ret = self.commitctx(wctx, editor, True)
             ms.reset()
-            return r
+            return ret
 
         finally:
+            if ret == None:
+                self.dirstate.invalidate() # didn't successfully commit
             wlock.release()
 
     def commitctx(self, ctx, editor=None, working=False):
@@ -827,7 +830,6 @@
         """
 
         tr = lock = None
-        valid = 0 # don't save the dirstate if this isn't set
         remove = ctx.removed()
         p1, p2 = ctx.p1(), ctx.p2()
         m1 = p1.manifest().copy()
@@ -908,13 +910,10 @@
                 self.dirstate.setparents(n)
                 for f in removed:
                     self.dirstate.forget(f)
-            valid = 1 # our dirstate updates are complete
 
             self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
             return n
         finally:
-            if not valid: # don't save our updated dirstate
-                self.dirstate.invalidate()
             del tr
             lock.release()