[PATCH 6 of 6] dirstate: make write() aware of pending file

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue May 19 11:42:06 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1432051569 -32400
#      Wed May 20 01:06:09 2015 +0900
# Node ID 18d35e7df884b3bdd8f6d1351703679f650a83b9
# Parent  06310e0ab134f1bb45bdebd5d87cfcfca4ca2548
dirstate: make write() aware of pending file

When pending file exists, `write()` should:

- rename from `dirstate.pendnig` to `dirstate`, if not dirty
  - the former works well as the latter
    (dirstate hasn't been changed since last `_writepending()`), and
  - renaming is more efficient than writing out again

- remove `dirstate.pending` and write changes into `dirstate`, otherwise

`_fixuppending()` is defined as a function to reuse it in subsequent
patch: pending file should be fixed up also at the end of transaction
regardless of outcome of it.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -621,6 +621,7 @@
         self._dirty = True
 
     def write(self):
+        self._fixuppending(None)
         if not self._dirty:
             return
         self._writedirstate(self._filename)
@@ -633,6 +634,21 @@
                 raise
         self._diverted = False
 
+    def _fixuppending(self, tr):
+        '''Fix up pending file
+
+        `tr` may be None, because this is used also out of transaction
+        scope.
+        '''
+        if self._diverted:
+            if self._dirty:
+                # '.pending' file should be out of date
+                self._removepending()
+            else:
+                # dirstate hasn't been changed since last _writepending
+                self._opener.rename(self._pendingfilename, self._filename)
+                self._diverted = False
+
     def _writepending(self, tr):
         '''Make pending data visible to external processes
 


More information about the Mercurial-devel mailing list