/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.95.2 by Ian Clatworthy
update help
35
  bzr fast-import project.fi project.fi
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
36
37
The list of known front-ends and their status is documented on
38
http://bazaar-vcs.org/BzrFastImport/FrontEnds. The fast-export-from-xxx
39
commands provide simplified access to these so that the majority of users
40
can generate a fast-import dump file without needing to study up on all
41
the options - and the best combination of them to use - for the front-end
42
relevant to them. In some cases, a fast-export-from-xxx wrapper will require
43
that certain dependencies are installed so it checks for these before
44
starting. A wrapper may also provide a limited set of options. See the
45
online help for the individual commands for details::
46
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
47
  bzr help fast-export-from-cvs
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
48
  bzr help fast-export-from-darcs
49
  bzr help fast-export-from-hg
50
  bzr help fast-export-from-git
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
51
  bzr help fast-export-from-mnt
0.94.1 by Matt McClure
Adds a fast-export-from-p4 command.
52
  bzr help fast-export-from-p4
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
53
  bzr help fast-export-from-svn
54
55
Once a fast-import dump file is created, it can be imported into a
56
Bazaar repository using the fast-import command. If required, you can
57
manipulate the stream first using the fast-import-filter command.
58
This is useful for creating a repository with just part of a project
59
or for removing large old binaries (say) from history that are no longer
60
valuable to retain. For further details on importing, manipulating and
61
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
62
63
  bzr help fast-import
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
64
  bzr help fast-import-filter
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
65
  bzr help fast-import-info
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
66
  bzr help fast-import-query
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
67
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
68
Finally, you may wish to generate a fast-import dump file from a Bazaar
69
repository. The fast-export command is provided for that purpose.
70
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
71
To report bugs or publish enhancements, visit the bzr-fastimport project
72
page on Launchpad, https://launchpad.net/bzr-fastimport.
73
"""
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
74
0.64.185 by Ian Clatworthy
Open 0.9 development
75
version_info = (0, 9, 0, 'dev', 0)
0.64.126 by Ian Clatworthy
ensure version appears in bzr plugins output (Alexander Belchenko)
76
0.95.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
77
from bzrlib import bzrdir
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
78
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
79
from bzrlib.option import Option, ListOption, RegistryOption
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
80
81
82
def test_suite():
83
    import tests
84
    return tests.test_suite()
85
86
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
87
def _run(source, processor_factory, control, params, verbose):
88
    """Create and run a processor.
89
    
90
    :param source: a filename or '-' for standard input
91
    :param processor_factory: a callable for creating a processor
92
    :param control: the BzrDir of the destination or None if no
93
      destination is expected
94
    """
95
    import parser
96
    if source == '-':
97
        import sys
0.84.2 by Ian Clatworthy
make sure fast-export uses a binary stream on Windows
98
        stream = helpers.binary_stream(sys.stdin)
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
99
    else:
0.65.6 by James Westby
Open the input in binary mode, as suggested by Paul Moore.
100
        stream = open(source, "rb")
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
101
    proc = processor_factory(control, params=params, verbose=verbose)
102
    p = parser.ImportParser(stream, verbose=verbose)
103
    return proc.process(p.iter_commands)
0.64.8 by Ian Clatworthy
custom parameters for processors
104
105
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
106
class cmd_fast_import(Command):
107
    """Backend for fast Bazaar data importers.
108
0.95.2 by Ian Clatworthy
update help
109
    This command reads a mixed command/data stream and creates
110
    branches in a Bazaar repository accordingly. The preferred
111
    recipe is::
112
113
      bzr fast-import project.fi project.bzr
114
115
    Numerous commands are provided for generating a fast-import file
116
    to use as input. These are named fast-export-from-xxx where xxx
117
    is one of cvs, darcs, git, hg, mnt, p4 or svn.
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
118
    To specify standard input as the input stream, use a
0.95.2 by Ian Clatworthy
update help
119
    source name of '-' (instead of project.fi).
120
    
121
    project.bzr will be created if it doesn't exist. If it exists
122
    already, it should be empty or be an existing Bazaar repository
123
    or branch. If not specified, the current directory is assumed.
124
 
125
    fast-import will intelligently select the format to use when
