~vmiklos/bzr-fastimport/darcs

1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
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
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
17
r"""FastImport Plugin
18
=================
19
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
20
The fastimport plugin provides stream-based importing and exporting of
21
data into and out of Bazaar. As well as enabling interchange between
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
22
multiple VCS tools, fastimport/export can be useful for complex branch
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
23
operations, e.g. partitioning off part of a code base in order to Open
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
24
Source it.
25
26
The normal import recipe is::
27
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
28
  bzr fast-export-from-xxx SOURCE project.fi
205.2.2 by Ian Clatworthy
update help
29
  bzr fast-import project.fi project.bzr
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
30
31
If fast-export-from-xxx doesn't exist yet for the tool you're importing
32
from, the alternative recipe is::
33
34
  front-end > project.fi
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
35
  bzr fast-import project.fi project.bzr
36
37
In either case, if you wish to save disk space, project.fi can be
38
compressed to gzip format after it is generated like this::
39
40
  (generate project.fi)
41
  gzip project.fi
42
  bzr fast-import project.fi.gz project.bzr
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
43
44
The list of known front-ends and their status is documented on
45
http://bazaar-vcs.org/BzrFastImport/FrontEnds. The fast-export-from-xxx
46
commands provide simplified access to these so that the majority of users
47
can generate a fast-import dump file without needing to study up on all
48
the options - and the best combination of them to use - for the front-end
49
relevant to them. In some cases, a fast-export-from-xxx wrapper will require
50
that certain dependencies are installed so it checks for these before
51
starting. A wrapper may also provide a limited set of options. See the
52
online help for the individual commands for details::
53
205 by Ian Clatworthy
added fast-export-to-cvs
54
  bzr help fast-export-from-cvs
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
55
  bzr help fast-export-from-darcs
56
  bzr help fast-export-from-hg
57
  bzr help fast-export-from-git
205 by Ian Clatworthy
added fast-export-to-cvs
58
  bzr help fast-export-from-mnt
205.1.1 by Matt McClure
Adds a fast-export-from-p4 command.
59
  bzr help fast-export-from-p4
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
60
  bzr help fast-export-from-svn
61
62
Once a fast-import dump file is created, it can be imported into a
63
Bazaar repository using the fast-import command. If required, you can
64
manipulate the stream first using the fast-import-filter command.
65
This is useful for creating a repository with just part of a project
66
or for removing large old binaries (say) from history that are no longer
67
valuable to retain. For further details on importing, manipulating and
68
reporting on fast-import streams, see the online help for the commands::
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
69
70
  bzr help fast-import
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
71
  bzr help fast-import-filter
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
72
  bzr help fast-import-info
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
73
  bzr help fast-import-query
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
74
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
75
Finally, you may wish to generate a fast-import dump file from a Bazaar
76
repository. The fast-export command is provided for that purpose.
77
81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
78
To report bugs or publish enhancements, visit the bzr-fastimport project
79
page on Launchpad, https://launchpad.net/bzr-fastimport.
80
"""
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
81
185 by Ian Clatworthy
Open 0.9 development
82
version_info = (0, 9, 0, 'dev', 0)
126 by Ian Clatworthy
ensure version appears in bzr plugins output (Alexander Belchenko)
83
205.2.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
84
from bzrlib import bzrdir
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
85
from bzrlib.commands import Command, register_command
171 by Ian Clatworthy
use inv deltas by default for all formats now: --classic to get old algorithm for packs
86
from bzrlib.option import Option, ListOption, RegistryOption
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
87
88
89
def test_suite():
90
    import tests
91
    return tests.test_suite()
92
93
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
94
def _run(source, processor_factory, control, params, verbose,
95
    user_map=None):
38 by Ian Clatworthy
clean-up doc ready for initial release
96
    """Create and run a processor.
97
    
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
98
    :param source: a filename or '-' for standard input. If the
99
      filename ends in .gz, it will be opened as a gzip file and
100
      the stream will be implicitly uncompressed
38 by Ian Clatworthy
clean-up doc ready for initial release
101
    :param processor_factory: a callable for creating a processor
102
    :param control: the BzrDir of the destination or None if no
103
      destination is expected
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
104
    :param user_map: if not None, the file containing the user map.
38 by Ian Clatworthy
clean-up doc ready for initial release
105
    """
106
    import parser
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
107
    stream = _get_source_stream(source)
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
108
    user_mapper = _get_user_mapper(user_map)
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
109
    proc = processor_factory(control, params=params, verbose=verbose)
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
110
    p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
111
    return proc.process(p.iter_commands)
112
113
114
def _get_source_stream(source):
38 by Ian Clatworthy
clean-up doc ready for initial release
115
    if source == '-':
116
        import sys
136.1.2 by Ian Clatworthy
make sure fast-export uses a binary stream on Windows
117
        stream = helpers.binary_stream(sys.stdin)
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
118
    elif source.endswith('.gz'):
119
        import gzip
120
        stream = gzip.open(source, "rb")
38 by Ian Clatworthy
clean-up doc ready for initial release
121
    else:
55.1.6 by James Westby
Open the input in binary mode, as suggested by Paul Moore.
122
        stream = open(source, "rb")
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
123
    return stream
8 by Ian Clatworthy
custom parameters for processors
124
125
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
126
def _get_user_mapper(filename):
127
    import user_mapper
128
    if filename is None:
129
        return None
130
    f = open(filename)
131
    lines = f.readlines()
132
    f.close()
133
    return user_mapper.UserMapper(lines)
