[PATCH] add: only retrieve from dirstate.walk files that do exist on the filesystem

Nicolas Dumazet nicdumz at gmail.com
Thu Dec 10 20:40:55 CST 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1260498662 -32400
# Node ID 4423def9e8ee48b373fd6253efef145cd32cdc1d
# Parent  2b630e4c8f2f626f1e5d0f88646463968860f8ac
add: only retrieve from dirstate.walk files that do exist on the filesystem

It does not make sense to match removed or missing files in this context.
It should suppress a bogus hg add warning when adding a directory over
a removed 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, existing_only=True):
         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, existing_only=False):
         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, existing_only=False):
+        files = self._repo.dirstate.walk(match, True, False)
+        if not existing_only:
+            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, existing_only=False):
         '''
         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, existing_only)
 
     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,15 @@
+#!/bin/sh
+
+hg init
+
+touch a
+hg ci -Aqm"init"
+hg rm a
+
+# now replace the file with a directory
+mkdir a b
+
+touch a/a b/b
+
+# bug is here
+hg add a b
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,2 @@
+adding a/a
+adding b/b


More information about the Mercurial-devel mailing list