126
    creating a repository or branch. If you are running Bazaar 1.17
127
    up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
128
    Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
0.64.208 by Ian Clatworthy
minor doc tweaks
129
    is used. If you wish to specify a custom format, use the `--format`
0.95.2 by Ian Clatworthy
update help
130
    option.
131
132
     .. note::
133
     
134
        To maintain backwards compatibility, fast-import lets you
135
        create the target repository or standalone branch yourself.
136
        It is recommended though that you let fast-import create
137
        these for you instead.
138
139
    :Branch mapping rules:
140
141
     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
142
      
0.95.2 by Ian Clatworthy
update help
143
     * refs/heads/foo is mapped to foo
144
     * refs/remotes/origin/foo is mapped to foo.remote
145
     * refs/tags/foo is mapped to foo.tag
146
     * */master is mapped to trunk, trunk.remote, etc.
147
     * */trunk is mapped to git-trunk, git-trunk.remote, etc.
148
149
    :Branch creation rules:
150
151
     When a shared repository is created or found at the destination,
152
     branches are created inside it. In the simple case of a single
153
     branch (refs/heads/master) inside the input file, the branch is
154
     project.bzr/trunk.
155
156
     When a standalone branch is found at the destination, the trunk
157
     is imported there and warnings are output about any other branches
158
     found in the input file.
159
160
     When a branch in a shared repository is found at the destination,
161
     that branch is made the trunk and other branches, if any, are
162
     created in sister directories.
163
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
164
    :Working tree updates:
165
166
     The working tree is generated for the trunk branch. If multiple
167
     branches are created, a message is output on completion explaining
168
     how to create the working trees for other branches.
169
0.95.2 by Ian Clatworthy
update help
170
    :Custom exporters:
171
172
     The fast-export-from-xxx commands typically call more advanced
173
     xxx-fast-export scripts. You are welcome to use the advanced
174
     scripts if you prefer.
175
176
     If you wish to write a custom exporter for your project, see
177
     http://bazaar-vcs.org/BzrFastImport for the detailed protocol
178
     specification. In many cases, exporters can be written quite
179
     quickly using whatever scripting/programming language you like.
180
181
    :Reducing memory usage:
182
183
     A slightly more complex recipe is required when importing large
184
     projects via exporters (like fast-export-from-git and
185
     git-fast-export) that reuse blob data across commits.
186
     The recipe is::
187
188
       bzr fast-import-info -v xxx.fi > xxx.cfg
189
       bzr fast-import xxx.fi --info xxx.cfg xxx.bzr
190
191
     In this scenario, the xxx.cfg file generated by the first pass
192
     holds caching hints that the second pass uses to lower memory
193
     usage. Development is planned so that this recipe becomes obsolete
194
     in the future, i.e. so that the simple recipe always works.
195
196
    :Restarting an import:
197
198
     At checkpoints and on completion, the commit-id -> revision-id
199
     map is saved to a file called 'fastimport-id-map' in the control
200
     directory for the repository (e.g. .bzr/repository). If the import
201
     is interrupted or unexpectedly crashes, it can be started again
202
     and this file will be used to skip over already loaded revisions.
203
     As long as subsequent exports from the original source begin
204
     with exactly the same revisions, you can use this feature to
205
     maintain a mirror of a repository managed by a foreign tool.
206
     If and when Bazaar is used to manage the repository, this file
207
     can be safely deleted.
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
208
0.64.201 by Ian Clatworthy
tweak help formatting
209
    :Examples:
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
210
0.64.201 by Ian Clatworthy
tweak help formatting
211
     Import a Subversion repository into Bazaar::
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
212
213
       bzr fast-export-from-svn /svn/repo/path project.fi
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
214
       bzr fast-import project.fi project.bzr
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
215
0.95.2 by Ian Clatworthy
update help
216
     Import a CVS repository into Bazaar::
217
218
       bzr fast-export-from-cvs /cvs/repo/path project.fi
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
219
       bzr fast-import project.fi project.bzr
