[PATCH] add: do not retrieve directories/missing files from dirstate.walk

Nicolas Dumazet nicdumz at gmail.com
Thu Dec 10 05:01:07 CST 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1260437938 -32400
# Node ID 73ff53b16c9e18e15af43d0131629e005570e7ad
# Parent  2b630e4c8f2f626f1e5d0f88646463968860f8ac
add: do not retrieve directories/missing files from dirstate.walk

It should suppress a bogus hg add warning when adding a directory over
a previously committed file.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -36,7 +36,7 @@
     oldbad = m.bad
     m.bad = lambda x,y: bad.append(x) or oldbad(x,y)
 
-    for f in repo.walk(m):
+    for f in repo.walk(m, missing=False):
         exact = m.exact(f)
         if exact or f not in repo.dirstate:
             names.append(f)
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -171,7 +171,7 @@
         n = self._repo.changelog.ancestor(self._node, n2)
         return changectx(self._repo, n)
 
-    def walk(self, match):
+    def walk(self, match, missing=True):
         fset = set(match.files())
         # for dirstate.walk, files=['.'] means "walk the whole tree".
         # follow that here, too
@@ -637,8 +637,12 @@
         """return the ancestor context of self and c2"""
         return self._parents[0].ancestor(c2) # punt on two parents for now
 
-    def walk(self, match):
-        return sorted(self._repo.dirstate.walk(match, True, False))
+    def walk(self, match, missing=True):
+        files = self._repo.dirstate.walk(match, True, False)
+        if missing:
+            return sorted(files)
+        else:
+            return sorted(k for k,v in files.iteritems() if v is not None)
 
     def dirty(self, missing=False):
         "check whether a working directory is modified"
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -952,13 +952,13 @@
         # tag cache retrieval" case to work.
         tags_.findglobaltags(self.ui, self, {}, {})
 
-    def walk(self, match, node=None):
+    def walk(self, match, node=None, missing=True):
         '''
         walk recursively through the directory tree or a given
         changeset, finding all files matched by the match
         function
         '''
-        return self[node].walk(match)
+        return self[node].walk(match, missing)
 
     def status(self, node1='.', node2=None, match=None,
                ignored=False, clean=False, unknown=False):
diff --git a/tests/test-rename-file-to-dir b/tests/test-rename-file-to-dir
new file mode 100755
--- /dev/null
+++ b/tests/test-rename-file-to-dir
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+hg init
+
+touch parent
+hg ci -Am"init"
+
+# now replace the file with a directory
+hg mv parent tmp
+mkdir parent
+
+# bug is here
+hg add parent
diff --git a/tests/test-rename-file-to-dir.out b/tests/test-rename-file-to-dir.out
new file mode 100644
--- /dev/null
+++ b/tests/test-rename-file-to-dir.out
@@ -0,0 +1,1 @@
+adding parent


More information about the Mercurial-devel mailing list