134
135
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
136
class cmd_fast_import(Command):
137
    """Backend for fast Bazaar data importers.
138
205.2.2 by Ian Clatworthy
update help
139
    This command reads a mixed command/data stream and creates
140
    branches in a Bazaar repository accordingly. The preferred
141
    recipe is::
142
143
      bzr fast-import project.fi project.bzr
144
145
    Numerous commands are provided for generating a fast-import file
146
    to use as input. These are named fast-export-from-xxx where xxx
147
    is one of cvs, darcs, git, hg, mnt, p4 or svn.
38 by Ian Clatworthy
clean-up doc ready for initial release
148
    To specify standard input as the input stream, use a
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
149
    source name of '-' (instead of project.fi). If the source name
150
    ends in '.gz', it is assumed to be compressed in gzip format.
205.2.2 by Ian Clatworthy
update help
151
    
152
    project.bzr will be created if it doesn't exist. If it exists
153
    already, it should be empty or be an existing Bazaar repository
154
    or branch. If not specified, the current directory is assumed.
155
 
156
    fast-import will intelligently select the format to use when
157
    creating a repository or branch. If you are running Bazaar 1.17
158
    up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
159
    Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
208 by Ian Clatworthy
minor doc tweaks
160
    is used. If you wish to specify a custom format, use the `--format`
205.2.2 by Ian Clatworthy
update help
161
    option.
162
163
     .. note::
164
     
165
        To maintain backwards compatibility, fast-import lets you
166
        create the target repository or standalone branch yourself.
167
        It is recommended though that you let fast-import create
168
        these for you instead.
169
170
    :Branch mapping rules:
171
172
     Git reference names are mapped to Bazaar branch names as follows:
128.1.1 by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names
173
      
205.2.2 by Ian Clatworthy
update help
174
     * refs/heads/foo is mapped to foo
175
     * refs/remotes/origin/foo is mapped to foo.remote
176
     * refs/tags/foo is mapped to foo.tag
177
     * */master is mapped to trunk, trunk.remote, etc.
178
     * */trunk is mapped to git-trunk, git-trunk.remote, etc.
179
180
    :Branch creation rules:
181
182
     When a shared repository is created or found at the destination,
183
     branches are created inside it. In the simple case of a single
184
     branch (refs/heads/master) inside the input file, the branch is
185
     project.bzr/trunk.
186
187
     When a standalone branch is found at the destination, the trunk
188
     is imported there and warnings are output about any other branches
189
     found in the input file.
190
191
     When a branch in a shared repository is found at the destination,
192
     that branch is made the trunk and other branches, if any, are
193
     created in sister directories.
194
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
195
    :Working tree updates:
196
197
     The working tree is generated for the trunk branch. If multiple
198
     branches are created, a message is output on completion explaining
199
     how to create the working trees for other branches.
200
205.2.2 by Ian Clatworthy
update help
201
    :Custom exporters:
202
203
     The fast-export-from-xxx commands typically call more advanced
204
     xxx-fast-export scripts. You are welcome to use the advanced
205
     scripts if you prefer.
206
207
     If you wish to write a custom exporter for your project, see
208
     http://bazaar-vcs.org/BzrFastImport for the detailed protocol
209
     specification. In many cases, exporters can be written quite
210
     quickly using whatever scripting/programming language you like.
211
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
212
    :User mapping:
213
214
     Some source repositories store just the user name while Bazaar
215
     prefers a full email address. You can adjust user-ids while
216
     importing by using the --user-map option. The argument is a
217
     text file with lines in the format::
218
219
       old-id = new-id
220
221
     Blank lines and lines beginning with # are ignored.
222
     If old-id has the special value '@', then users without an
223
     email address will get one created by using the matching new-id
224
     as the domain, unless a more explicit address is given for them.
225
     For example, given the user-map of::
226
227
       @ = example.com
228
       bill = William Jones <bill@example.com>
229
230
     then user-ids are mapped as follows::
231
     
232
      maria => maria <maria@example.com>
233
      bill => William Jones <bill@example.com>
234
235
     .. note::
236
     
237
        User mapping is supported by both the fast-import and
238
        fast-import-filter commands.
239
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
240
    :Blob tracking:
241
242
     As some exporters (like git-fast-export) reuse blob data across
243
     commits, fast-import makes two passes over the input file by
244
     default. In the first pass, it collects data about what blobs are
245
     used when, along with some other statistics (e.g. total number of
246
     commits). In the second pass, it generates the repository and
247
     branches.
248
     
249
     .. note::
250
     
251
        The initial pass isn't done if the --info option is used
252
        to explicitly pass in information about the input stream.
253
        It also isn't done if the source is standard input. In the
254
        latter case, memory consumption may be higher than otherwise
255
        because some blobs may be kept in memory longer than necessary.
205.2.2 by Ian Clatworthy
update help
256
257
    :Restarting an import:
258
259
     At checkpoints and on completion, the commit-id -> revision-id
260
     map is saved to a file called 'fastimport-id-map' in the control
261
     directory for the repository (e.g. .bzr/repository). If the import
262
     is interrupted or unexpectedly crashes, it can be started again
263
     and this file will be used to skip over already loaded revisions.
264
     As long as subsequent exports from the original source begin
265
     with exactly the same revisions, you can use this feature to
266
     maintain a mirror of a repository managed by a foreign tool.
267
     If and when Bazaar is used to manage the repository, this file
268
     can be safely deleted.
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
269
201 by Ian Clatworthy
tweak help formatting
270
    :Examples:
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
271
201 by Ian Clatworthy
tweak help formatting
272
     Import a Subversion repository into Bazaar::
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
273
274
       bzr fast-export-from-svn /svn/repo/path project.fi
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
275
       bzr fast-import project.fi project.bzr
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
276
205.2.2 by Ian Clatworthy
update help
277
     Import a CVS repository into Bazaar::
278
279
       bzr fast-export-from-cvs /cvs/repo/path project.fi
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
280
       bzr fast-import project.fi project.bzr
205.2.2 by Ian Clatworthy
update help
281
201 by Ian Clatworthy
tweak help formatting
282
     Import a Git repository into Bazaar::
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
283
284
       bzr fast-export-from-git /git/repo/path project.fi
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
285
       bzr fast-import project.fi project.bzr
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
286
201 by Ian Clatworthy
tweak help formatting
287
     Import a Mercurial repository into Bazaar::
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
288
289
       bzr fast-export-from-hg /hg/repo/path project.fi
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
290
       bzr fast-import project.fi project.bzr
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
291
201 by Ian Clatworthy
tweak help formatting
292
     Import a Darcs repository into Bazaar::
198.1.12 by Ian Clatworthy
NEWS item and doco tweaks
293
294
       bzr fast-export-from-darcs /darcs/repo/path project.fi
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
295
       bzr fast-import project.fi project.bzr
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
296
    """
