# HG changeset patch # User Drew Gottlieb # Date 1427761309 25200 # Node ID 4fdf5eac5b39b9137945c64e6f370be1bcb0d2ee # Parent 4daae7edf166b9b126d0dfee3d7b593b3b9d6586 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 -r 4daae7edf166 -r 4fdf5eac5b39 mercurial/manifest.py --- 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 '' % 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]