0.95.2 by Ian Clatworthy
update help
220
0.64.201 by Ian Clatworthy
tweak help formatting
221
     Import a Git repository into Bazaar::
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
222
223
       bzr fast-export-from-git /git/repo/path project.fi
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
224
       bzr fast-import project.fi project.bzr
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
225
0.64.201 by Ian Clatworthy
tweak help formatting
226
     Import a Mercurial repository into Bazaar::
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
227
228
       bzr fast-export-from-hg /hg/repo/path project.fi
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
229
       bzr fast-import project.fi project.bzr
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
230
0.64.201 by Ian Clatworthy
tweak help formatting
231
     Import a Darcs repository into Bazaar::
0.93.12 by Ian Clatworthy
NEWS item and doco tweaks
232
233
       bzr fast-export-from-darcs /darcs/repo/path project.fi
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
234
       bzr fast-import project.fi project.bzr
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
235
    """
0.64.120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
236
    hidden = False
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
237
    _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
238
    takes_args = ['source', 'destination?']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
239
    takes_options = ['verbose',
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
240
                    Option('info', type=str,
241
                        help="Path to file containing caching hints.",
242
                        ),
243
                    Option('trees',
0.95.3 by Ian Clatworthy
Update the working tree for trunk implicitly
244
                        help="Update all working trees, not just trunk's.",
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
245
                        ),
246
                    Option('count', type=int,
247
                        help="Import this many revisions then exit.",
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
248
                        ),
0.64.170 by Ian Clatworthy
add autopack option to fast-import
249
                    Option('checkpoint', type=int,
250
                        help="Checkpoint automatically every N revisions."
251
                             " The default is 10000.",
252
                        ),
253
                    Option('autopack', type=int,
254
                        help="Pack every N checkpoints. The default is 4.",
255
                        ),
0.64.44 by Ian Clatworthy
smart caching of serialised inventories
256
                    Option('inv-cache', type=int,
257
                        help="Number of inventories to cache.",
258
                        ),
0.64.171 by Ian Clatworthy
use inv deltas by default for all formats now: --classic to get old algorithm for packs
259
                    RegistryOption.from_kwargs('mode',
260
                        'The import algorithm to use.',
261
                        title='Import Algorithm',
262
                        default='Use the preferred algorithm (inventory deltas).',
263
                        classic="Use the original algorithm (mutable inventories).",
264
                        experimental="Enable experimental features.",
265
                        value_switches=True, enum_switch=False,
0.64.47 by Ian Clatworthy
add option for enabling experimental stuff
266
                        ),
0.68.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
267
                    Option('import-marks', type=str,
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
268
                        help="Import marks from file."
269
                        ),
0.68.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
270
                    Option('export-marks', type=str,
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
271
                        help="Export marks to file."
272
                        ),
0.95.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
273
                    RegistryOption('format',
274
                            help='Specify a format for the created repository. See'
275
                                 ' "bzr help formats" for details.',
276
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
277
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
278
                            value_switches=False, title='Repository format'),
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
279
                     ]
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
280
    aliases = []
0.95.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
281
    def run(self, source, destination='.', verbose=False, info=None,
282
        trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
283
        mode=None, import_marks=None, export_marks=None, format=None):
0.64.135 by Ian Clatworthy
improve error message when .bzr directory not found
284
        from bzrlib.errors import BzrCommandError, NotBranchError
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
285
        from bzrlib.plugins.fastimport.processors import generic_processor
0.95.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
286
        from bzrlib.plugins.fastimport.helpers import (
287
            open_destination_directory,
288
            )
0.64.171 by Ian Clatworthy
use inv deltas by default for all formats now: --classic to get old algorithm for packs
289
        if mode is None:
290
            mode = 'default'
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
291
        params = {
292
            'info': info,
293
            'trees': trees,
0.64.170 by Ian Clatworthy
add autopack option to fast-import
294
            'count': count,
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
295
            'checkpoint': checkpoint,
0.64.170 by Ian Clatworthy
add autopack option to fast-import
296
            'autopack': autopack,
0.64.44 by Ian Clatworthy
smart caching of serialised inventories
297
            '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
298
            'mode': mode,
0.68.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
299
            'import-marks': import_marks,
300
            'export-marks': export_marks,
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
301
            }
0.95.1 by Ian Clatworthy
Create a repository implicitly if one doesn't already exist
302
        # If no format is given and the user is running a release
303
        # leading up to 2.0, select 2a for them. Otherwise, use
304
        # the default format.
305
        if format is None:
306
            import bzrlib
307
            bzr_version = bzrlib.version_info[0:2]
308
            if bzr_version in [(1,17), (1,18), (2,0)]:
309
                format = bzrdir.format_registry.make_bzrdir('2a')
310
        control = open_destination_directory(destination, format=format)
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
311
        return _run(source, generic_processor.GenericProcessor, control,
312
            params, verbose)
313
314
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
315
class cmd_fast_import_filter(Command):
316
    """Filter a fast-import stream to include/exclude files & directories.
