summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Reitter <david.reitter@gmail.com>2009-03-24 18:27:28 +0000
committerDavid Reitter <david.reitter@gmail.com>2009-03-24 18:27:28 +0000
commitb1531a1744dd4423e9cafdc857985de004f58758 (patch)
tree1241aace7496fad21fcdb7c3f75a172d397f882b
parentb464024dfbb8e1cea007c2fa395886c4c7db4d53 (diff)
downloadbzr-fastimport-b1531a1744dd4423e9cafdc857985de004f58758.tar.gz
fix bug #348038 (call to warning() with two arguments) and handle malformed revisions gracefully by not generating any output
-rwxr-xr-xbzr_exporter.py109
1 files changed, 56 insertions, 53 deletions
diff --git a/bzr_exporter.py b/bzr_exporter.py
index 76916d8..c9f07f2 100755
--- a/bzr_exporter.py
+++ b/bzr_exporter.py
@@ -195,64 +195,67 @@ class BzrFastExporter(object):
tree_new = self.branch.repository.revision_tree(revision_id)
except bazErrors.UnexpectedInventoryFormat:
# We can't really do anything anymore
- self.warning("Revision %s is malformed - skipping", revision_id)
+ self.warning("Revision %s is malformed - skipping" % revision_id)
return tree_old, tree_new
def _get_filecommands(self, parent, revision_id):
"""Get the list of FileCommands for the changes between two revisions."""
tree_old, tree_new = self._get_revision_trees(parent, revision_id)
- changes = tree_new.changes_from(tree_old)
-
- # Make "modified" have 3-tuples, as added does
- my_modified = [ x[0:3] for x in changes.modified ]
-
- # We have to keep track of previous renames in this commit
- file_cmds = []
- renamed = []
- for (oldpath, newpath, id_, kind,
- text_modified, meta_modified) in changes.renamed:
- if (self.is_empty_dir(tree_old, oldpath)):
- self.note("Skipping empty dir %s in rev %s" % (oldpath,
- revision_id))
- continue
- for old, new in renamed:
- # If a previous rename is found in this rename, we should
- # adjust the path
- if old in oldpath:
- oldpath = oldpath.replace(old + "/", new + "/")
- self.note("Fixing recursive rename for %s" % oldpath)
- renamed.append([oldpath, newpath])
- file_cmds.append(commands.FileRenameCommand(oldpath, newpath))
- if text_modified or meta_modified:
- my_modified.append((newpath, id_, kind))
-
- # Record deletes
- for path, id_, kind in changes.removed:
- for old, new in renamed:
- path = path.replace(old + "/", new + "/")
- file_cmds.append(commands.FileDeleteCommand(path))
-
- # Map kind changes to a delete followed by an add
- for path, id_, kind1, kind2 in changes.kind_changed:
- for old, new in renamed:
- path = path.replace(old + "/", new + "/")
- file_cmds.append(commands.FileDeleteCommand(path))
- my_modified.append((path, id_, kind2))
-
- # Record modifications
- for path, id_, kind in changes.added + my_modified:
- if kind == 'file':
- text = tree_new.get_file_text(id_)
- file_cmds.append(commands.FileModifyCommand(path, 'file',
- tree_new.is_executable(id_), None, text))
- elif kind == 'symlink':
- file_cmds.append(commands.FileModifyCommand(path, 'symlink',
- False, None, tree_new.get_symlink_target(id_)))
- else:
- # Should we do something here for importers that
- # can handle directory and tree-reference changes?
- continue
- return file_cmds
+ if tree_old and tree_new:
+ changes = tree_new.changes_from(tree_old)
+
+ # Make "modified" have 3-tuples, as added does
+ my_modified = [ x[0:3] for x in changes.modified ]
+
+ # We have to keep track of previous renames in this commit
+ file_cmds = []
+ renamed = []
+ for (oldpath, newpath, id_, kind,
+ text_modified, meta_modified) in changes.renamed:
+ if (self.is_empty_dir(tree_old, oldpath)):
+ self.note("Skipping empty dir %s in rev %s" % (oldpath,
+ revision_id))
+ continue
+ for old, new in renamed:
+ # If a previous rename is found in this rename, we should
+ # adjust the path
+ if old in oldpath:
+ oldpath = oldpath.replace(old + "/", new + "/")
+ self.note("Fixing recursive rename for %s" % oldpath)
+ renamed.append([oldpath, newpath])
+ file_cmds.append(commands.FileRenameCommand(oldpath, newpath))
+ if text_modified or meta_modified:
+ my_modified.append((newpath, id_, kind))
+
+ # Record deletes
+ for path, id_, kind in changes.removed:
+ for old, new in renamed:
+ path = path.replace(old + "/", new + "/")
+ file_cmds.append(commands.FileDeleteCommand(path))
+
+ # Map kind changes to a delete followed by an add
+ for path, id_, kind1, kind2 in changes.kind_changed:
+ for old, new in renamed:
+ path = path.replace(old + "/", new + "/")
+ file_cmds.append(commands.FileDeleteCommand(path))
+ my_modified.append((path, id_, kind2))
+
+ # Record modifications
+ for path, id_, kind in changes.added + my_modified:
+ if kind == 'file':
+ text = tree_new.get_file_text(id_)
+ file_cmds.append(commands.FileModifyCommand(path, 'file',
+ tree_new.is_executable(id_), None, text))
+ elif kind == 'symlink':
+ file_cmds.append(commands.FileModifyCommand(path, 'symlink',
+ False, None, tree_new.get_symlink_target(id_)))
+ else:
+ # Should we do something here for importers that
+ # can handle directory and tree-reference changes?
+ continue
+ return file_cmds
+ else:
+ return []
def emit_tags(self):
for tag, revid in self.branch.tags.get_tag_dict().items():