120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
297
    hidden = False
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
298
    _see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
205.2.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
299
    takes_args = ['source', 'destination?']
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
300
    takes_options = ['verbose',
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
301
                    Option('user-map', type=str,
302
                        help="Path to file containing a map of user-ids.",
303
                        ),
38 by Ian Clatworthy
clean-up doc ready for initial release
304
                    Option('info', type=str,
305
                        help="Path to file containing caching hints.",
306
                        ),
307
                    Option('trees',
205.2.3 by Ian Clatworthy
Update the working tree for trunk implicitly
308
                        help="Update all working trees, not just trunk's.",
38 by Ian Clatworthy
clean-up doc ready for initial release
309
                        ),
310
                    Option('count', type=int,
311
                        help="Import this many revisions then exit.",
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
312
                        ),
170 by Ian Clatworthy
add autopack option to fast-import
313
                    Option('checkpoint', type=int,
314
                        help="Checkpoint automatically every N revisions."
315
                             " The default is 10000.",
316
                        ),
317
                    Option('autopack', type=int,
318
                        help="Pack every N checkpoints. The default is 4.",
319
                        ),
44 by Ian Clatworthy
smart caching of serialised inventories
320
                    Option('inv-cache', type=int,
321
                        help="Number of inventories to cache.",
322
                        ),
171 by Ian Clatworthy
use inv deltas by default for all formats now: --classic to get old algorithm for packs
323
                    RegistryOption.from_kwargs('mode',
324
                        'The import algorithm to use.',
325
                        title='Import Algorithm',
326
                        default='Use the preferred algorithm (inventory deltas).',
327
                        classic="Use the original algorithm (mutable inventories).",
328
                        experimental="Enable experimental features.",
329
                        value_switches=True, enum_switch=False,
47 by Ian Clatworthy
add option for enabling experimental stuff
330
                        ),
76.1.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
331
                    Option('import-marks', type=str,
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
332
                        help="Import marks from file."
333
                        ),
76.1.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
334
                    Option('export-marks', type=str,
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
335
                        help="Export marks to file."
336
                        ),
205.2.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
337
                    RegistryOption('format',
338
                            help='Specify a format for the created repository. See'
339
                                 ' "bzr help formats" for details.',
340
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
341
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
342
                            value_switches=False, title='Repository format'),
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
343
                     ]
38 by Ian Clatworthy
clean-up doc ready for initial release
344
    aliases = []
205.2.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
345
    def run(self, source, destination='.', verbose=False, info=None,
346
        trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
347
        mode=None, import_marks=None, export_marks=None, format=None,
348
        user_map=None):
135 by Ian Clatworthy
improve error message when .bzr directory not found
349
        from bzrlib.errors import BzrCommandError, NotBranchError
38 by Ian Clatworthy
clean-up doc ready for initial release
350
        from bzrlib.plugins.fastimport.processors import generic_processor
205.2.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
351
        from bzrlib.plugins.fastimport.helpers import (
352
            open_destination_directory,
353
            )
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
354
        # If no format is given and the user is running a release
355
        # leading up to 2.0, select 2a for them. Otherwise, use
356
        # the default format.
357
        if format is None:
358
            import bzrlib
359
            bzr_version = bzrlib.version_info[0:2]
360
            if bzr_version in [(1,17), (1,18), (2,0)]:
361
                format = bzrdir.format_registry.make_bzrdir('2a')
362
        control = open_destination_directory(destination, format=format)
363
364
        # If an information file was given and the source isn't stdin,
365
        # generate the information by reading the source file as a first pass
366
        if info is None and source != '-':
367
            info = self._generate_info(source)
368
369
        # Do the work
171 by Ian Clatworthy
use inv deltas by default for all formats now: --classic to get old algorithm for packs
370
        if mode is None:
371
            mode = 'default'
38 by Ian Clatworthy
clean-up doc ready for initial release
372
        params = {
373
            'info': info,
374
            'trees': trees,
170 by Ian Clatworthy
add autopack option to fast-import
375
            'count': count,
38 by Ian Clatworthy
clean-up doc ready for initial release
376
            'checkpoint': checkpoint,
170 by Ian Clatworthy
add autopack option to fast-import
377
            'autopack': autopack,
44 by Ian Clatworthy
smart caching of serialised inventories
378
            'inv-cache': inv_cache,
171 by Ian Clatworthy
use inv deltas by default for all formats now: --classic to get old algorithm for packs
379
            'mode': mode,
76.1.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
380
            'import-marks': import_marks,
381
            'export-marks': export_marks,
38 by Ian Clatworthy
clean-up doc ready for initial release
382
            }