317
318
    This command is useful for splitting a subdirectory or bunch of
319
    files out from a project to create a new project complete with history
320
    for just those files. It can also be used to create a new project
321
    repository that removes all references to files that should not have
322
    been committed, e.g. security-related information (like passwords),
323
    commercially sensitive material, files with an incompatible license or
324
    large binary files like CD images.
325
326
    When filtering out a subdirectory (or file), the new stream uses the
327
    subdirectory (or subdirectory containing the file) as the root. As
328
    fast-import doesn't know in advance whether a path is a file or
329
    directory in the stream, you need to specify a trailing '/' on
0.64.208 by Ian Clatworthy
minor doc tweaks
330
    directories passed to the `--includes option`. If multiple files or
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
331
    directories are given, the new root is the deepest common directory.
332
333
    To specify standard input as the input stream, use a source
334
    name of '-'.
335
336
    Note: If a path has been renamed, take care to specify the *original*
337
    path name, not the final name that it ends up with.
338
0.64.201 by Ian Clatworthy
tweak help formatting
339
    :Examples:
340
341
     Create a new project from a library (note the trailing / on the
342
     directory name of the library)::
343
344
       front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
0.95.2 by Ian Clatworthy
update help
345
       bzr fast-import xxx.fi mylibrary.bzr
0.64.201 by Ian Clatworthy
tweak help formatting
346
       (lib/xxx/foo is now foo)
347
348
     Create a new repository without a sensitive file::
349
350
       front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
0.95.2 by Ian Clatworthy
update help
351
       bzr fast-import clean.fi clean.bzr
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
352
    """
353
    hidden = False
354
    _see_also = ['fast-import']
355
    takes_args = ['source']
356
    takes_options = ['verbose',
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
357
                    ListOption('include_paths', short_name='i', type=str,
358
                        help="Only include commits affecting these paths."
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
359
                             " Directories should have a trailing /."
360
                        ),
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
361
                    ListOption('exclude_paths', short_name='x', type=str,
362
                        help="Exclude these paths from commits."
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
363
                        ),
364
                     ]
365
    aliases = []
0.77.17 by Alexander Belchenko
fast-import-filter should produce binary output.
366
    encoding_type = 'exact'
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
367
    def run(self, source, verbose=False, include_paths=None,
368
        exclude_paths=None):
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
369
        from bzrlib.plugins.fastimport.processors import filter_processor
370
        params = {
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
371
            'include_paths': include_paths,
372
            'exclude_paths': exclude_paths,
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
373
            }
374
        return _run(source, filter_processor.FilterProcessor, None, params,
375
            verbose)
376
377
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
378
class cmd_fast_import_info(Command):
379
    """Output information about a fast-import stream.
380
381
    This command reads a fast-import stream and outputs
382
    statistics and interesting properties about what it finds.
383
    When run in verbose mode, the information is output as a
384
    configuration file that can be passed to fast-import to
385
    assist it in intelligently caching objects.
386
387
    To specify standard input as the input stream, use a source
388
    name of '-'.
389
0.64.201 by Ian Clatworthy
tweak help formatting
390
    :Examples:
391
392
     Display statistics about the import stream produced by front-end::
393
394
      front-end | bzr fast-import-info -
395
396
     Create a hints file for running fast-import on a large repository::
397
398
       front-end | bzr fast-import-info -v - > front-end.cfg
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
399
    """
0.64.120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
400
    hidden = False
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
401
    _see_also = ['fast-import']
402
    takes_args = ['source']
403
    takes_options = ['verbose']
404
    aliases = []
405
    def run(self, source, verbose=False):
406
        from bzrlib.plugins.fastimport.processors import info_processor
407
        return _run(source, info_processor.InfoProcessor, None, {}, verbose)
408
409
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
410
class cmd_fast_import_query(Command):
411
    """Query a fast-import stream displaying selected commands.
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
412
413
    To specify standard input as the input stream, use a source
