/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
0.64.334 by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan.
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
15
16
"""Fastimport/fastexport commands."""
17
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
18
from __future__ import absolute_import
19
6658.5.2 by Jelmer Vernooij
Remove breezy.bzrdir.format_registry.
20
from ... import controldir
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
21
from ...commands import Command
22
from ...option import Option, ListOption, RegistryOption
6808 by Jelmer Vernooij
merge lp:~jelmer/brz/options-unicode/
23
from ...sixish import (
24
    text_type,
25
    )
26
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
27
28
from . import (
0.139.1 by Jelmer Vernooij
Import helper functions that have been removed from python-fastimport.
29
    helpers,
30
    load_fastimport,
31
    )
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
32
33
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
34
def _run(source, processor_factory, verbose=False, user_map=None, **kwargs):
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
35
    """Create and run a processor.
36
37
    :param source: a filename or '-' for standard input. If the
38
      filename ends in .gz, it will be opened as a gzip file and
39
      the stream will be implicitly uncompressed
40
    :param processor_factory: a callable for creating a processor
41
    :param user_map: if not None, the file containing the user map.
42
    """
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
43
    from fastimport.errors import ParsingError
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
44
    from ...errors import BzrCommandError
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
45
    from fastimport import parser
46
    stream = _get_source_stream(source)
47
    user_mapper = _get_user_mapper(user_map)
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
48
    proc = processor_factory(verbose=verbose, **kwargs)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
49
    p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
50
    try:
51
        return proc.process(p.iter_commands)
6754.5.1 by Jelmer Vernooij
Fix some python3 compatibility issues that break 'make check-nodocs3' for me.
52
    except ParsingError as e:
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
53
        raise BzrCommandError("%d: Parse error: %s" % (e.lineno, e))
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
54
55
56
def _get_source_stream(source):
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
57
    if source == '-' or source is None:
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
58
        import sys
59
        stream = helpers.binary_stream(sys.stdin)
60
    elif source.endswith('.gz'):
61
        import gzip
62
        stream = gzip.open(source, "rb")
63
    else:
64
        stream = open(source, "rb")
65
    return stream
66
67
68
def _get_user_mapper(filename):
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
69
    from . import user_mapper
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
70
    if filename is None:
71
        return None
72
    f = open(filename)
73
    lines = f.readlines()
74
    f.close()
75
    return user_mapper.UserMapper(lines)
