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