414
    name of '-'. To specify the commands to display, use the -C
415
    option one or more times. To specify just some fields for
416
    a command, use the syntax::
417
418
      command=field1,...
419
420
    By default, the nominated fields for the nominated commands
421
    are displayed tab separated. To see the information in
422
    a name:value format, use verbose mode.
423
424
    Note: Binary fields (e.g. data for blobs) are masked out
425
    so it is generally safe to view the output in a terminal.
426
0.64.201 by Ian Clatworthy
tweak help formatting
427
    :Examples:
428
429
    Show all the fields of the reset and tag commands::
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
430
431
      front-end > xxx.fi
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
432
      bzr fast-import-query xxx.fi -Creset -Ctag
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
433
0.64.201 by Ian Clatworthy
tweak help formatting
434
    Show the mark and merge fields of the commit commands::
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
435
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
436
      bzr fast-import-query xxx.fi -Ccommit=mark,merge
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
437
    """
438
    hidden = True
0.64.120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
439
    _see_also = ['fast-import', 'fast-import-filter']
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
440
    takes_args = ['source']
441
    takes_options = ['verbose',
442
                    ListOption('commands', short_name='C', type=str,
443
                        help="Display fields for these commands."
444
                        ),
445
                     ]
446
    aliases = []
447
    def run(self, source, verbose=False, commands=None):
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
448
        from bzrlib.plugins.fastimport.processors import query_processor
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
449
        from bzrlib.plugins.fastimport import helpers
450
        params = helpers.defines_to_dict(commands)
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
451
        return _run(source, query_processor.QueryProcessor, None, params,
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
452
            verbose)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
453
454
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
455
class cmd_fast_export(Command):
456
    """Generate a fast-import stream from a Bazaar branch.
457
458
    This program generates a stream from a bzr branch in the format required by
459
    git-fast-import(1). It preserves merges correctly, even merged branches with
460
    no common history (`bzr merge -r 0..-1`).
461
0.64.201 by Ian Clatworthy
tweak help formatting
462
    :Examples:
463
464
     To import several unmerged but related branches into the same repository,
465
     use the --{export,import}-marks options, and specify a name for the git
466
     branch like this::
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
467
    
0.64.201 by Ian Clatworthy
tweak help formatting
468
      bzr fast-export --export-marks=marks.bzr project.dev |
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
469
              GIT_DIR=project/.git git-fast-import --export-marks=marks.git
470
0.64.201 by Ian Clatworthy
tweak help formatting
471
      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
472
              GIT_DIR=project/.git git-fast-import --import-marks=marks.git
0.79.10 by Ian Clatworthy
documentation clean-ups
473
0.64.201 by Ian Clatworthy
tweak help formatting
474
     If you get a "Missing space after source" error from git-fast-import,
475
     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
476
    """
0.79.10 by Ian Clatworthy
documentation clean-ups
477
    hidden = False
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
478
    _see_also = ['fast-import', 'fast-import-filter']
479
    takes_args = ['source']
0.64.173 by Ian Clatworthy
add -r option to fast-export
480
    takes_options = ['verbose', 'revision',
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
481
                    Option('git-branch', short_name='b', type=str,
482
                        argname='FILE',
483
                        help='Name of the git branch to create (default=master).'
484
                        ),
485
                    Option('checkpoint', type=int, argname='N',
0.64.173 by Ian Clatworthy
add -r option to fast-export
486
                        help="Checkpoint every N revisions (default=10000)."
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
487
                        ),
488
                    Option('marks', type=str, argname='FILE',
489
                        help="Import marks from and export marks to file."
490
                        ),
491
                    Option('import-marks', type=str, argname='FILE',
492
                        help="Import marks from file."
493
                        ),
494
                    Option('export-marks', type=str, argname='FILE',
495
                        help="Export marks to file."
496
                        ),
497
                     ]
498
    aliases = []
0.86.1 by Alexander Belchenko
fast-export should force binary sys.stdout on win32
499
    encoding_type = 'exact'
0.64.173 by Ian Clatworthy
add -r option to fast-export
500
    def run(self, source, verbose=False, git_branch="master", checkpoint=10000,
501
        marks=None, import_marks=None, export_marks=None, revision=None):
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
502
        from bzrlib.plugins.fastimport import bzr_exporter
503
504
        if marks:                                              
505
            import_marks = export_marks = marks
506
        exporter = bzr_exporter.BzrFastExporter(source,
507
            git_branch=git_branch, checkpoint=checkpoint,
0.64.173 by Ian Clatworthy
add -r option to fast-export
508
            import_marks_file=import_marks, export_marks_file=export_marks,
0.64.176 by Ian Clatworthy
faster export of revision range & improved diagnostics in fast-export
509
            revision=revision, verbose=verbose)
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
510
        return exporter.run()
511
512
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
513
class cmd_fast_export_from_cvs(Command):
514
    """Generate a fast-import file from a CVS repository.