383
        return _run(source, generic_processor.GenericProcessor, control,
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
384
            params, verbose, user_map=user_map)
38 by Ian Clatworthy
clean-up doc ready for initial release
385
213 by Ian Clatworthy
Smarter blob tracking by implicitly collecting statistics before starting the import
386
    def _generate_info(self, source):
387
        from cStringIO import StringIO
388
        import parser
389
        from bzrlib.plugins.fastimport.processors import info_processor
390
        stream = _get_source_stream(source)
391
        output = StringIO()
392
        try:
393
            proc = info_processor.InfoProcessor(verbose=True, outf=output)
394
            p = parser.ImportParser(stream)
395
            return_code = proc.process(p.iter_commands)
396
            lines = output.getvalue().splitlines()
397
        finally:
398
            output.close()
399
            stream.seek(0)
400
        return lines
401
38 by Ian Clatworthy
clean-up doc ready for initial release
402
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
403
class cmd_fast_import_filter(Command):
404
    """Filter a fast-import stream to include/exclude files & directories.
405
406
    This command is useful for splitting a subdirectory or bunch of
407
    files out from a project to create a new project complete with history
408
    for just those files. It can also be used to create a new project
409
    repository that removes all references to files that should not have
410
    been committed, e.g. security-related information (like passwords),
411
    commercially sensitive material, files with an incompatible license or
412
    large binary files like CD images.
413
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
414
    To specify standard input as the input stream, use a source name
415
    of '-'. If the source name ends in '.gz', it is assumed to be
416
    compressed in gzip format.
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
417
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
418
    :File/directory filtering:
419
420
     This is supported by the -i and -x options. Excludes take precedence
421
     over includes.
422
423
     When filtering out a subdirectory (or file), the new stream uses the
424
     subdirectory (or subdirectory containing the file) as the root. As
425
     fast-import doesn't know in advance whether a path is a file or
426
     directory in the stream, you need to specify a trailing '/' on
427
     directories passed to the `--includes option`. If multiple files or
428
     directories are given, the new root is the deepest common directory.
429
430
     Note: If a path has been renamed, take care to specify the *original*
431
     path name, not the final name that it ends up with.
432
433
    :User mapping:
434
435
     Some source repositories store just the user name while Bazaar
436
     prefers a full email address. You can adjust user-ids
437
     by using the --user-map option. The argument is a
438
     text file with lines in the format::
439
440
       old-id = new-id
441
442
     Blank lines and lines beginning with # are ignored.
443
     If old-id has the special value '@', then users without an
444
     email address will get one created by using the matching new-id
445
     as the domain, unless a more explicit address is given for them.
446
     For example, given the user-map of::
447
448
       @ = example.com
449
       bill = William Jones <bill@example.com>
450
451
     then user-ids are mapped as follows::
452
     
453
      maria => maria <maria@example.com>
454
      bill => William Jones <bill@example.com>
455
456
     .. note::
457
     
458
        User mapping is supported by both the fast-import and
459
        fast-import-filter commands.
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
460
201 by Ian Clatworthy
tweak help formatting
461
    :Examples:
462
463
     Create a new project from a library (note the trailing / on the
464
     directory name of the library)::
465
466
       front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
205.2.2 by Ian Clatworthy
update help
467
       bzr fast-import xxx.fi mylibrary.bzr
201 by Ian Clatworthy
tweak help formatting
468
       (lib/xxx/foo is now foo)
469
470
     Create a new repository without a sensitive file::
471
472
       front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
205.2.2 by Ian Clatworthy
update help
473
       bzr fast-import clean.fi clean.bzr
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
474
    """
475
    hidden = False
476
    _see_also = ['fast-import']
477
    takes_args = ['source']
478
    takes_options = ['verbose',
112.1.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
479
                    ListOption('include_paths', short_name='i', type=str,
480
                        help="Only include commits affecting these paths."
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
481
                             " Directories should have a trailing /."
482
                        ),
112.1.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
483
                    ListOption('exclude_paths', short_name='x', type=str,
484
                        help="Exclude these paths from commits."
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
485
                        ),
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
486
                    Option('user-map', type=str,
487
                        help="Path to file containing a map of user-ids.",
488
                        ),
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
489
                     ]
490
    aliases = []
112.1.17 by Alexander Belchenko
fast-import-filter should produce binary output.
491
    encoding_type = 'exact'
112.1.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
492
    def run(self, source, verbose=False, include_paths=None,
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
493
        exclude_paths=None, user_map=None):
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
494
        from bzrlib.plugins.fastimport.processors import filter_processor
495
        params = {
112.1.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
496
            'include_paths': include_paths,
497
            'exclude_paths': exclude_paths,
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
498
            }
499
        return _run(source, filter_processor.FilterProcessor, None, params,
252 by Ian Clatworthy
Add --user-map option to both fast-import and fast-import-filter
500
            verbose, user_map=user_map)
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
501
502
38 by Ian Clatworthy
clean-up doc ready for initial release
503
class cmd_fast_import_info(Command):
504
    """Output information about a fast-import stream.
505
506
    This command reads a fast-import stream and outputs
507
    statistics and interesting properties about what it finds.
508
    When run in verbose mode, the information is output as a
509
    configuration file that can be passed to fast-import to
510
    assist it in intelligently caching objects.
511
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
512
    To specify standard input as the input stream, use a source name
513
    of '-'. If the source name ends in '.gz', it is assumed to be
514
    compressed in gzip format.
38 by Ian Clatworthy
clean-up doc ready for initial release
515
201 by Ian Clatworthy
tweak help formatting
516
    :Examples:
517
518
     Display statistics about the import stream produced by front-end::
519
520
      front-end | bzr fast-import-info -
521
522
     Create a hints file for running fast-import on a large repository::
523
524
       front-end | bzr fast-import-info -v - > front-end.cfg
38 by Ian Clatworthy
clean-up doc ready for initial release
525
    """
