[PATCH 3 of 4] treemanifest: add treemanifest._isempty()

Drew Gottlieb drgott at google.com
Tue Mar 31 17:29:13 CDT 2015


# HG changeset patch
# User Drew Gottlieb <drgott at google.com>
# Date 1427761309 25200
#      Mon Mar 30 17:21:49 2015 -0700
# Node ID 0a665bd18b18eb6a27e82475ad13810378637478
# Parent  3e59a573b043f2e39334347232bf9def2acba801
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.

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -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]


More information about the Mercurial-devel mailing list