515
516
    Destination is a dump file, typically named xxx.fi where xxx is
517
    the name of the project. If '-' is given, standard output is used.
518
519
    cvs2svn 2.3 or later must be installed as its cvs2bzr script is used
520
    under the covers to do the export. (If cvs2bzr is not included in
521
    cvs2svn yet, grab the branch from
522
    https://code.launchpad.net/~ian-clatworthy/+junk/cvs2svn and use it.)
523
    
524
    The source must be the path on your filesystem to the part of the
525
    repository you wish to convert. i.e. either that path or a parent
526
    directory must contain a CVSROOT subdirectory. The path may point to
527
    either the top of a repository or to a path within it. In the latter
528
    case, only that project within the repository will be converted.
529
530
    .. note::
531
       Remote access to the repository is not sufficient - the path
532
       must point into a copy of the repository itself. See
533
       http://cvs2svn.tigris.org/faq.html#repoaccess for instructions
534
       on how to clone a remote CVS repository locally.
535
536
    By default, the trunk, branches and tags are all exported. If you
0.64.208 by Ian Clatworthy
minor doc tweaks
537
    only want the trunk, use the `--trunk-only` option.
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
538
539
    By default, filenames, log messages and author names are expected
0.64.208 by Ian Clatworthy
minor doc tweaks
540
    to be encoded in ascii. Use the `--encoding` option to specify an
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
541
    alternative. If multiple encodings are used, specify the option
542
    multiple times. For a list of valid encoding names, see
543
    http://docs.python.org/lib/standard-encodings.html.
544
0.64.208 by Ian Clatworthy
minor doc tweaks
545
    Windows users need to install GNU sort and use the `--sort`
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
546
    option to specify its location. GNU sort can be downloaded from
547
    http://unxutils.sourceforge.net/.
548
    """
549
    hidden = False
550
    _see_also = ['fast-import', 'fast-import-filter']
551
    takes_args = ['source', 'destination']
552
    takes_options = ['verbose',
553
                    Option('trunk-only',
554
                        help="Export just the trunk, ignoring tags and branches."
555
                        ),
556
                    ListOption('encoding', type=str, argname='CODEC',
557
                        help="Encoding used for filenames, commit messages "
558
                             "and author names if not ascii."
559
                        ),
560
                    Option('sort', type=str, argname='PATH',
561
                        help="GNU sort program location if not on the path."
562
                        ),
563
                    ]
564
    aliases = []
565
    encoding_type = 'exact'
566
    def run(self, source, destination, verbose=False, trunk_only=False,
567
        encoding=None, sort=None):
568
        from bzrlib.plugins.fastimport.exporters import fast_export_from
569
        custom = []
570
        if trunk_only:
571
            custom.append("--trunk-only")
572
        if encoding:
573
            for enc in encoding:
574
                custom.extend(['--encoding', enc])
575
        if sort:
576
            custom.extend(['--sort', sort])
577
        fast_export_from(source, destination, 'cvs', verbose, custom)
578
579
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
580
class cmd_fast_export_from_darcs(Command):
581
    """Generate a fast-import file from a Darcs repository.
582
0.64.202 by Ian Clatworthy
more help tweaks
583
    Destination is a dump file, typically named xxx.fi where xxx is
584
    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
585
586
    Darcs 2.2 or later must be installed as various subcommands are
587
    used to access the source repository. The source may be a network
588
    URL but using a local URL is recommended for performance reasons.
589
    """
590
    hidden = False
591
    _see_also = ['fast-import', 'fast-import-filter']
592
    takes_args = ['source', 'destination']
0.93.8 by Ian Clatworthy
add encoding option to fast-export-from-darcs
593
    takes_options = ['verbose',
594
                    Option('encoding', type=str, argname='CODEC',
595
                        help="Encoding used for commit messages if not utf-8."
596
                        ),
597
                    ]
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
598
    aliases = []
599
    encoding_type = 'exact'
0.93.8 by Ian Clatworthy
add encoding option to fast-export-from-darcs
600
    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
601
        from bzrlib.plugins.fastimport.exporters import fast_export_from
0.93.8 by Ian Clatworthy
add encoding option to fast-export-from-darcs
602
        custom = None
603
        if encoding is not None:
604
            custom = ['--encoding', encoding]
605
        fast_export_from(source, destination, 'darcs', verbose, custom)
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
606
607
608
class cmd_fast_export_from_hg(Command):
609
    """Generate a fast-import file from a Mercurial repository.
610
0.64.202 by Ian Clatworthy
more help tweaks
611
    Destination is a dump file, typically named xxx.fi where xxx is
612
    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
613
614
    Mercurial 1.2 or later must be installed as its libraries are used
615
    to access the source repository. Given the APIs currently used,
616
    the source repository must be a local file, not a network URL.
617
    """
618
    hidden = False
619
    _see_also = ['fast-import', 'fast-import-filter']
620
    takes_args = ['source', 'destination']
621
    takes_options = ['verbose']
622
    aliases = []
623
    encoding_type = 'exact'
624
    def run(self, source, destination, verbose=False):
625
        from bzrlib.plugins.fastimport.exporters import fast_export_from
626
        fast_export_from(source, destination, 'hg', verbose)
627
628
629
class cmd_fast_export_from_git(Command):
630
    """Generate a fast-import file from a Git repository.
631
0.64.202 by Ian Clatworthy
more help tweaks
632
    Destination is a dump file, typically named xxx.fi where xxx is
633
    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
634
635
    Git 1.6 or later must be installed as the git fast-export
636
    subcommand is used under the covers to generate the stream.
0.93.3 by Ian Clatworthy
implement fast-export-from-git
637
    The source must be a local directory.
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
638
0.64.201 by Ian Clatworthy
tweak help formatting
639
    .. note::
640
    
641
       Earlier versions of Git may also work fine but are
642
       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
643
    """
644
    hidden = False
645
    _see_also = ['fast-import', 'fast-import-filter']
646
    takes_args = ['source', 'destination']
647
    takes_options = ['verbose']
648
    aliases = []
649
    encoding_type = 'exact'
650
    def run(self, source, destination, verbose=False):
651
        from bzrlib.plugins.fastimport.exporters import fast_export_from
652
        fast_export_from(source, destination, 'git', verbose)
653
654
0.64.204 by Ian Clatworthy
added fast-export-from-mnt command
655
class cmd_fast_export_from_mnt(Command):
656
    """Generate a fast-import file from a Monotone repository.
657
658
    Destination is a dump file, typically named xxx.fi where xxx is
659
    the name of the project. If '-' is given, standard output is used.
660
661
    Monotone 0.43 or later must be installed as the mnt git_export
662
    subcommand is used under the covers to generate the stream.
663
    The source must be a local directory.
664
    """
665
    hidden = False
666
    _see_also = ['fast-import', 'fast-import-filter']
667
    takes_args = ['source', 'destination']
668
    takes_options = ['verbose']
669
    aliases = []
670
    encoding_type = 'exact'
671
    def run(self, source, destination, verbose=False):
672
        from bzrlib.plugins.fastimport.exporters import fast_export_from
673
        fast_export_from(source, destination, 'mnt', verbose)
674
675
0.94.1 by Matt McClure
Adds a fast-export-from-p4 command.
676
class cmd_fast_export_from_p4(Command):
677
    """Generate a fast-import file from a Perforce repository.
678
679
    Source is a Perforce depot path, e.g., //depot/project
680
681
    Destination is a dump file, typically named xxx.fi where xxx is
682
    the name of the project. If '-' is given, standard output is used.
683
684
    bzrp4 must be installed as its p4_fast_export.py module is used under
685
    the covers to do the export.  bzrp4 can be downloaded from
686
    https://launchpad.net/bzrp4/.
687
    
688
    The P4PORT environment variable must be set, and you must be logged
689
    into the Perforce server.
690
691
    By default, only the HEAD changelist is exported.  To export all
692
    changelists, append '@all' to the source.  To export a revision range,
693
    append a comma-delimited pair of changelist numbers to the source,
694
    e.g., '100,200'.
695
    """
696
    hidden = False
697
    _see_also = ['fast-import', 'fast-import-filter']
698
    takes_args = ['source', 'destination']
699
    takes_options = []
700
    aliases = []
701
    encoding_type = 'exact'
702
    def run(self, source, destination, verbose=False):
703
        from bzrlib.plugins.fastimport.exporters import fast_export_from
704
        custom = []
705
        fast_export_from(source, destination, 'p4', verbose, custom)
706
707
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
708
class cmd_fast_export_from_svn(Command):
709
    """Generate a fast-import file from a Subversion repository.
710
0.64.202 by Ian Clatworthy
more help tweaks
711
    Destination is a dump file, typically named xxx.fi where xxx is
712
    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
713
714
    Python-Subversion (Python bindings to the Subversion APIs)
715
    1.4 or later must be installed as this library is used to
716
    access the source repository. The source may be a network URL
717
    but using a local URL is recommended for performance reasons.
718
    """
719
    hidden = False
720
    _see_also = ['fast-import', 'fast-import-filter']
721
    takes_args = ['source', 'destination']
0.93.11 by Ian Clatworthy
initial cut at fast-export-from-svn
722
    takes_options = ['verbose',
723
                    Option('trunk-path', type=str, argname="STR",
724
                        help="Path in repo to /trunk.\n"
725
                              "May be `regex:/cvs/(trunk)/proj1/(.*)` in "
726
                              "which case the first group is used as the "
727
                              "branch name and the second group is used "
728
                              "to match files.",
729
                        ),
730
                    Option('branches-path', type=str, argname="STR",
731
                        help="Path in repo to /branches."
732
                        ),
733
                    Option('tags-path', type=str, argname="STR",
734
                        help="Path in repo to /tags."
735
                        ),
736
                    ]
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
737
    aliases = []
738
    encoding_type = 'exact'
0.93.11 by Ian Clatworthy
initial cut at fast-export-from-svn
739
    def run(self, source, destination, verbose=False, trunk_path=None,
740
        branches_path=None, tags_path=None):
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
741
        from bzrlib.plugins.fastimport.exporters import fast_export_from
0.93.11 by Ian Clatworthy
initial cut at fast-export-from-svn
742
        custom = []
743
        if trunk_path is not None:
744
            custom.extend(['--trunk-path', trunk_path])
745
        if branches_path is not None:
746
            custom.extend(['--branches-path', branches_path])
747
        if tags_path is not None:
748
            custom.extend(['--tags-path', tags_path])
749
        fast_export_from(source, destination, 'svn', verbose, custom)
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
750
751
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
752
register_command(cmd_fast_import)
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
753
register_command(cmd_fast_import_filter)
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
754
register_command(cmd_fast_import_info)
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
755
register_command(cmd_fast_import_query)
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
756
register_command(cmd_fast_export)
0.64.205 by Ian Clatworthy
added fast-export-to-cvs
757
register_command(cmd_fast_export_from_cvs)
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
758
register_command(cmd_fast_export_from_darcs)
759
register_command(cmd_fast_export_from_hg)
760
register_command(cmd_fast_export_from_git)
0.64.204 by Ian Clatworthy
added fast-export-from-mnt command
761
register_command(cmd_fast_export_from_mnt)
0.94.1 by Matt McClure
Adds a fast-export-from-p4 command.
762
register_command(cmd_fast_export_from_p4)
0.93.1 by Ian Clatworthy
initial cut at a simplified ui to xxx-fast-export
763
register_command(cmd_fast_export_from_svn)