120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
526
    hidden = False
38 by Ian Clatworthy
clean-up doc ready for initial release
527
    _see_also = ['fast-import']
528
    takes_args = ['source']
529
    takes_options = ['verbose']
530
    aliases = []
531
    def run(self, source, verbose=False):
532
        from bzrlib.plugins.fastimport.processors import info_processor
533
        return _run(source, info_processor.InfoProcessor, None, {}, verbose)
534
535
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
536
class cmd_fast_import_query(Command):
537
    """Query a fast-import stream displaying selected commands.
38 by Ian Clatworthy
clean-up doc ready for initial release
538
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
539
    To specify standard input as the input stream, use a source name
540
    of '-'. If the source name ends in '.gz', it is assumed to be
541
    compressed in gzip format.
542
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
543
    To specify a commit to display, give its mark using the
544
    --commit-mark option. The commit will be displayed with
545
    file-commands included but with inline blobs hidden.
546
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
547
    To specify the commands to display, use the -C option one or
548
    more times. To specify just some fields for a command, use the
549
    syntax::
38 by Ian Clatworthy
clean-up doc ready for initial release
550
551
      command=field1,...
552
553
    By default, the nominated fields for the nominated commands
554
    are displayed tab separated. To see the information in
555
    a name:value format, use verbose mode.
556
557
    Note: Binary fields (e.g. data for blobs) are masked out
558
    so it is generally safe to view the output in a terminal.
559
201 by Ian Clatworthy
tweak help formatting
560
    :Examples:
561
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
562
     Show the commit with mark 429::
563
564
      bzr fast-import-query xxx.fi -m429
565
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
566
     Show all the fields of the reset and tag commands::
38 by Ian Clatworthy
clean-up doc ready for initial release
567
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
568
      bzr fast-import-query xxx.fi -Creset -Ctag
38 by Ian Clatworthy
clean-up doc ready for initial release
569
211 by Ian Clatworthy
implicitly uncompress if a fast-import source ends in .gz
570
     Show the mark and merge fields of the commit commands::
38 by Ian Clatworthy
clean-up doc ready for initial release
571
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
572
      bzr fast-import-query xxx.fi -Ccommit=mark,merge
38 by Ian Clatworthy
clean-up doc ready for initial release
573
    """
574
    hidden = True
120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
575
    _see_also = ['fast-import', 'fast-import-filter']
38 by Ian Clatworthy
clean-up doc ready for initial release
576
    takes_args = ['source']
577
    takes_options = ['verbose',
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
578
                    Option('commit-mark', short_name='m', type=str,
579
                        help="Mark of the commit to display."
580
                        ),
38 by Ian Clatworthy
clean-up doc ready for initial release
581
                    ListOption('commands', short_name='C', type=str,
582
                        help="Display fields for these commands."
583
                        ),
584
                     ]
585
    aliases = []
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
586
    def run(self, source, verbose=False, commands=None, commit_mark=None):
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
587
        from bzrlib.plugins.fastimport.processors import query_processor
38 by Ian Clatworthy
clean-up doc ready for initial release
588
        from bzrlib.plugins.fastimport import helpers
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
589
        params = helpers.defines_to_dict(commands) or {}
590
        if commit_mark:
