1
# Copyright (C) 2008 Canonical Ltd
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.
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.
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
20
The fastimport plugin provides stream-based importing of data into Bazaar.
21
A bzr-fast-export.py script is also included providing exporting of data
22
out of Bazaar to the same format. As well as enabling interchange between
23
multiple VCS tools, fastimport/export can be useful for complex branch
24
operatons, e.g. partitioning off part of a code base in order to Open
27
The normal import recipe is::
30
front-end | bzr fast-import -
32
Numerous front-ends are provided in the exporters directory where
33
the plugin is installed. The list of known front-ends and their
34
status is documented on http://bazaar-vcs.org/BzrFastImport/FrontEnds.
35
For further details, see http://bazaar-vcs.org/BzrFastImport and the
36
online help for the commands::
39
bzr help fast-import-info
40
bzr help fast-import-query
42
To report bugs or publish enhancements, visit the bzr-fastimport project
43
page on Launchpad, https://launchpad.net/bzr-fastimport.
46
from bzrlib.commands import Command, register_command
47
from bzrlib.option import Option, ListOption
52
return tests.test_suite()
55
def _run(source, processor_factory, control, params, verbose):
56
"""Create and run a processor.
58
:param source: a filename or '-' for standard input
59
:param processor_factory: a callable for creating a processor
60
:param control: the BzrDir of the destination or None if no
61
destination is expected
70
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
74
stream = open(source, "rb")
75
proc = processor_factory(control, params=params, verbose=verbose)
76
p = parser.ImportParser(stream, verbose=verbose)
77
return proc.process(p.iter_commands)
80
class cmd_fast_import(Command):
81
"""Backend for fast Bazaar data importers.
83
This command reads a mixed command/data stream and
84
creates branches in the current repository accordingly.
85
To specify standard input as the input stream, use a
91
front-end | bzr fast-import -
93
If run inside a branch using a shared repository, then
94
the current branch is made the trunk and other branches,
95
if any, are created in sister directories. If run inside
96
a standalone tree, the current branch is also made the
97
trunk, but warnings are output about other branches found.
99
The stream format is upwardly compatible with git-fast-import
100
so existing front-ends for that tool can typically be reused
101
without changes. See http://bazaar-vcs.org/BzrFastImport for
102
links to matching exporters from Subversion, CVS, Git,
103
Mercurial, Darcs, Perforce and SCCS.
105
While reusing an existing format with existing frontends is
106
great, it does mean a slightly more complex recipe when
107
importing large projects via exporters that reuse blob data
108
across commits, namely::
112
bzr fast-import-info -v xxx.fi > xxx.cfg
113
bzr fast-import xxx.fi --info xxx.cfg
115
In this scenario, the xxx.cfg file generated by the first pass
116
holds caching hints that the second pass uses to lower memory
119
At checkpoints and on completion, the commit-id -> revision-id
120
map is saved to a file called 'fastimport-id-map' in the control
121
directory for the repository (e.g. .bzr/repository). If the import
122
is interrupted or unexpectedly crashes, it can be started again
123
and this file will be used to skip over already loaded revisions.
124
As long as subsequent exports from the original source begin
125
with exactly the same revisions, you can use this feature to
126
maintain a mirror of a repository managed by a foreign tool.
127
If and when Bazaar is used to manage the repository, this file
128
can be safely deleted.
130
If you wish to write a custom exporter for your project, see
131
http://bazaar-vcs.org/BzrFastImport for the detailed protocol
132
specification. In many cases, exporters can be written quite
133
quickly using whatever scripting/programming language you like.
138
git-fast-export --signed-tags=warn | bzr fast-import -
140
Import a Git repository into Bazaar.
142
svn-fast-export.py /svn/repo/path | bzr fast-import -
144
Import a Subversion repository into Bazaar.
146
hg-fast-export.py -r /hg/repo/path | bzr fast-import -
148
Import a Mercurial repository into Bazaar.
151
_see_also = ['fast-import-info', 'fast-import-query']
152
takes_args = ['source']
153
takes_options = ['verbose',
154
Option('info', type=str,
155
help="Path to file containing caching hints.",
158
help="Update working trees.",
160
Option('checkpoint', type=int,
161
help="Checkpoint automatically every N revisions.",
163
Option('count', type=int,
164
help="Import this many revisions then exit.",
166
Option('inv-cache', type=int,
167
help="Number of inventories to cache.",
169
Option('experimental',
170
help="Enable experimental features.",
172
Option('import-marks', type=str,
173
help="Import marks from file."),
174
Option('export-marks', type=str,
175
help="Export marks to file."),
178
def run(self, source, verbose=False, info=None, trees=False,
179
checkpoint=10000, count=-1, inv_cache=10,
180
experimental=True, import_marks=None, export_marks=None):
181
from bzrlib import bzrdir
182
from bzrlib.plugins.fastimport.processors import generic_processor
183
control, relpath = bzrdir.BzrDir.open_containing('.')
187
'checkpoint': checkpoint,
189
'inv-cache': inv_cache,
190
'experimental': experimental,
191
'import-marks': import_marks,
192
'export-marks': export_marks,
194
return _run(source, generic_processor.GenericProcessor, control,
198
class cmd_fast_import_info(Command):
199
"""Output information about a fast-import stream.
201
This command reads a fast-import stream and outputs
202
statistics and interesting properties about what it finds.
203
When run in verbose mode, the information is output as a
204
configuration file that can be passed to fast-import to
205
assist it in intelligently caching objects.
207
To specify standard input as the input stream, use a source
212
front-end | bzr fast-import-info -
214
Display statistics about the import stream produced by front-end.
216
front-end | bzr fast-import-info -v - > front-end.cfg
218
Create a hints file for running fast-import on a large repository.
221
_see_also = ['fast-import']
222
takes_args = ['source']
223
takes_options = ['verbose']
225
def run(self, source, verbose=False):
226
from bzrlib.plugins.fastimport.processors import info_processor
227
return _run(source, info_processor.InfoProcessor, None, {}, verbose)
230
class cmd_fast_import_query(Command):
231
"""Query a fast-import stream displaying selected commands.
233
To specify standard input as the input stream, use a source
234
name of '-'. To specify the commands to display, use the -C
235
option one or more times. To specify just some fields for
236
a command, use the syntax::
240
By default, the nominated fields for the nominated commands
241
are displayed tab separated. To see the information in
242
a name:value format, use verbose mode.
244
Note: Binary fields (e.g. data for blobs) are masked out
245
so it is generally safe to view the output in a terminal.
250
bzr fast-import-query xxx.fi -Creset -Ctag
252
Show all the fields of the reset and tag commands.
254
bzr fast-import-query xxx.fi -Ccommit=mark,merge
256
Show the mark and merge fields of the commit commands.
259
_see_also = ['fast-import']
260
takes_args = ['source']
261
takes_options = ['verbose',
262
ListOption('commands', short_name='C', type=str,
263
help="Display fields for these commands."
267
def run(self, source, verbose=False, commands=None):
268
from bzrlib.plugins.fastimport.processors import query_processor
269
from bzrlib.plugins.fastimport import helpers
270
params = helpers.defines_to_dict(commands)
271
return _run(source, query_processor.QueryProcessor, None, params,
275
register_command(cmd_fast_import)
276
register_command(cmd_fast_import_info)
277
register_command(cmd_fast_import_query)