changeset 24551:4fdf5eac5b39

treemanifest: add treemanifest._isempty() During operations that involve building up a new manifest tree, it will be useful to be able to quickly check if a submanifest is empty, and if so, to avoid including it in the final tree. Doing this check lets us avoid creating treemanifest structures that contain any empty submanifests.
author Drew Gottlieb <drgott@google.com>
date Mon, 30 Mar 2015 17:21:49 -0700
parents 4daae7edf166
children a2292da6d821
files mercurial/manifest.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/manifest.py	Fri Mar 27 13:16:13 2015 -0700
+++ b/mercurial/manifest.py	Mon Mar 30 17:21:49 2015 -0700
@@ -370,6 +370,10 @@
             size += m.__len__()
         return size
 
+    def _isempty(self):
+        return (not self._files and (not self._dirs or
+                util.all(m._isempty() for m in self._dirs.values())))
+
     def __str__(self):
         return '<treemanifest dir=%s>' % self._dir
 
@@ -445,7 +449,7 @@
         if dir:
             self._dirs[dir].__delitem__(subpath)
             # If the directory is now empty, remove it
-            if not self._dirs[dir]._dirs and not self._dirs[dir]._files:
+            if self._dirs[dir]._isempty():
                 del self._dirs[dir]
         else:
             del self._files[f]