Patchwork [4,of,6] treemanifest: store directory path in treemanifest nodes

login
register
mail settings
Submitter Martin von Zweigbergk
Date March 11, 2015, 4:23 a.m.
Message ID <d388050f8756d028c597.1426047816@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7997/
State Superseded
Commit 0e23faa1511c9a456e651b6cf0dfa3b40edff41d
Headers show

Comments

Martin von Zweigbergk - March 11, 2015, 4:23 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1424717877 28800
#      Mon Feb 23 10:57:57 2015 -0800
# Node ID d388050f8756d028c5975cf8cc744a9cfe816632
# Parent  34ad94f42d39e9ad3e7a7b8695f419bc2ff8b37f
treemanifest: store directory path in treemanifest nodes

This leads to less concatenation while iterating, and it's useful for
debugging.

Patch

diff -r 34ad94f42d39 -r d388050f8756 mercurial/manifest.py
--- a/mercurial/manifest.py	Mon Mar 09 12:57:56 2015 -0700
+++ b/mercurial/manifest.py	Mon Feb 23 10:57:57 2015 -0800
@@ -319,7 +319,8 @@ 
         return '', f
 
 class treemanifest(object):
-    def __init__(self, text=''):
+    def __init__(self, dir='', text=''):
+        self._dir = dir
         self._dirs = {}
         self._files = {}
         self._flags = {}
@@ -329,27 +330,33 @@ 
             if mfdict.flags(f):
                 self.setflag(f, mfdict.flags(f))
 
+    def _subpath(self, path):
+        return self._dir + path
+
     def __len__(self):
         size = len(self._files)
         for m in self._dirs.values():
             size += m.__len__()
         return size
 
+    def __str__(self):
+        return '<treemanifest dir=%s>' % self._dir
+
     def iteritems(self):
         for p, n in sorted(self._dirs.items() + self._files.items()):
             if p in self._files:
-                yield p, n
+                yield self._subpath(p), n
             else:
-                for sf, sn in n.iteritems():
-                    yield p + sf, sn
+                for f, sn in n.iteritems():
+                    yield f, sn
 
     def iterkeys(self):
         for p in sorted(self._dirs.keys() + self._files.keys()):
             if p in self._files:
-                yield p
+                yield self._subpath(p)
             else:
                 for f in self._dirs[p].iterkeys():
-                    yield p + f
+                    yield f
 
     def keys(self):
         return list(self.iterkeys())
@@ -418,7 +425,7 @@ 
         dir, subpath = _splittopdir(f)
         if dir:
             if dir not in self._dirs:
-                self._dirs[dir] = treemanifest()
+                self._dirs[dir] = treemanifest(self._subpath(dir))
             self._dirs[dir].__setitem__(subpath, n)
         else:
             self._files[f] = n
@@ -428,13 +435,13 @@ 
         dir, subpath = _splittopdir(f)
         if dir:
             if dir not in self._dirs:
-                self._dirs[dir] = treemanifest()
+                self._dirs[dir] = treemanifest(self._subpath(dir))
             self._dirs[dir].setflag(subpath, flags)
         else:
             self._flags[f] = flags
 
     def copy(self):
-        copy = treemanifest()
+        copy = treemanifest(self._dir)
         for d in self._dirs:
             copy._dirs[d] = self._dirs[d].copy()
         copy._files = dict.copy(self._files)
@@ -538,7 +545,7 @@ 
 
     def _newmanifest(self, data=''):
         if self._usetreemanifest:
-            return treemanifest(data)
+            return treemanifest('', data)
         return manifestdict(data)
 
     def readdelta(self, node):