76
77
78
class cmd_fast_import(Command):
79
    """Backend for fast Bazaar data importers.
80
81
    This command reads a mixed command/data stream and creates
82
    branches in a Bazaar repository accordingly. The preferred
83
    recipe is::
84
85
      bzr fast-import project.fi project.bzr
86
87
    Numerous commands are provided for generating a fast-import file
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
88
    to use as input. 
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
89
    To specify standard input as the input stream, use a
90
    source name of '-' (instead of project.fi). If the source name
91
    ends in '.gz', it is assumed to be compressed in gzip format.
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
92
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
93
    project.bzr will be created if it doesn't exist. If it exists
94
    already, it should be empty or be an existing Bazaar repository
95
    or branch. If not specified, the current directory is assumed.
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
96
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
97
    fast-import will intelligently select the format to use when
98
    creating a repository or branch. If you are running Bazaar 1.17
99
    up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
100
    Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
101
    is used. If you wish to specify a custom format, use the `--format`
102
    option.
103
104
     .. note::
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
105
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
106
        To maintain backwards compatibility, fast-import lets you
107
        create the target repository or standalone branch yourself.
108
        It is recommended though that you let fast-import create
109
        these for you instead.
110
111
    :Branch mapping rules:
112
113
     Git reference names are mapped to Bazaar branch names as follows:
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
114
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
115
     * refs/heads/foo is mapped to foo
116
     * refs/remotes/origin/foo is mapped to foo.remote
117
     * refs/tags/foo is mapped to foo.tag
118
     * */master is mapped to trunk, trunk.remote, etc.
119
     * */trunk is mapped to git-trunk, git-trunk.remote, etc.
120
121
    :Branch creation rules:
122
123
     When a shared repository is created or found at the destination,
124
     branches are created inside it. In the simple case of a single
125
     branch (refs/heads/master) inside the input file, the branch is
126
     project.bzr/trunk.
127
128
     When a standalone branch is found at the destination, the trunk
129
     is imported there and warnings are output about any other branches
130
     found in the input file.
131
132
     When a branch in a shared repository is found at the destination,
133
     that branch is made the trunk and other branches, if any, are
134
     created in sister directories.
135
136
    :Working tree updates:
137
138
     The working tree is generated for the trunk branch. If multiple
139
     branches are created, a message is output on completion explaining
140
     how to create the working trees for other branches.
141
142
    :Custom exporters:
143
144
     The fast-export-from-xxx commands typically call more advanced
145
     xxx-fast-export scripts. You are welcome to use the advanced
146
     scripts if you prefer.
147
148
     If you wish to write a custom exporter for your project, see
149
     http://bazaar-vcs.org/BzrFastImport for the detailed protocol
150
     specification. In many cases, exporters can be written quite
151
     quickly using whatever scripting/programming language you like.
152
153
    :User mapping:
154
155
     Some source repositories store just the user name while Bazaar
156
     prefers a full email address. You can adjust user-ids while
157
     importing by using the --user-map option. The argument is a
158
     text file with lines in the format::
159
160
       old-id = new-id
161
162
     Blank lines and lines beginning with # are ignored.
163
     If old-id has the special value '@', then users without an
164
     email address will get one created by using the matching new-id
165
     as the domain, unless a more explicit address is given for them.
166
     For example, given the user-map of::
167
168
       @ = example.com
169
       bill = William Jones <bill@example.com>
170
171
     then user-ids are mapped as follows::
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
172
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
173
      maria => maria <maria@example.com>
174
      bill => William Jones <bill@example.com>
175
176
     .. note::
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
177
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
178
        User mapping is supported by both the fast-import and
179
        fast-import-filter commands.
180
181
    :Blob tracking:
182
183
     As some exporters (like git-fast-export) reuse blob data across
184
     commits, fast-import makes two passes over the input file by
185
     default. In the first pass, it collects data about what blobs are
186
     used when, along with some other statistics (e.g. total number of
187
     commits). In the second pass, it generates the repository and
188
     branches.
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
189
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
190
     .. note::
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
191
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
192
        The initial pass isn't done if the --info option is used
193
        to explicitly pass in information about the input stream.
194
        It also isn't done if the source is standard input. In the
195
        latter case, memory consumption may be higher than otherwise
196
        because some blobs may be kept in memory longer than necessary.
197
198
    :Restarting an import:
199
200
     At checkpoints and on completion, the commit-id -> revision-id
201
     map is saved to a file called 'fastimport-id-map' in the control
202
     directory for the repository (e.g. .bzr/repository). If the import
203
     is interrupted or unexpectedly crashes, it can be started again
204
     and this file will be used to skip over already loaded revisions.
205
     As long as subsequent exports from the original source begin
206
     with exactly the same revisions, you can use this feature to
207
     maintain a mirror of a repository managed by a foreign tool.
208
     If and when Bazaar is used to manage the repository, this file
209
     can be safely deleted.
210
211
    :Examples:
212
213
     Import a Subversion repository into Bazaar::
214
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
215
       svn-fast-export /svn/repo/path > project.fi
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
216
       bzr fast-import project.fi project.bzr
217
218
     Import a CVS repository into Bazaar::
219
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
220
       cvs2git /cvs/repo/path > project.fi
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
221
       bzr fast-import project.fi project.bzr
222
223
     Import a Git repository into Bazaar::
224
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
225
       cd /git/repo/path
226
       git fast-export --all > project.fi
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
227
       bzr fast-import project.fi project.bzr
228
229
     Import a Mercurial repository into Bazaar::
230
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
231
       cd /hg/repo/path
232
       hg fast-export > project.fi
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
233
       bzr fast-import project.fi project.bzr
234
235
     Import a Darcs repository into Bazaar::
236
0.136.2 by Jelmer Vernooij
remove more references to fast-export-from-*.
237
       cd /darcs/repo/path
238
       darcs-fast-export > project.fi
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
239
       bzr fast-import project.fi project.bzr
240
    """
241
    hidden = False
242
    _see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
243
    takes_args = ['source', 'destination?']
