Patchwork [5,of,6] dirstate: make invalidate aware of pending file

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 19, 2015, 4:42 p.m.
Message ID <06310e0ab134f1bb45bd.1432053725@feefifofum>
Download mbox | patch
Permalink /patch/9183/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Katsunori FUJIWARA - May 19, 2015, 4:42 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1432051569 -32400
#      Wed May 20 01:06:09 2015 +0900
# Node ID 06310e0ab134f1bb45bdebd5d87cfcfca4ca2548
# Parent  32bb772580da70c05822ab830349585f0245ae92
dirstate: make invalidate aware of pending file

When pending file exists, `invalidate()` should remove it, because
part (or all) of changes after last `write()` are still held in it:
remaining it may cause accidental reading it in.

`_removepending()` is defined as a function to reuse it in subsequent
patches.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -394,6 +394,9 @@ 
         self._lastnormaltime = 0
         self._dirty = False
         self._parentwriters = 0
+        if self._diverted:
+            # avoid accidental reading '.pending' in
+            self._removepending()
 
     def copy(self, source, dest):
         """Mark dest as a copy of source. Unmark dest if source is None."""
@@ -622,6 +625,14 @@ 
             return
         self._writedirstate(self._filename)
 
+    def _removepending(self):
+        try:
+            self._opener.unlink(self._pendingfilename)
+        except OSError, e:
+            if e.errno != errno.ENOENT:
+                raise
+        self._diverted = False
+
     def _writepending(self, tr):
         '''Make pending data visible to external processes