591
            params['commit-mark'] = commit_mark
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
592
        return _run(source, query_processor.QueryProcessor, None, params,
38 by Ian Clatworthy
clean-up doc ready for initial release
593
            verbose)
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
594
595
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
596
class cmd_fast_export(Command):
597
    """Generate a fast-import stream from a Bazaar branch.
598
229.1.12 by Ian Clatworthy
add --plain option to fast-export
599
    This program generates a stream from a Bazaar branch in fast-import
600
    format used by tools such as bzr fast-import, git-fast-import and
601
    hg-fast-import.
222 by Ian Clatworthy
Support an explicit output destination for bzr fast-export
602
603
    If no destination is given or the destination is '-', standard output
604
    is used. Otherwise, the destination is the name of a file. If the
605
    destination ends in '.gz', the output will be compressed into gzip
606
    format.
229.1.12 by Ian Clatworthy
add --plain option to fast-export
607
 
608
    :Round-tripping:
609
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
610
     Recent versions of the fast-import specification support features
229.1.12 by Ian Clatworthy
add --plain option to fast-export
611
     that allow effective round-tripping of many Bazaar branches. As
612
     such, fast-exporting a branch and fast-importing the data produced
613
     will create a new repository with equivalent history, i.e.
238 by Ian Clatworthy
--forward, not --reverse, in fast-export help
614
     "bzr log -v -p --include-merges --forward" on the old branch and
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
615
     new branch should produce similar, if not identical, results.
229.1.12 by Ian Clatworthy
add --plain option to fast-export
616
617
     .. note::
618
    
619
        Be aware that the new repository may appear to have similar history
620
        but internally it is quite different with new revision-ids and
621
        file-ids assigned. As a consequence, the ability to easily merge
622
        with branches based on the old repository is lost. Depending on your
623
        reasons for producing a new repository, this may or may not be an
624
        issue.
625
626
    :Interoperability:
627
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
628
     fast-export can use the following "extended features" to
229.1.12 by Ian Clatworthy
add --plain option to fast-export
629
     produce a richer data stream:
630
631
     * *multiple-authors* - if a commit has multiple authors (as commonly
632
       occurs in pair-programming), all authors will be included in the
633
       output, not just the first author
634
635
     * *commit-properties* - custom metadata per commit that Bazaar stores
636
       in revision properties (e.g. branch-nick and bugs fixed by this
637
       change) will be included in the output.
638
229.1.14 by Ian Clatworthy
export and import empty directories
639
     * *empty-directories* - directories, even the empty ones, will be
640
       included in the output.
641
229.1.12 by Ian Clatworthy
add --plain option to fast-export
642
     To disable these features and produce output acceptable to git 1.6,
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
643
     use the --plain option. To enable these features, use --no-plain.
644
     Currently, --plain is the default but that will change in the near
645
     future once the feature names and definitions are formally agreed
646
     to by the broader fast-import developer community.
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
647
201 by Ian Clatworthy
tweak help formatting
648
    :Examples:
649
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
650
     To produce data destined for import into Bazaar::
651
652
       bzr fast-export --no-plain my-bzr-branch my.fi.gz
653
654
     To produce data destined for Git 1.6::
655
656
       bzr fast-export --plain my-bzr-branch my.fi
657
201 by Ian Clatworthy
tweak help formatting
658
     To import several unmerged but related branches into the same repository,
659
     use the --{export,import}-marks options, and specify a name for the git
660
     branch like this::
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
661
    
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
662
       bzr fast-export --export-marks=marks.bzr project.dev |
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
663
              GIT_DIR=project/.git git-fast-import --export-marks=marks.git
664
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
665
       bzr fast-export --import-marks=marks.bzr -b other project.other |
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
666
              GIT_DIR=project/.git git-fast-import --import-marks=marks.git
117.1.10 by Ian Clatworthy
documentation clean-ups
667
201 by Ian Clatworthy
tweak help formatting
668
     If you get a "Missing space after source" error from git-fast-import,
669
     see the top of the commands.py module for a work-around.
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
670
    """
117.1.10 by Ian Clatworthy
documentation clean-ups
671
    hidden = False
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
672
    _see_also = ['fast-import', 'fast-import-filter']
222 by Ian Clatworthy
Support an explicit output destination for bzr fast-export
673
    takes_args = ['source', 'destination?']
173 by Ian Clatworthy
add -r option to fast-export
674
    takes_options = ['verbose', 'revision',
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
675
                    Option('git-branch', short_name='b', type=str,
676
                        argname='FILE',
677
                        help='Name of the git branch to create (default=master).'
678
                        ),
679
                    Option('checkpoint', type=int, argname='N',
173 by Ian Clatworthy
add -r option to fast-export
680
                        help="Checkpoint every N revisions (default=10000)."
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
681
                        ),
682
                    Option('marks', type=str, argname='FILE',
683
                        help="Import marks from and export marks to file."
684
                        ),
685
                    Option('import-marks', type=str, argname='FILE',
686
                        help="Import marks from file."
687
                        ),
688
                    Option('export-marks', type=str, argname='FILE',
689
                        help="Export marks to file."
690
                        ),
229.1.12 by Ian Clatworthy
add --plain option to fast-export
691
                    Option('plain',
692
                        help="Exclude metadata to maximise interoperability."
693
                        ),
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
694
                     ]
695
    aliases = []
162.1.1 by Alexander Belchenko
fast-export should force binary sys.stdout on win32
696
    encoding_type = 'exact'
222 by Ian Clatworthy
Support an explicit output destination for bzr fast-export
697
    def run(self, source, destination=None, verbose=False,
698
        git_branch="master", checkpoint=10000, marks=None,
229.1.12 by Ian Clatworthy
add --plain option to fast-export
699
        import_marks=None, export_marks=None, revision=None,
232 by Ian Clatworthy
Merge feature support including generation/parsing of commit-properties, multiple-authors and empty-directories
700
        plain=True):
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
701
        from bzrlib.plugins.fastimport import bzr_exporter
702
703
        if marks:                                              
704
            import_marks = export_marks = marks
705
        exporter = bzr_exporter.BzrFastExporter(source,
222 by Ian Clatworthy
Support an explicit output destination for bzr fast-export
706
            destination=destination,
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
707
            git_branch=git_branch, checkpoint=checkpoint,
173 by Ian Clatworthy
add -r option to fast-export
708
            import_marks_file=import_marks, export_marks_file=export_marks,
229.1.12 by Ian Clatworthy
add --plain option to fast-export
709
            revision=revision, verbose=verbose, plain_format=plain)
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
710
        return exporter.run()