244
    takes_options = ['verbose',
6805.1.2 by Jelmer Vernooij
Text type.
245
                    Option('user-map', type=text_type,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
246
                        help="Path to file containing a map of user-ids.",
247
                        ),
6805.1.2 by Jelmer Vernooij
Text type.
248
                    Option('info', type=text_type,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
249
                        help="Path to file containing caching hints.",
250
                        ),
251
                    Option('trees',
252
                        help="Update all working trees, not just trunk's.",
253
                        ),
254
                    Option('count', type=int,
255
                        help="Import this many revisions then exit.",
256
                        ),
257
                    Option('checkpoint', type=int,
258
                        help="Checkpoint automatically every N revisions."
259
                             " The default is 10000.",
260
                        ),
261
                    Option('autopack', type=int,
262
                        help="Pack every N checkpoints. The default is 4.",
263
                        ),
264
                    Option('inv-cache', type=int,
265
                        help="Number of inventories to cache.",
266
                        ),
267
                    RegistryOption.from_kwargs('mode',
268
                        'The import algorithm to use.',
269
                        title='Import Algorithm',
270
                        default='Use the preferred algorithm (inventory deltas).',
271
                        classic="Use the original algorithm (mutable inventories).",
272
                        experimental="Enable experimental features.",
273
                        value_switches=True, enum_switch=False,
274
                        ),
6805.1.2 by Jelmer Vernooij
Text type.
275
                    Option('import-marks', type=text_type,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
276
                        help="Import marks from file."
277
                        ),
6805.1.2 by Jelmer Vernooij
Text type.
278
                    Option('export-marks', type=text_type,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
279
                        help="Export marks to file."
280
                        ),
281
                    RegistryOption('format',
282
                            help='Specify a format for the created repository. See'
283
                                 ' "bzr help formats" for details.',
6658.5.2 by Jelmer Vernooij
Remove breezy.bzrdir.format_registry.
284
                            lazy_registry=('breezy.controldir', 'format_registry'),
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
285
                            converter=lambda name: controldir.format_registry.make_controldir(name),
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
286
                            value_switches=False, title='Repository format'),
287
                     ]
288
    def run(self, source, destination='.', verbose=False, info=None,
289
        trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
290
        mode=None, import_marks=None, export_marks=None, format=None,
291
        user_map=None):
292
        load_fastimport()
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
293
        from .processors import generic_processor
294
        from .helpers import (
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
295
            open_destination_directory,
296
            )
297
        control = open_destination_directory(destination, format=format)
298
299
        # If an information file was given and the source isn't stdin,
300
        # generate the information by reading the source file as a first pass
301
        if info is None and source != '-':
302
            info = self._generate_info(source)
303
304
        # Do the work
305
        if mode is None:
306
            mode = 'default'
307
        params = {
308
            'info': info,
309
            'trees': trees,
310
            'count': count,
311
            'checkpoint': checkpoint,
312
            'autopack': autopack,
313
            'inv-cache': inv_cache,
314
            'mode': mode,
315
            'import-marks': import_marks,
316
            'export-marks': export_marks,
317
            }
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
318
        return _run(source, generic_processor.GenericProcessor,
0.131.2 by Jelmer Vernooij
Fix 'bzr fast-import' bzrdir argument and add a blackbox test.
319
                bzrdir=control, params=params, verbose=verbose,
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
320
                user_map=user_map)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
321
322
    def _generate_info(self, source):
6791.2.3 by Jelmer Vernooij
Fix more imports.
323
        from ...sixish import StringIO
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
324
        from fastimport import parser
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
325
        from fastimport.errors import ParsingError
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
326
        from ...errors import BzrCommandError
6929.13.2 by Jelmer Vernooij
Remove functionality moved to fastimport.
327
        from fastimport.processors import info_processor
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
328
        stream = _get_source_stream(source)
329
        output = StringIO()
330
        try:
331
            proc = info_processor.InfoProcessor(verbose=True, outf=output)
332
            p = parser.ImportParser(stream)
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
333
            try:
334
                return_code = proc.process(p.iter_commands)
6754.5.1 by Jelmer Vernooij
Fix some python3 compatibility issues that break 'make check-nodocs3' for me.
335
            except ParsingError as e:
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
336
                raise BzrCommandError("%d: Parse error: %s" % (e.lineno, e))
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
337
            lines = output.getvalue().splitlines()
338
        finally:
339
            output.close()
340
            stream.seek(0)
341
        return lines
