diff options
author | Ian Clatworthy <ian.clatworthy@canonical.com> | 2009-08-23 21:06:02 +1000 |
---|---|---|
committer | Ian Clatworthy <ian.clatworthy@canonical.com> | 2009-08-23 21:06:02 +1000 |
commit | d3d86853d56b8b87f75a15ffbc8c72538d6eb72a (patch) | |
tree | 942acace6a7b217a99a9bdeed6782a89e0313d72 | |
parent | 682805c7a9890f09587be709e94fe3188a9f65f5 (diff) | |
download | bzr-fastimport-d3d86853d56b8b87f75a15ffbc8c72538d6eb72a.tar.gz |
Support an explicit output destination for bzr fast-export
-rw-r--r-- | __init__.py | 19 | ||||
-rwxr-xr-x | bzr_exporter.py | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/__init__.py b/__init__.py index 12dd4cc..8ba91fc 100644 --- a/__init__.py +++ b/__init__.py @@ -503,9 +503,14 @@ class cmd_fast_import_query(Command): class cmd_fast_export(Command): """Generate a fast-import stream from a Bazaar branch. - This program generates a stream from a bzr branch in the format required by - git-fast-import(1). It preserves merges correctly, even merged branches with - no common history (`bzr merge -r 0..-1`). + This program generates a stream from a bzr branch in the format + required by git-fast-import(1). It preserves merges correctly, + even merged branches with no common history (`bzr merge -r 0..-1`). + + If no destination is given or the destination is '-', standard output + is used. Otherwise, the destination is the name of a file. If the + destination ends in '.gz', the output will be compressed into gzip + format. :Examples: @@ -524,7 +529,7 @@ class cmd_fast_export(Command): """ hidden = False _see_also = ['fast-import', 'fast-import-filter'] - takes_args = ['source'] + takes_args = ['source', 'destination?'] takes_options = ['verbose', 'revision', Option('git-branch', short_name='b', type=str, argname='FILE', @@ -545,13 +550,15 @@ class cmd_fast_export(Command): ] aliases = [] encoding_type = 'exact' - def run(self, source, verbose=False, git_branch="master", checkpoint=10000, - marks=None, import_marks=None, export_marks=None, revision=None): + def run(self, source, destination=None, verbose=False, + git_branch="master", checkpoint=10000, marks=None, + import_marks=None, export_marks=None, revision=None): from bzrlib.plugins.fastimport import bzr_exporter if marks: import_marks = export_marks = marks exporter = bzr_exporter.BzrFastExporter(source, + destination=destination, git_branch=git_branch, checkpoint=checkpoint, import_marks_file=import_marks, export_marks_file=export_marks, revision=revision, verbose=verbose) diff --git a/bzr_exporter.py b/bzr_exporter.py index a1a46d1..38b7656 100755 --- a/bzr_exporter.py +++ b/bzr_exporter.py @@ -75,11 +75,17 @@ def _iter_linear_revisions(branch, start_rev_id, end_rev_id): class BzrFastExporter(object): - def __init__(self, source, git_branch=None, checkpoint=-1, + def __init__(self, source, destination, git_branch=None, checkpoint=-1, import_marks_file=None, export_marks_file=None, revision=None, verbose=False): self.source = source - self.outf = helpers.binary_stream(sys.stdout) + if destination is None or destination == '-': + self.outf = helpers.binary_stream(sys.stdout) + elif destination.endswith('gz'): + import gzip + self.outf = gzip.open(destination, 'wb') + else: + self.outf = open(destination, 'wb') self.git_branch = git_branch self.checkpoint = checkpoint self.import_marks_file = import_marks_file |