711
712
205 by Ian Clatworthy
added fast-export-to-cvs
713
class cmd_fast_export_from_cvs(Command):
714
    """Generate a fast-import file from a CVS repository.
715
716
    Destination is a dump file, typically named xxx.fi where xxx is
717
    the name of the project. If '-' is given, standard output is used.
718
719
    cvs2svn 2.3 or later must be installed as its cvs2bzr script is used
210 by Ian Clatworthy
eliminate the reference to my temporary cvs2svn branch
720
    under the covers to do the export.
205 by Ian Clatworthy
added fast-export-to-cvs
721
    
722
    The source must be the path on your filesystem to the part of the
723
    repository you wish to convert. i.e. either that path or a parent
724
    directory must contain a CVSROOT subdirectory. The path may point to
725
    either the top of a repository or to a path within it. In the latter
726
    case, only that project within the repository will be converted.
727
728
    .. note::
729
       Remote access to the repository is not sufficient - the path
730
       must point into a copy of the repository itself. See
731
       http://cvs2svn.tigris.org/faq.html#repoaccess for instructions
732
       on how to clone a remote CVS repository locally.
733
734
    By default, the trunk, branches and tags are all exported. If you
208 by Ian Clatworthy
minor doc tweaks
735
    only want the trunk, use the `--trunk-only` option.
205 by Ian Clatworthy
added fast-export-to-cvs
736
737
    By default, filenames, log messages and author names are expected
208 by Ian Clatworthy
minor doc tweaks
738
    to be encoded in ascii. Use the `--encoding` option to specify an
205 by Ian Clatworthy
added fast-export-to-cvs
739
    alternative. If multiple encodings are used, specify the option
740
    multiple times. For a list of valid encoding names, see
741
    http://docs.python.org/lib/standard-encodings.html.
742
208 by Ian Clatworthy
minor doc tweaks
743
    Windows users need to install GNU sort and use the `--sort`
205 by Ian Clatworthy
added fast-export-to-cvs
744
    option to specify its location. GNU sort can be downloaded from
745
    http://unxutils.sourceforge.net/.
746
    """
747
    hidden = False
748
    _see_also = ['fast-import', 'fast-import-filter']
749
    takes_args = ['source', 'destination']
750
    takes_options = ['verbose',
751
                    Option('trunk-only',
752
                        help="Export just the trunk, ignoring tags and branches."
753
                        ),
754
                    ListOption('encoding', type=str, argname='CODEC',
755
                        help="Encoding used for filenames, commit messages "
756
                             "and author names if not ascii."
757
                        ),
758
                    Option('sort', type=str, argname='PATH',
759
                        help="GNU sort program location if not on the path."
760
                        ),
761
                    ]
762
    aliases = []
763
    encoding_type = 'exact'
764
    def run(self, source, destination, verbose=False, trunk_only=False,
765
        encoding=None, sort=None):
766
        from bzrlib.plugins.fastimport.exporters import fast_export_from
767
        custom = []
768
        if trunk_only:
769
            custom.append("--trunk-only")
770
        if encoding:
771
            for enc in encoding:
772
                custom.extend(['--encoding', enc])
773
        if sort:
774
            custom.extend(['--sort', sort])
775
        fast_export_from(source, destination, 'cvs', verbose, custom)
776
777
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
778
class cmd_fast_export_from_darcs(Command):
779
    """Generate a fast-import file from a Darcs repository.
780
202 by Ian Clatworthy
more help tweaks
781
    Destination is a dump file, typically named xxx.fi where xxx is
782
    the name of the project. If '-' is given, standard output is used.
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
783
784
    Darcs 2.2 or later must be installed as various subcommands are
785
    used to access the source repository. The source may be a network
786
    URL but using a local URL is recommended for performance reasons.
787
    """
788
    hidden = False
789
    _see_also = ['fast-import', 'fast-import-filter']
790
    takes_args = ['source', 'destination']
198.1.8 by Ian Clatworthy
add encoding option to fast-export-from-darcs
791
    takes_options = ['verbose',
792
                    Option('encoding', type=str, argname='CODEC',
793
                        help="Encoding used for commit messages if not utf-8."
794
                        ),
795
                    ]
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
796
    aliases = []
797
    encoding_type = 'exact'
198.1.8 by Ian Clatworthy
add encoding option to fast-export-from-darcs
798
    def run(self, source, destination, verbose=False, encoding=None):
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
799
        from bzrlib.plugins.fastimport.exporters import fast_export_from
198.1.8 by Ian Clatworthy
add encoding option to fast-export-from-darcs
800
        custom = None
801
        if encoding is not None:
802
            custom = ['--encoding', encoding]
803
        fast_export_from(source, destination, 'darcs', verbose, custom)
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
804
805
806
class cmd_fast_export_from_hg(Command):
807
    """Generate a fast-import file from a Mercurial repository.
808
202 by Ian Clatworthy
more help tweaks
809
    Destination is a dump file, typically named xxx.fi where xxx is
810
    the name of the project. If '-' is given, standard output is used.
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
811
812
    Mercurial 1.2 or later must be installed as its libraries are used
813
    to access the source repository. Given the APIs currently used,
814
    the source repository must be a local file, not a network URL.
815
    """
816
    hidden = False
817
    _see_also = ['fast-import', 'fast-import-filter']
818
    takes_args = ['source', 'destination']
819
    takes_options = ['verbose']
820
    aliases = []
821
    encoding_type = 'exact'
822
    def run(self, source, destination, verbose=False):
823
        from bzrlib.plugins.fastimport.exporters import fast_export_from
824
        fast_export_from(source, destination, 'hg', verbose)
825
826
827
class cmd_fast_export_from_git(Command):
828
    """Generate a fast-import file from a Git repository.
829
202 by Ian Clatworthy
more help tweaks
830
    Destination is a dump file, typically named xxx.fi where xxx is
831
    the name of the project. If '-' is given, standard output is used.
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
832
833
    Git 1.6 or later must be installed as the git fast-export
834
    subcommand is used under the covers to generate the stream.
198.1.3 by Ian Clatworthy
implement fast-export-from-git
835
    The source must be a local directory.
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
836
201 by Ian Clatworthy
tweak help formatting
837
    .. note::
838
    
839
       Earlier versions of Git may also work fine but are
840
       likely to receive less active support if problems arise.
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
841
    """
842
    hidden = False
843
    _see_also = ['fast-import', 'fast-import-filter']
844
    takes_args = ['source', 'destination']
845
    takes_options = ['verbose']
846
    aliases = []
847
    encoding_type = 'exact'
