/brz/remove-bazaar

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