342
343
344
class cmd_fast_export(Command):
345
    """Generate a fast-import stream from a Bazaar branch.
346
347
    This program generates a stream from a Bazaar branch in fast-import
348
    format used by tools such as bzr fast-import, git-fast-import and
349
    hg-fast-import.
350
0.64.351 by Jelmer Vernooij
Document the SOURCE argument for ``bzr fast-export``.
351
    It takes two optional arguments: the source bzr branch to export and
352
    the destination to write the file to write the fastimport stream to.
353
354
    If no source is specified, it will search for a branch in the
355
    current directory.
356
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
357
    If no destination is given or the destination is '-', standard output
358
    is used. Otherwise, the destination is the name of a file. If the
359
    destination ends in '.gz', the output will be compressed into gzip
360
    format.
0.64.351 by Jelmer Vernooij
Document the SOURCE argument for ``bzr fast-export``.
361
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
362
    :Round-tripping:
363
364
     Recent versions of the fast-import specification support features
0.64.341 by Jelmer Vernooij
Fix test, clarify help description for 'bzr fast-export'.
365
     that allow effective round-tripping most of the metadata in Bazaar
366
     branches. As such, fast-exporting a branch and fast-importing the data
367
     produced will create a new repository with roughly equivalent history, i.e.
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
368
     "bzr log -v -p --include-merges --forward" on the old branch and
369
     new branch should produce similar, if not identical, results.
370
371
     .. note::
0.64.351 by Jelmer Vernooij
Document the SOURCE argument for ``bzr fast-export``.
372
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
373
        Be aware that the new repository may appear to have similar history
374
        but internally it is quite different with new revision-ids and
375
        file-ids assigned. As a consequence, the ability to easily merge
376
        with branches based on the old repository is lost. Depending on your
377
        reasons for producing a new repository, this may or may not be an
378
        issue.
379
380
    :Interoperability:
381
382
     fast-export can use the following "extended features" to
383
     produce a richer data stream:
384
385
     * *multiple-authors* - if a commit has multiple authors (as commonly
386
       occurs in pair-programming), all authors will be included in the
387
       output, not just the first author
388
389
     * *commit-properties* - custom metadata per commit that Bazaar stores
390
       in revision properties (e.g. branch-nick and bugs fixed by this
391
       change) will be included in the output.
392
393
     * *empty-directories* - directories, even the empty ones, will be
394
       included in the output.
395
396
     To disable these features and produce output acceptable to git 1.6,
397
     use the --plain option. To enable these features, use --no-plain.
398
     Currently, --plain is the default but that will change in the near
399
     future once the feature names and definitions are formally agreed
400
     to by the broader fast-import developer community.
401
0.64.337 by Jelmer Vernooij
Merge support for --rewrite-tag-names.
402
     Git has stricter naming rules for tags and fast-export --plain
403
     will skip tags which can't be imported into git. To replace characters
404
     unsupported in git with an underscore instead, specify
405
     --rewrite-tag-names.
406
0.135.1 by Andy Grimm
Add --baseline option
407
    :History truncation:
408
0.64.341 by Jelmer Vernooij
Fix test, clarify help description for 'bzr fast-export'.
409
     It is sometimes convenient to simply truncate the revision history at a
410
     certain point.  The --baseline option, to be used in conjunction with -r,
411
     emits a baseline commit containing the state of the entire source tree at
412
     the first requested revision.  This allows a user to produce a tree
413
     identical to the original without munging multiple exports.
0.135.1 by Andy Grimm
Add --baseline option
414
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
415
    :Examples:
416
417
     To produce data destined for import into Bazaar::
418
419
       bzr fast-export --no-plain my-bzr-branch my.fi.gz
420
421
     To produce data destined for Git 1.6::
422
423
       bzr fast-export --plain my-bzr-branch my.fi
424
425
     To import several unmerged but related branches into the same repository,
426
     use the --{export,import}-marks options, and specify a name for the git
427
     branch like this::
0.64.356 by Jelmer Vernooij
Remove trailing whitespace.
428
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
429
       bzr fast-export --export-marks=marks.bzr project.dev |
430
              GIT_DIR=project/.git git-fast-import --export-marks=marks.git
431
432
       bzr fast-export --import-marks=marks.bzr -b other project.other |
433
              GIT_DIR=project/.git git-fast-import --import-marks=marks.git
434
435
     If you get a "Missing space after source" error from git-fast-import,
436
     see the top of the commands.py module for a work-around.
0.64.359 by Richard Wilbur
Add NEWS entries for recent changes and additional documentation for new option.(Richard Wilbur)
437
438
     Since bzr uses per-branch tags and git/hg use per-repo tags, the
439
     way bzr fast-export presently emits tags (unconditional reset &
440
     new ref) may result in clashes when several different branches
441
     are imported into single git/hg repo.  If this occurs, use the
442
     bzr fast-export option --no-tags during the export of one or more
443
     branches to avoid the issue.
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
444
    """
