changeset 5516:f252ba975925

Fix dir-changed-to-file updates on clean workdir. Workaround for dir-changed-to-file updates mentioned in rev 7a64931e2d76 doesn't actually work since tests introduced in mentioned changeset prevented dirstate updates even if working directory updates succeded. Make tests more relaxed for dirstate operations not directly accessible from cli. See also issue660. While here, move _dirs existance check from _decpath() to _changepath() for unification.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 07 Nov 2007 22:57:28 +0100
parents bf2bb53e5d2b
children 98d5f9b95699
files mercurial/dirstate.py tests/test-issue660 tests/test-issue660.out
diffstat 3 files changed, 40 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Fri Oct 26 16:43:13 2007 -0700
+++ b/mercurial/dirstate.py	Wed Nov 07 22:57:28 2007 +0100
@@ -185,16 +185,15 @@
                 dirs[base] += 1
 
     def _decpath(self, path):
-        if "_dirs" in self.__dict__:
-            c = path.rfind('/')
-            if c >= 0:
-                base = path[:c]
-                dirs = self._dirs
-                if dirs[base] == 1:
-                    del dirs[base]
-                    self._decpath(base)
-                else:
-                    dirs[base] -= 1
+        c = path.rfind('/')
+        if c >= 0:
+            base = path[:c]
+            dirs = self._dirs
+            if dirs[base] == 1:
+                del dirs[base]
+                self._decpath(base)
+            else:
+                dirs[base] -= 1
 
     def _incpathcheck(self, f):
         if '\r' in f or '\n' in f:
@@ -211,20 +210,29 @@
                                  (d, f))
         self._incpath(f)
 
-    def _changepath(self, f, newstate):
+    def _changepath(self, f, newstate, relaxed=False):
         # handle upcoming path changes
         oldstate = self[f]
         if oldstate not in "?r" and newstate in "?r":
-            self._decpath(f)
+            if "_dirs" in self.__dict__:
+                self._decpath(f)
             return
         if oldstate in "?r" and newstate not in "?r":
+            if relaxed and oldstate == '?':
+                # XXX
+                # in relaxed mode we assume the caller knows
+                # what it is doing, workaround for updating
+                # dir-to-file revisions
+                if "_dirs" in self.__dict__:
+                    self._incpath(f)
+                return
             self._incpathcheck(f)
             return
 
     def normal(self, f):
         'mark a file normal and clean'
         self._dirty = True
-        self._changepath(f, 'n')
+        self._changepath(f, 'n', True)
         s = os.lstat(self._join(f))
         self._map[f] = ('n', s.st_mode, s.st_size, s.st_mtime, 0)
         if self._copymap.has_key(f):
@@ -233,7 +241,7 @@
     def normallookup(self, f):
         'mark a file normal, but possibly dirty'
         self._dirty = True
-        self._changepath(f, 'n')
+        self._changepath(f, 'n', True)
         self._map[f] = ('n', 0, -1, -1, 0)
         if f in self._copymap:
             del self._copymap[f]
@@ -241,7 +249,7 @@
     def normaldirty(self, f):
         'mark a file normal, but dirty'
         self._dirty = True
-        self._changepath(f, 'n')
+        self._changepath(f, 'n', True)
         self._map[f] = ('n', 0, -2, -1, 0)
         if f in self._copymap:
             del self._copymap[f]
@@ -266,7 +274,7 @@
         'mark a file merged'
         self._dirty = True
         s = os.lstat(self._join(f))
-        self._changepath(f, 'm')
+        self._changepath(f, 'm', True)
         self._map[f] = ('m', s.st_mode, s.st_size, s.st_mtime, 0)
         if f in self._copymap:
             del self._copymap[f]
--- a/tests/test-issue660	Fri Oct 26 16:43:13 2007 -0700
+++ b/tests/test-issue660	Wed Nov 07 22:57:28 2007 +0100
@@ -80,10 +80,15 @@
 
 echo % should succeed - shadow removed
 hg add d
+hg ci -md
 
-#echo % update should work
-#
-#hg up -r 0
-#hg up -r 1
+echo % update should work at least with clean workdir
+
+rm -r a b d
+hg up -r 0
+hg st --all
+rm -r a b
+hg up -r 1
+hg st --all
 
 exit 0
--- a/tests/test-issue660.out	Fri Oct 26 16:43:13 2007 -0700
+++ b/tests/test-issue660.out	Wed Nov 07 22:57:28 2007 +0100
@@ -40,3 +40,10 @@
 abort: directory 'd' already in dirstate
 % removing shadow
 % should succeed - shadow removed
+% update should work at least with clean workdir
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+C a
+C b/b
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+C a/a
+C b