Patchwork [2,of,2] scmutil: move dirs() to pure/ - all "parsers" C extensions have it now

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 25, 2014, 1:38 a.m.
Message ID <854f8ca47e7a66612f7f.1408930696@localhost.localdomain>
Download mbox | patch
Permalink /patch/5594/
State Changes Requested
Headers show

Comments

Mads Kiilerich - Aug. 25, 2014, 1:38 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1408395237 -7200
#      Mon Aug 18 22:53:57 2014 +0200
# Node ID 854f8ca47e7a66612f7fb25d0203c090c694a07e
# Parent  8c8b4c31df719d1095e96efcd26be34079b074f6
scmutil: move dirs() to pure/ - all "parsers" C extensions have it now
Matt Mackall - Sept. 4, 2014, 7:58 p.m.
On Mon, 2014-08-25 at 03:38 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1408395237 -7200
> #      Mon Aug 18 22:53:57 2014 +0200
> # Node ID 854f8ca47e7a66612f7fb25d0203c090c694a07e
> # Parent  8c8b4c31df719d1095e96efcd26be34079b074f6
> scmutil: move dirs() to pure/ - all "parsers" C extensions have it now

Same probably applies here, though it's more complicated.

Patch

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -119,3 +119,39 @@  def pack_dirstate(dmap, copymap, pl, now
         write(e)
         write(f)
     return cs.getvalue()
+
+class dirs(object):
+    '''a multiset of directory names from a dirstate or manifest'''
+
+    def __init__(self, map, skip=None):
+        self._dirs = {}
+        addpath = self.addpath
+        if util.safehasattr(map, 'iteritems') and skip is not None:
+            for f, s in map.iteritems():
+                if s[0] != skip:
+                    addpath(f)
+        else:
+            for f in map:
+                addpath(f)
+
+    def addpath(self, path):
+        dirs = self._dirs
+        for base in util.finddirs(path):
+            if base in dirs:
+                dirs[base] += 1
+                return
+            dirs[base] = 1
+
+    def delpath(self, path):
+        dirs = self._dirs
+        for base in util.finddirs(path):
+            if dirs[base] > 1:
+                dirs[base] -= 1
+                return
+            del dirs[base]
+
+    def __iter__(self):
+        return self._dirs.iterkeys()
+
+    def __contains__(self, d):
+        return d in self._dirs
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -924,41 +924,4 @@  class filecache(object):
         except KeyError:
             raise AttributeError(self.name)
 
-class dirs(object):
-    '''a multiset of directory names from a dirstate or manifest'''
-
-    def __init__(self, map, skip=None):
-        self._dirs = {}
-        addpath = self.addpath
-        if util.safehasattr(map, 'iteritems') and skip is not None:
-            for f, s in map.iteritems():
-                if s[0] != skip:
-                    addpath(f)
-        else:
-            for f in map:
-                addpath(f)
-
-    def addpath(self, path):
-        dirs = self._dirs
-        for base in util.finddirs(path):
-            if base in dirs:
-                dirs[base] += 1
-                return
-            dirs[base] = 1
-
-    def delpath(self, path):
-        dirs = self._dirs
-        for base in util.finddirs(path):
-            if dirs[base] > 1:
-                dirs[base] -= 1
-                return
-            del dirs[base]
-
-    def __iter__(self):
-        return self._dirs.iterkeys()
-
-    def __contains__(self, d):
-        return d in self._dirs
-
-if util.safehasattr(parsers, 'dirs'):
-    dirs = parsers.dirs
+dirs = parsers.dirs