445
    hidden = False
446
    _see_also = ['fast-import', 'fast-import-filter']
0.64.351 by Jelmer Vernooij
Document the SOURCE argument for ``bzr fast-export``.
447
    takes_args = ['source?', 'destination?']
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
448
    takes_options = ['verbose', 'revision',
6805.1.2 by Jelmer Vernooij
Text type.
449
                    Option('git-branch', short_name='b', type=text_type,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
450
                        argname='FILE',
451
                        help='Name of the git branch to create (default=master).'
452
                        ),
453
                    Option('checkpoint', type=int, argname='N',
454
                        help="Checkpoint every N revisions (default=10000)."
455
                        ),
6805.1.2 by Jelmer Vernooij
Text type.
456
                    Option('marks', type=text_type, argname='FILE',
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
457
                        help="Import marks from and export marks to file."
458
                        ),
6805.1.2 by Jelmer Vernooij
Text type.
459
                    Option('import-marks', type=text_type, argname='FILE',
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
460
                        help="Import marks from file."
461
                        ),
6805.1.2 by Jelmer Vernooij
Text type.
462
                    Option('export-marks', type=text_type, argname='FILE',
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
463
                        help="Export marks to file."
464
                        ),
465
                    Option('plain',
466
                        help="Exclude metadata to maximise interoperability."
467
                        ),
0.133.2 by Oleksandr Usov
Rewrite tag names when exporting plain stream
468
                    Option('rewrite-tag-names',
0.64.337 by Jelmer Vernooij
Merge support for --rewrite-tag-names.
469
                        help="Replace characters invalid in git with '_'"
470
                             " (plain mode only).",
0.133.2 by Oleksandr Usov
Rewrite tag names when exporting plain stream
471
                        ),
0.135.1 by Andy Grimm
Add --baseline option
472
                    Option('baseline',
0.135.2 by Andy Grimm
fix --baseline bugs, and add a couple of tests
473
                        help="Export an 'absolute' baseline commit prior to"
0.135.1 by Andy Grimm
Add --baseline option
474
                             "the first relative commit",
475
                        ),
0.138.1 by Oleksandr Usov
Add --no-tags flag
476
                    Option('no-tags',
477
                        help="Don't export tags"
478
                        ),
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
479
                     ]
480
    encoding_type = 'exact'
0.64.351 by Jelmer Vernooij
Document the SOURCE argument for ``bzr fast-export``.
481
    def run(self, source=None, destination=None, verbose=False,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
482
        git_branch="master", checkpoint=10000, marks=None,
483
        import_marks=None, export_marks=None, revision=None,
0.138.1 by Oleksandr Usov
Add --no-tags flag
484
        plain=True, rewrite_tag_names=False, no_tags=False, baseline=False):
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
485
        load_fastimport()
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
486
        from ...branch import Branch
487
        from . import exporter
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
488
489
        if marks:
490
            import_marks = export_marks = marks
0.64.339 by Jelmer Vernooij
Some refactoring of exporter.
491
492
        # Open the source
0.64.351 by Jelmer Vernooij
Document the SOURCE argument for ``bzr fast-export``.
493
        if source is None:
494
            source = "."
0.64.339 by Jelmer Vernooij
Some refactoring of exporter.
495
        branch = Branch.open_containing(source)[0]
496
        outf = exporter._get_output_stream(destination)
497
        exporter = exporter.BzrFastExporter(branch,
0.64.350 by Jelmer Vernooij
Rename git_branch to ref.
498
            outf=outf, ref="refs/heads/%s" % git_branch, checkpoint=checkpoint,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
499
            import_marks_file=import_marks, export_marks_file=export_marks,
0.133.2 by Oleksandr Usov
Rewrite tag names when exporting plain stream
500
            revision=revision, verbose=verbose, plain_format=plain,
0.138.1 by Oleksandr Usov
Add --no-tags flag
501
            rewrite_tags=rewrite_tag_names, no_tags=no_tags, baseline=baseline)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
502
        return exporter.run()