summaryrefslogtreecommitdiff
path: root/bzr_commit_handler.py
diff options
context:
space:
mode:
authorIan Clatworthy <ian.clatworthy@canonical.com>2009-08-21 23:30:20 +1000
committerIan Clatworthy <ian.clatworthy@canonical.com>2009-08-21 23:30:20 +1000
commitf4653bac45f74072da471c50e4ec2c930a9cabf3 (patch)
tree179c0cda58eb75489016fcb1d44c8a6fa9cf0197 /bzr_commit_handler.py
parent5911672b1a903fa954b2807533c61c09e6769279 (diff)
downloadbzr-fastimport-f4653bac45f74072da471c50e4ec2c930a9cabf3.tar.gz
test and fix for implicit directory delete recursing up
Diffstat (limited to 'bzr_commit_handler.py')
-rw-r--r--bzr_commit_handler.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/bzr_commit_handler.py b/bzr_commit_handler.py
index ae1f79a..23fe63e 100644
--- a/bzr_commit_handler.py
+++ b/bzr_commit_handler.py
@@ -575,11 +575,27 @@ class InventoryDeltaCommitHandler(GenericCommitHandler):
result = []
for dir in candidates:
file_id = new_inv.path2id(dir)
- children = new_inv[file_id].children
- if len(children) == 0:
+ ie = new_inv[file_id]
+ if len(ie.children) == 0:
+ result.append((dir, file_id))
if self.verbose:
self.note("pruning empty directory %s" % (dir,))
- result.append((dir, file_id))
+ # Check parents in case deleting this dir makes *them* empty
+ while True:
+ file_id = ie.parent_id
+ if file_id == inventory.ROOT_ID:
+ # We've reach the root
+ break
+ try:
+ ie = new_inv[file_id]
+ except errors.NoSuchId:
+ break
+ if len(ie.children) > 1:
+ break
+ dir = new_inv.id2path(file_id)
+ result.append((dir, file_id))
+ if self.verbose:
+ self.note("pruning empty directory parent %s" % (dir,))
return result
def _add_entry(self, entry):