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

login
register
mail settings
Submitter Drew Gottlieb
Date March 31, 2015, 10:29 p.m.
Message ID <0a665bd18b18eb6a27e8.1427840953@waste.org>
Download mbox | patch
Permalink /patch/8401/
State Accepted
Commit 4fdf5eac5b39b9137945c64e6f370be1bcb0d2ee
Headers show

Comments

Drew Gottlieb - March 31, 2015, 10:29 p.m.
# HG changeset patch
# User Drew Gottlieb <drgott@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.

Patch

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]