848
    def run(self, source, destination, verbose=False):
849
        from bzrlib.plugins.fastimport.exporters import fast_export_from
850
        fast_export_from(source, destination, 'git', verbose)
851
852
204 by Ian Clatworthy
added fast-export-from-mnt command
853
class cmd_fast_export_from_mnt(Command):
854
    """Generate a fast-import file from a Monotone repository.
855
856
    Destination is a dump file, typically named xxx.fi where xxx is
857
    the name of the project. If '-' is given, standard output is used.
858
859
    Monotone 0.43 or later must be installed as the mnt git_export
860
    subcommand is used under the covers to generate the stream.
861
    The source must be a local directory.
862
    """
863
    hidden = False
864
    _see_also = ['fast-import', 'fast-import-filter']
865
    takes_args = ['source', 'destination']
866
    takes_options = ['verbose']
867
    aliases = []
868
    encoding_type = 'exact'
869
    def run(self, source, destination, verbose=False):
870
        from bzrlib.plugins.fastimport.exporters import fast_export_from
871
        fast_export_from(source, destination, 'mnt', verbose)
872
873
205.1.1 by Matt McClure
Adds a fast-export-from-p4 command.
874
class cmd_fast_export_from_p4(Command):
875
    """Generate a fast-import file from a Perforce repository.
876
877
    Source is a Perforce depot path, e.g., //depot/project
878
879
    Destination is a dump file, typically named xxx.fi where xxx is
880
    the name of the project. If '-' is given, standard output is used.
881
882
    bzrp4 must be installed as its p4_fast_export.py module is used under
883
    the covers to do the export.  bzrp4 can be downloaded from
884
    https://launchpad.net/bzrp4/.
885
    
886
    The P4PORT environment variable must be set, and you must be logged
887
    into the Perforce server.
888
889
    By default, only the HEAD changelist is exported.  To export all
890
    changelists, append '@all' to the source.  To export a revision range,
891
    append a comma-delimited pair of changelist numbers to the source,
892
    e.g., '100,200'.
893
    """
894
    hidden = False
895
    _see_also = ['fast-import', 'fast-import-filter']
896
    takes_args = ['source', 'destination']
897
    takes_options = []
898
    aliases = []
899
    encoding_type = 'exact'
900
    def run(self, source, destination, verbose=False):
901
        from bzrlib.plugins.fastimport.exporters import fast_export_from
902
        custom = []
903
        fast_export_from(source, destination, 'p4', verbose, custom)
904
905
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
906
class cmd_fast_export_from_svn(Command):
907
    """Generate a fast-import file from a Subversion repository.
908
202 by Ian Clatworthy
more help tweaks
909
    Destination is a dump file, typically named xxx.fi where xxx is
910
    the name of the project. If '-' is given, standard output is used.
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
911
912
    Python-Subversion (Python bindings to the Subversion APIs)
913
    1.4 or later must be installed as this library is used to
914
    access the source repository. The source may be a network URL
915
    but using a local URL is recommended for performance reasons.
916
    """
917
    hidden = False
918
    _see_also = ['fast-import', 'fast-import-filter']
919
    takes_args = ['source', 'destination']
198.1.11 by Ian Clatworthy
initial cut at fast-export-from-svn
920
    takes_options = ['verbose',
921
                    Option('trunk-path', type=str, argname="STR",
922
                        help="Path in repo to /trunk.\n"
923
                              "May be `regex:/cvs/(trunk)/proj1/(.*)` in "
924
                              "which case the first group is used as the "
925
                              "branch name and the second group is used "
926
                              "to match files.",
927
                        ),
928
                    Option('branches-path', type=str, argname="STR",
929
                        help="Path in repo to /branches."
930
                        ),
931
                    Option('tags-path', type=str, argname="STR",
932
                        help="Path in repo to /tags."
933
                        ),
934
                    ]
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
935
    aliases = []
936
    encoding_type = 'exact'
198.1.11 by Ian Clatworthy
initial cut at fast-export-from-svn
937
    def run(self, source, destination, verbose=False, trunk_path=None,
938
        branches_path=None, tags_path=None):
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
939
        from bzrlib.plugins.fastimport.exporters import fast_export_from
198.1.11 by Ian Clatworthy
initial cut at fast-export-from-svn
940
        custom = []
941
        if trunk_path is not None:
942
            custom.extend(['--trunk-path', trunk_path])
943
        if branches_path is not None:
944
            custom.extend(['--branches-path', branches_path])
945
        if tags_path is not None:
946
            custom.extend(['--tags-path', tags_path])
947
        fast_export_from(source, destination, 'svn', verbose, custom)
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
948
949
1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
950
register_command(cmd_fast_import)
112.1.1 by Ian Clatworthy
initial cut at fast-import-filter
951
register_command(cmd_fast_import_filter)
38 by Ian Clatworthy
clean-up doc ready for initial release
952
register_command(cmd_fast_import_info)
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
953
register_command(cmd_fast_import_query)
117.1.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
954
register_command(cmd_fast_export)
205 by Ian Clatworthy
added fast-export-to-cvs
955
register_command(cmd_fast_export_from_cvs)
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
956
register_command(cmd_fast_export_from_darcs)
957
register_command(cmd_fast_export_from_hg)
958
register_command(cmd_fast_export_from_git)
204 by Ian Clatworthy
added fast-export-from-mnt command
959
register_command(cmd_fast_export_from_mnt)
205.1.1 by Matt McClure
Adds a fast-export-from-p4 command.
960
register_command(cmd_fast_export_from_p4)
198.1.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
961
register_command(cmd_fast_export_from_svn)