bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
1 |
# Copyright (C) 2008 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
|
0.64.334
by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan. |
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
15 |
|
16 |
"""Fastimport/fastexport commands."""
|
|
17 |
||
18 |
from bzrlib import bzrdir |
|
19 |
from bzrlib.commands import Command |
|
20 |
from bzrlib.option import Option, ListOption, RegistryOption |
|
21 |
||
22 |
from bzrlib.plugins.fastimport import load_fastimport |
|
23 |
||
24 |
||
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
25 |
def _run(source, processor_factory, verbose=False, user_map=None, **kwargs): |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
26 |
"""Create and run a processor. |
27 |
||
28 |
:param source: a filename or '-' for standard input. If the
|
|
29 |
filename ends in .gz, it will be opened as a gzip file and
|
|
30 |
the stream will be implicitly uncompressed
|
|
31 |
:param processor_factory: a callable for creating a processor
|
|
32 |
:param user_map: if not None, the file containing the user map.
|
|
33 |
"""
|
|
34 |
from fastimport import parser |
|
35 |
stream = _get_source_stream(source) |
|
36 |
user_mapper = _get_user_mapper(user_map) |
|
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
37 |
proc = processor_factory(verbose=verbose, **kwargs) |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
38 |
p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper) |
39 |
return proc.process(p.iter_commands) |
|
40 |
||
41 |
||
42 |
def _get_source_stream(source): |
|
|
0.64.321
by Jelmer Vernooij
Allow fast-import-filter to be used without first argument. |
43 |
if source == '-' or source is None: |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
44 |
import sys |
45 |
from fastimport import helpers |
|
46 |
stream = helpers.binary_stream(sys.stdin) |
|
47 |
elif source.endswith('.gz'): |
|
48 |
import gzip |
|
49 |
stream = gzip.open(source, "rb") |
|
50 |
else: |
|
51 |
stream = open(source, "rb") |
|
52 |
return stream |
|
53 |
||
54 |
||
55 |
def _get_user_mapper(filename): |
|
56 |
import user_mapper |
|
57 |
if filename is None: |
|
58 |
return None |
|
59 |
f = open(filename) |
|
60 |
lines = f.readlines() |
|
61 |
f.close() |
|
62 |
return user_mapper.UserMapper(lines) |
|
63 |
||
64 |
||
65 |
class cmd_fast_import(Command): |
|
66 |
"""Backend for fast Bazaar data importers. |
|
67 |
||
68 |
This command reads a mixed command/data stream and creates
|
|
69 |
branches in a Bazaar repository accordingly. The preferred
|
|
70 |
recipe is::
|
|
71 |
||
72 |
bzr fast-import project.fi project.bzr
|
|
73 |
||
74 |
Numerous commands are provided for generating a fast-import file
|
|
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
75 |
to use as input.
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
76 |
To specify standard input as the input stream, use a
|
77 |
source name of '-' (instead of project.fi). If the source name
|
|
78 |
ends in '.gz', it is assumed to be compressed in gzip format.
|
|
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
79 |
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
80 |
project.bzr will be created if it doesn't exist. If it exists
|
81 |
already, it should be empty or be an existing Bazaar repository
|
|
82 |
or branch. If not specified, the current directory is assumed.
|
|
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
83 |
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
84 |
fast-import will intelligently select the format to use when
|
85 |
creating a repository or branch. If you are running Bazaar 1.17
|
|
86 |
up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
|
|
87 |
Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
|
|
88 |
is used. If you wish to specify a custom format, use the `--format`
|
|
89 |
option.
|
|
90 |
||
91 |
.. note::
|
|
92 |
|
|
93 |
To maintain backwards compatibility, fast-import lets you
|
|
94 |
create the target repository or standalone branch yourself.
|
|
95 |
It is recommended though that you let fast-import create
|
|
96 |
these for you instead.
|
|
97 |
||
98 |
:Branch mapping rules:
|
|
99 |
||
100 |
Git reference names are mapped to Bazaar branch names as follows:
|
|
101 |
|
|
102 |
* refs/heads/foo is mapped to foo
|
|
103 |
* refs/remotes/origin/foo is mapped to foo.remote
|
|
104 |
* refs/tags/foo is mapped to foo.tag
|
|
105 |
* */master is mapped to trunk, trunk.remote, etc.
|
|
106 |
* */trunk is mapped to git-trunk, git-trunk.remote, etc.
|
|
107 |
||
108 |
:Branch creation rules:
|
|
109 |
||
110 |
When a shared repository is created or found at the destination,
|
|
111 |
branches are created inside it. In the simple case of a single
|
|
112 |
branch (refs/heads/master) inside the input file, the branch is
|
|
113 |
project.bzr/trunk.
|
|
114 |
||
115 |
When a standalone branch is found at the destination, the trunk
|
|
116 |
is imported there and warnings are output about any other branches
|
|
117 |
found in the input file.
|
|
118 |
||
119 |
When a branch in a shared repository is found at the destination,
|
|
120 |
that branch is made the trunk and other branches, if any, are
|
|
121 |
created in sister directories.
|
|
122 |
||
123 |
:Working tree updates:
|
|
124 |
||
125 |
The working tree is generated for the trunk branch. If multiple
|
|
126 |
branches are created, a message is output on completion explaining
|
|
127 |
how to create the working trees for other branches.
|
|
128 |
||
129 |
:Custom exporters:
|
|
130 |
||
131 |
The fast-export-from-xxx commands typically call more advanced
|
|
132 |
xxx-fast-export scripts. You are welcome to use the advanced
|
|
133 |
scripts if you prefer.
|
|
134 |
||
135 |
If you wish to write a custom exporter for your project, see
|
|
136 |
http://bazaar-vcs.org/BzrFastImport for the detailed protocol
|
|
137 |
specification. In many cases, exporters can be written quite
|
|
138 |
quickly using whatever scripting/programming language you like.
|
|
139 |
||
140 |
:User mapping:
|
|
141 |
||
142 |
Some source repositories store just the user name while Bazaar
|
|
143 |
prefers a full email address. You can adjust user-ids while
|
|
144 |
importing by using the --user-map option. The argument is a
|
|
145 |
text file with lines in the format::
|
|
146 |
||
147 |
old-id = new-id
|
|
148 |
||
149 |
Blank lines and lines beginning with # are ignored.
|
|
150 |
If old-id has the special value '@', then users without an
|
|
151 |
email address will get one created by using the matching new-id
|
|
152 |
as the domain, unless a more explicit address is given for them.
|
|
153 |
For example, given the user-map of::
|
|
154 |
||
155 |
@ = example.com
|
|
156 |
bill = William Jones <bill@example.com>
|
|
157 |
||
158 |
then user-ids are mapped as follows::
|
|
159 |
|
|
160 |
maria => maria <maria@example.com>
|
|
161 |
bill => William Jones <bill@example.com>
|
|
162 |
||
163 |
.. note::
|
|
164 |
|
|
165 |
User mapping is supported by both the fast-import and
|
|
166 |
fast-import-filter commands.
|
|
167 |
||
168 |
:Blob tracking:
|
|
169 |
||
170 |
As some exporters (like git-fast-export) reuse blob data across
|
|
171 |
commits, fast-import makes two passes over the input file by
|
|
172 |
default. In the first pass, it collects data about what blobs are
|
|
173 |
used when, along with some other statistics (e.g. total number of
|
|
174 |
commits). In the second pass, it generates the repository and
|
|
175 |
branches.
|
|
176 |
|
|
177 |
.. note::
|
|
178 |
|
|
179 |
The initial pass isn't done if the --info option is used
|
|
180 |
to explicitly pass in information about the input stream.
|
|
181 |
It also isn't done if the source is standard input. In the
|
|
182 |
latter case, memory consumption may be higher than otherwise
|
|
183 |
because some blobs may be kept in memory longer than necessary.
|
|
184 |
||
185 |
:Restarting an import:
|
|
186 |
||
187 |
At checkpoints and on completion, the commit-id -> revision-id
|
|
188 |
map is saved to a file called 'fastimport-id-map' in the control
|
|
189 |
directory for the repository (e.g. .bzr/repository). If the import
|
|
190 |
is interrupted or unexpectedly crashes, it can be started again
|
|
191 |
and this file will be used to skip over already loaded revisions.
|
|
192 |
As long as subsequent exports from the original source begin
|
|
193 |
with exactly the same revisions, you can use this feature to
|
|
194 |
maintain a mirror of a repository managed by a foreign tool.
|
|
195 |
If and when Bazaar is used to manage the repository, this file
|
|
196 |
can be safely deleted.
|
|
197 |
||
198 |
:Examples:
|
|
199 |
||
200 |
Import a Subversion repository into Bazaar::
|
|
201 |
||
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
202 |
svn-fast-export /svn/repo/path > project.fi
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
203 |
bzr fast-import project.fi project.bzr
|
204 |
||
205 |
Import a CVS repository into Bazaar::
|
|
206 |
||
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
207 |
cvs2git /cvs/repo/path > project.fi
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
208 |
bzr fast-import project.fi project.bzr
|
209 |
||
210 |
Import a Git repository into Bazaar::
|
|
211 |
||
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
212 |
cd /git/repo/path
|
213 |
git fast-export --all > project.fi
|
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
214 |
bzr fast-import project.fi project.bzr
|
215 |
||
216 |
Import a Mercurial repository into Bazaar::
|
|
217 |
||
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
218 |
cd /hg/repo/path
|
219 |
hg fast-export > project.fi
|
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
220 |
bzr fast-import project.fi project.bzr
|
221 |
||
222 |
Import a Darcs repository into Bazaar::
|
|
223 |
||
|
0.136.2
by Jelmer Vernooij
remove more references to fast-export-from-*. |
224 |
cd /darcs/repo/path
|
225 |
darcs-fast-export > project.fi
|
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
226 |
bzr fast-import project.fi project.bzr
|
227 |
"""
|
|
228 |
hidden = False |
|
229 |
_see_also = ['fast-export', 'fast-import-filter', 'fast-import-info'] |
|
230 |
takes_args = ['source', 'destination?'] |
|
231 |
takes_options = ['verbose', |
|
232 |
Option('user-map', type=str, |
|
233 |
help="Path to file containing a map of user-ids.", |
|
234 |
),
|
|
235 |
Option('info', type=str, |
|
236 |
help="Path to file containing caching hints.", |
|
237 |
),
|
|
238 |
Option('trees', |
|
239 |
help="Update all working trees, not just trunk's.", |
|
240 |
),
|
|
241 |
Option('count', type=int, |
|
242 |
help="Import this many revisions then exit.", |
|
243 |
),
|
|
244 |
Option('checkpoint', type=int, |
|
245 |
help="Checkpoint automatically every N revisions." |
|
246 |
" The default is 10000.", |
|
247 |
),
|
|
248 |
Option('autopack', type=int, |
|
249 |
help="Pack every N checkpoints. The default is 4.", |
|
250 |
),
|
|
251 |
Option('inv-cache', type=int, |
|
252 |
help="Number of inventories to cache.", |
|
253 |
),
|
|
254 |
RegistryOption.from_kwargs('mode', |
|
255 |
'The import algorithm to use.', |
|
256 |
title='Import Algorithm', |
|
257 |
default='Use the preferred algorithm (inventory deltas).', |
|
258 |
classic="Use the original algorithm (mutable inventories).", |
|
259 |
experimental="Enable experimental features.", |
|
260 |
value_switches=True, enum_switch=False, |
|
261 |
),
|
|
262 |
Option('import-marks', type=str, |
|
263 |
help="Import marks from file." |
|
264 |
),
|
|
265 |
Option('export-marks', type=str, |
|
266 |
help="Export marks to file." |
|
267 |
),
|
|
268 |
RegistryOption('format', |
|
269 |
help='Specify a format for the created repository. See' |
|
270 |
' "bzr help formats" for details.', |
|
271 |
lazy_registry=('bzrlib.bzrdir', 'format_registry'), |
|
272 |
converter=lambda name: bzrdir.format_registry.make_bzrdir(name), |
|
273 |
value_switches=False, title='Repository format'), |
|
274 |
]
|
|
275 |
def run(self, source, destination='.', verbose=False, info=None, |
|
276 |
trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1, |
|
277 |
mode=None, import_marks=None, export_marks=None, format=None, |
|
278 |
user_map=None): |
|
279 |
load_fastimport() |
|
280 |
from bzrlib.plugins.fastimport.processors import generic_processor |
|
281 |
from bzrlib.plugins.fastimport.helpers import ( |
|
282 |
open_destination_directory, |
|
283 |
)
|
|
284 |
control = open_destination_directory(destination, format=format) |
|
285 |
||
286 |
# If an information file was given and the source isn't stdin,
|
|
287 |
# generate the information by reading the source file as a first pass
|
|
288 |
if info is None and source != '-': |
|
289 |
info = self._generate_info(source) |
|
290 |
||
291 |
# Do the work
|
|
292 |
if mode is None: |
|
293 |
mode = 'default' |
|
294 |
params = { |
|
295 |
'info': info, |
|
296 |
'trees': trees, |
|
297 |
'count': count, |
|
298 |
'checkpoint': checkpoint, |
|
299 |
'autopack': autopack, |
|
300 |
'inv-cache': inv_cache, |
|
301 |
'mode': mode, |
|
302 |
'import-marks': import_marks, |
|
303 |
'export-marks': export_marks, |
|
304 |
}
|
|
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
305 |
return _run(source, generic_processor.GenericProcessor, |
|
0.131.2
by Jelmer Vernooij
Fix 'bzr fast-import' bzrdir argument and add a blackbox test. |
306 |
bzrdir=control, params=params, verbose=verbose, |
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
307 |
user_map=user_map) |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
308 |
|
309 |
def _generate_info(self, source): |
|
310 |
from cStringIO import StringIO |
|
311 |
from fastimport import parser |
|
|
0.64.349
by Jelmer Vernooij
Reimport some modules removed from python-fastimport 0.9.2. |
312 |
from bzrlib.plugins.fastimport.processors import info_processor |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
313 |
stream = _get_source_stream(source) |
314 |
output = StringIO() |
|
315 |
try: |
|
316 |
proc = info_processor.InfoProcessor(verbose=True, outf=output) |
|
317 |
p = parser.ImportParser(stream) |
|
318 |
return_code = proc.process(p.iter_commands) |
|
319 |
lines = output.getvalue().splitlines() |
|
320 |
finally: |
|
321 |
output.close() |
|
322 |
stream.seek(0) |
|
323 |
return lines |
|
324 |
||
325 |
||
326 |
class cmd_fast_import_filter(Command): |
|
327 |
"""Filter a fast-import stream to include/exclude files & directories. |
|
328 |
||
329 |
This command is useful for splitting a subdirectory or bunch of
|
|
330 |
files out from a project to create a new project complete with history
|
|
331 |
for just those files. It can also be used to create a new project
|
|
332 |
repository that removes all references to files that should not have
|
|
333 |
been committed, e.g. security-related information (like passwords),
|
|
334 |
commercially sensitive material, files with an incompatible license or
|
|
335 |
large binary files like CD images.
|
|
336 |
||
337 |
To specify standard input as the input stream, use a source name
|
|
338 |
of '-'. If the source name ends in '.gz', it is assumed to be
|
|
339 |
compressed in gzip format.
|
|
340 |
||
341 |
:File/directory filtering:
|
|
342 |
||
343 |
This is supported by the -i and -x options. Excludes take precedence
|
|
344 |
over includes.
|
|
345 |
||
346 |
When filtering out a subdirectory (or file), the new stream uses the
|
|
347 |
subdirectory (or subdirectory containing the file) as the root. As
|
|
348 |
fast-import doesn't know in advance whether a path is a file or
|
|
349 |
directory in the stream, you need to specify a trailing '/' on
|
|
350 |
directories passed to the `--includes option`. If multiple files or
|
|
351 |
directories are given, the new root is the deepest common directory.
|
|
352 |
||
353 |
Note: If a path has been renamed, take care to specify the *original*
|
|
354 |
path name, not the final name that it ends up with.
|
|
355 |
||
356 |
:User mapping:
|
|
357 |
||
358 |
Some source repositories store just the user name while Bazaar
|
|
359 |
prefers a full email address. You can adjust user-ids
|
|
360 |
by using the --user-map option. The argument is a
|
|
361 |
text file with lines in the format::
|
|
362 |
||
363 |
old-id = new-id
|
|
364 |
||
365 |
Blank lines and lines beginning with # are ignored.
|
|
366 |
If old-id has the special value '@', then users without an
|
|
367 |
email address will get one created by using the matching new-id
|
|
368 |
as the domain, unless a more explicit address is given for them.
|
|
369 |
For example, given the user-map of::
|
|
370 |
||
371 |
@ = example.com
|
|
372 |
bill = William Jones <bill@example.com>
|
|
373 |
||
374 |
then user-ids are mapped as follows::
|
|
375 |
|
|
376 |
maria => maria <maria@example.com>
|
|
377 |
bill => William Jones <bill@example.com>
|
|
378 |
||
379 |
.. note::
|
|
380 |
|
|
381 |
User mapping is supported by both the fast-import and
|
|
382 |
fast-import-filter commands.
|
|
383 |
||
|
0.134.1
by Oleksandr Usov
Add preserve_all_history flag fast-import-filter |
384 |
:History rewriting:
|
385 |
||
386 |
By default fast-import-filter does quite aggressive history rewriting.
|
|
387 |
Empty commits (or commits which had all their content filtered out) will
|
|
388 |
be removed, and so are the references to commits not included in the stream.
|
|
389 |
||
|
0.134.2
by Oleksandr Usov
Command-line flag renamed to --dont-squash-empty-commits |
390 |
Flag --dont-squash-empty-commits reverses this behavior and makes it possible to
|
|
0.134.1
by Oleksandr Usov
Add preserve_all_history flag fast-import-filter |
391 |
use fast-import-filter on incremental streams.
|
392 |
||
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
393 |
:Examples:
|
394 |
||
395 |
Create a new project from a library (note the trailing / on the
|
|
396 |
directory name of the library)::
|
|
397 |
||
398 |
front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
|
|
399 |
bzr fast-import xxx.fi mylibrary.bzr
|
|
400 |
(lib/xxx/foo is now foo)
|
|
401 |
||
402 |
Create a new repository without a sensitive file::
|
|
403 |
||
404 |
front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
|
|
405 |
bzr fast-import clean.fi clean.bzr
|
|
406 |
"""
|
|
407 |
hidden = False |
|
408 |
_see_also = ['fast-import'] |
|
|
0.64.293
by Jelmer Vernooij
SOURCE argument to bzr fast-import-filter is now optional, consistent with examples. |
409 |
takes_args = ['source?'] |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
410 |
takes_options = ['verbose', |
411 |
ListOption('include_paths', short_name='i', type=str, |
|
412 |
help="Only include commits affecting these paths." |
|
413 |
" Directories should have a trailing /."
|
|
414 |
),
|
|
415 |
ListOption('exclude_paths', short_name='x', type=str, |
|
416 |
help="Exclude these paths from commits." |
|
417 |
),
|
|
418 |
Option('user-map', type=str, |
|
419 |
help="Path to file containing a map of user-ids.", |
|
420 |
),
|
|
|
0.134.2
by Oleksandr Usov
Command-line flag renamed to --dont-squash-empty-commits |
421 |
Option('dont-squash-empty-commits', |
|
0.134.1
by Oleksandr Usov
Add preserve_all_history flag fast-import-filter |
422 |
help="Preserve all commits and links between them" |
423 |
),
|
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
424 |
]
|
425 |
encoding_type = 'exact' |
|
|
0.64.293
by Jelmer Vernooij
SOURCE argument to bzr fast-import-filter is now optional, consistent with examples. |
426 |
def run(self, source=None, verbose=False, include_paths=None, |
|
0.134.2
by Oleksandr Usov
Command-line flag renamed to --dont-squash-empty-commits |
427 |
exclude_paths=None, user_map=None, dont_squash_empty_commits=False): |
|
0.64.338
by Jelmer Vernooij
Merge in support for --dont-squash-empty-commits. |
428 |
from bzrlib.errors import BzrCommandError |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
429 |
load_fastimport() |
430 |
from fastimport.processors import filter_processor |
|
431 |
params = { |
|
432 |
'include_paths': include_paths, |
|
433 |
'exclude_paths': exclude_paths, |
|
434 |
}
|
|
|
0.64.338
by Jelmer Vernooij
Merge in support for --dont-squash-empty-commits. |
435 |
if ('squash_empty_commits' in |
436 |
filter_processor.FilterProcessor.known_params): |
|
437 |
params['squash_empty_commits'] = (not dont_squash_empty_commits) |
|
438 |
else: |
|
439 |
if dont_squash_empty_commits: |
|
440 |
raise BzrCommandError("installed python-fastimport does not " |
|
441 |
"support not squashing empty commits. Please install "
|
|
442 |
" a newer python-fastimport to use "
|
|
443 |
"--dont-squash-empty-commits") |
|
444 |
||
|
0.64.287
by Jelmer Vernooij
Fix fast-import-filter. |
445 |
from fastimport import parser |
446 |
stream = _get_source_stream(source) |
|
447 |
user_mapper = _get_user_mapper(user_map) |
|
448 |
proc = filter_processor.FilterProcessor(params=params, verbose=verbose) |
|
449 |
p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper) |
|
450 |
return proc.process(p.iter_commands) |
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
451 |
|
452 |
||
453 |
class cmd_fast_import_info(Command): |
|
454 |
"""Output information about a fast-import stream. |
|
455 |
||
456 |
This command reads a fast-import stream and outputs
|
|
457 |
statistics and interesting properties about what it finds.
|
|
458 |
When run in verbose mode, the information is output as a
|
|
459 |
configuration file that can be passed to fast-import to
|
|
460 |
assist it in intelligently caching objects.
|
|
461 |
||
462 |
To specify standard input as the input stream, use a source name
|
|
463 |
of '-'. If the source name ends in '.gz', it is assumed to be
|
|
464 |
compressed in gzip format.
|
|
465 |
||
466 |
:Examples:
|
|
467 |
||
468 |
Display statistics about the import stream produced by front-end::
|
|
469 |
||
470 |
front-end | bzr fast-import-info -
|
|
471 |
||
472 |
Create a hints file for running fast-import on a large repository::
|
|
473 |
||
474 |
front-end | bzr fast-import-info -v - > front-end.cfg
|
|
475 |
"""
|
|
476 |
hidden = False |
|
477 |
_see_also = ['fast-import'] |
|
478 |
takes_args = ['source'] |
|
479 |
takes_options = ['verbose'] |
|
480 |
def run(self, source, verbose=False): |
|
481 |
load_fastimport() |
|
|
0.64.349
by Jelmer Vernooij
Reimport some modules removed from python-fastimport 0.9.2. |
482 |
from bzrlib.plugins.fastimport.processors import info_processor |
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
483 |
return _run(source, info_processor.InfoProcessor, verbose=verbose) |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
484 |
|
485 |
||
486 |
class cmd_fast_import_query(Command): |
|
487 |
"""Query a fast-import stream displaying selected commands. |
|
488 |
||
489 |
To specify standard input as the input stream, use a source name
|
|
490 |
of '-'. If the source name ends in '.gz', it is assumed to be
|
|
491 |
compressed in gzip format.
|
|
492 |
||
493 |
To specify a commit to display, give its mark using the
|
|
494 |
--commit-mark option. The commit will be displayed with
|
|
495 |
file-commands included but with inline blobs hidden.
|
|
496 |
||
497 |
To specify the commands to display, use the -C option one or
|
|
498 |
more times. To specify just some fields for a command, use the
|
|
499 |
syntax::
|
|
500 |
||
501 |
command=field1,...
|
|
502 |
||
503 |
By default, the nominated fields for the nominated commands
|
|
504 |
are displayed tab separated. To see the information in
|
|
505 |
a name:value format, use verbose mode.
|
|
506 |
||
507 |
Note: Binary fields (e.g. data for blobs) are masked out
|
|
508 |
so it is generally safe to view the output in a terminal.
|
|
509 |
||
510 |
:Examples:
|
|
511 |
||
512 |
Show the commit with mark 429::
|
|
513 |
||
514 |
bzr fast-import-query xxx.fi -m429
|
|
515 |
||
516 |
Show all the fields of the reset and tag commands::
|
|
517 |
||
518 |
bzr fast-import-query xxx.fi -Creset -Ctag
|
|
519 |
||
520 |
Show the mark and merge fields of the commit commands::
|
|
521 |
||
522 |
bzr fast-import-query xxx.fi -Ccommit=mark,merge
|
|
523 |
"""
|
|
524 |
hidden = True |
|
525 |
_see_also = ['fast-import', 'fast-import-filter'] |
|
526 |
takes_args = ['source'] |
|
527 |
takes_options = ['verbose', |
|
528 |
Option('commit-mark', short_name='m', type=str, |
|
529 |
help="Mark of the commit to display." |
|
530 |
),
|
|
531 |
ListOption('commands', short_name='C', type=str, |
|
532 |
help="Display fields for these commands." |
|
533 |
),
|
|
534 |
]
|
|
535 |
def run(self, source, verbose=False, commands=None, commit_mark=None): |
|
536 |
load_fastimport() |
|
537 |
from fastimport.processors import query_processor |
|
538 |
from bzrlib.plugins.fastimport import helpers |
|
539 |
params = helpers.defines_to_dict(commands) or {} |
|
540 |
if commit_mark: |
|
541 |
params['commit-mark'] = commit_mark |
|
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
542 |
return _run(source, query_processor.QueryProcessor, params=params, |
543 |
verbose=verbose) |
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
544 |
|
545 |
||
546 |
class cmd_fast_export(Command): |
|
547 |
"""Generate a fast-import stream from a Bazaar branch. |
|
548 |
||
549 |
This program generates a stream from a Bazaar branch in fast-import
|
|
550 |
format used by tools such as bzr fast-import, git-fast-import and
|
|
551 |
hg-fast-import.
|
|
552 |
||
553 |
If no destination is given or the destination is '-', standard output
|
|
554 |
is used. Otherwise, the destination is the name of a file. If the
|
|
555 |
destination ends in '.gz', the output will be compressed into gzip
|
|
556 |
format.
|
|
557 |
|
|
558 |
:Round-tripping:
|
|
559 |
||
560 |
Recent versions of the fast-import specification support features
|
|
|
0.64.341
by Jelmer Vernooij
Fix test, clarify help description for 'bzr fast-export'. |
561 |
that allow effective round-tripping most of the metadata in Bazaar
|
562 |
branches. As such, fast-exporting a branch and fast-importing the data
|
|
563 |
produced will create a new repository with roughly equivalent history, i.e.
|
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
564 |
"bzr log -v -p --include-merges --forward" on the old branch and
|
565 |
new branch should produce similar, if not identical, results.
|
|
566 |
||
567 |
.. note::
|
|
568 |
|
|
569 |
Be aware that the new repository may appear to have similar history
|
|
570 |
but internally it is quite different with new revision-ids and
|
|
571 |
file-ids assigned. As a consequence, the ability to easily merge
|
|
572 |
with branches based on the old repository is lost. Depending on your
|
|
573 |
reasons for producing a new repository, this may or may not be an
|
|
574 |
issue.
|
|
575 |
||
576 |
:Interoperability:
|
|
577 |
||
578 |
fast-export can use the following "extended features" to
|
|
579 |
produce a richer data stream:
|
|
580 |
||
581 |
* *multiple-authors* - if a commit has multiple authors (as commonly
|
|
582 |
occurs in pair-programming), all authors will be included in the
|
|
583 |
output, not just the first author
|
|
584 |
||
585 |
* *commit-properties* - custom metadata per commit that Bazaar stores
|
|
586 |
in revision properties (e.g. branch-nick and bugs fixed by this
|
|
587 |
change) will be included in the output.
|
|
588 |
||
589 |
* *empty-directories* - directories, even the empty ones, will be
|
|
590 |
included in the output.
|
|
591 |
||
592 |
To disable these features and produce output acceptable to git 1.6,
|
|
593 |
use the --plain option. To enable these features, use --no-plain.
|
|
594 |
Currently, --plain is the default but that will change in the near
|
|
595 |
future once the feature names and definitions are formally agreed
|
|
596 |
to by the broader fast-import developer community.
|
|
597 |
||
|
0.64.337
by Jelmer Vernooij
Merge support for --rewrite-tag-names. |
598 |
Git has stricter naming rules for tags and fast-export --plain
|
599 |
will skip tags which can't be imported into git. To replace characters
|
|
600 |
unsupported in git with an underscore instead, specify
|
|
601 |
--rewrite-tag-names.
|
|
602 |
||
|
0.135.1
by Andy Grimm
Add --baseline option |
603 |
:History truncation:
|
604 |
||
|
0.64.341
by Jelmer Vernooij
Fix test, clarify help description for 'bzr fast-export'. |
605 |
It is sometimes convenient to simply truncate the revision history at a
|
606 |
certain point. The --baseline option, to be used in conjunction with -r,
|
|
607 |
emits a baseline commit containing the state of the entire source tree at
|
|
608 |
the first requested revision. This allows a user to produce a tree
|
|
609 |
identical to the original without munging multiple exports.
|
|
|
0.135.1
by Andy Grimm
Add --baseline option |
610 |
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
611 |
:Examples:
|
612 |
||
613 |
To produce data destined for import into Bazaar::
|
|
614 |
||
615 |
bzr fast-export --no-plain my-bzr-branch my.fi.gz
|
|
616 |
||
617 |
To produce data destined for Git 1.6::
|
|
618 |
||
619 |
bzr fast-export --plain my-bzr-branch my.fi
|
|
620 |
||
621 |
To import several unmerged but related branches into the same repository,
|
|
622 |
use the --{export,import}-marks options, and specify a name for the git
|
|
623 |
branch like this::
|
|
624 |
|
|
625 |
bzr fast-export --export-marks=marks.bzr project.dev |
|
|
626 |
GIT_DIR=project/.git git-fast-import --export-marks=marks.git
|
|
627 |
||
628 |
bzr fast-export --import-marks=marks.bzr -b other project.other |
|
|
629 |
GIT_DIR=project/.git git-fast-import --import-marks=marks.git
|
|
630 |
||
631 |
If you get a "Missing space after source" error from git-fast-import,
|
|
632 |
see the top of the commands.py module for a work-around.
|
|
633 |
"""
|
|
634 |
hidden = False |
|
635 |
_see_also = ['fast-import', 'fast-import-filter'] |
|
636 |
takes_args = ['source', 'destination?'] |
|
637 |
takes_options = ['verbose', 'revision', |
|
638 |
Option('git-branch', short_name='b', type=str, |
|
639 |
argname='FILE', |
|
640 |
help='Name of the git branch to create (default=master).' |
|
641 |
),
|
|
642 |
Option('checkpoint', type=int, argname='N', |
|
643 |
help="Checkpoint every N revisions (default=10000)." |
|
644 |
),
|
|
645 |
Option('marks', type=str, argname='FILE', |
|
646 |
help="Import marks from and export marks to file." |
|
647 |
),
|
|
648 |
Option('import-marks', type=str, argname='FILE', |
|
649 |
help="Import marks from file." |
|
650 |
),
|
|
651 |
Option('export-marks', type=str, argname='FILE', |
|
652 |
help="Export marks to file." |
|
653 |
),
|
|
654 |
Option('plain', |
|
655 |
help="Exclude metadata to maximise interoperability." |
|
656 |
),
|
|
|
0.133.2
by Oleksandr Usov
Rewrite tag names when exporting plain stream |
657 |
Option('rewrite-tag-names', |
|
0.64.337
by Jelmer Vernooij
Merge support for --rewrite-tag-names. |
658 |
help="Replace characters invalid in git with '_'" |
659 |
" (plain mode only).", |
|
|
0.133.2
by Oleksandr Usov
Rewrite tag names when exporting plain stream |
660 |
),
|
|
0.135.1
by Andy Grimm
Add --baseline option |
661 |
Option('baseline', |
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
662 |
help="Export an 'absolute' baseline commit prior to" |
|
0.135.1
by Andy Grimm
Add --baseline option |
663 |
"the first relative commit", |
664 |
),
|
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
665 |
]
|
666 |
encoding_type = 'exact' |
|
667 |
def run(self, source, destination=None, verbose=False, |
|
668 |
git_branch="master", checkpoint=10000, marks=None, |
|
669 |
import_marks=None, export_marks=None, revision=None, |
|
|
0.135.1
by Andy Grimm
Add --baseline option |
670 |
plain=True, rewrite_tag_names=False, baseline=False): |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
671 |
load_fastimport() |
|
0.64.339
by Jelmer Vernooij
Some refactoring of exporter. |
672 |
from bzrlib.branch import Branch |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
673 |
from bzrlib.plugins.fastimport import exporter |
674 |
||
675 |
if marks: |
|
676 |
import_marks = export_marks = marks |
|
|
0.64.339
by Jelmer Vernooij
Some refactoring of exporter. |
677 |
|
678 |
# Open the source
|
|
679 |
branch = Branch.open_containing(source)[0] |
|
680 |
outf = exporter._get_output_stream(destination) |
|
681 |
exporter = exporter.BzrFastExporter(branch, |
|
682 |
outf=outf, git_branch=git_branch, checkpoint=checkpoint, |
|
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
683 |
import_marks_file=import_marks, export_marks_file=export_marks, |
|
0.133.2
by Oleksandr Usov
Rewrite tag names when exporting plain stream |
684 |
revision=revision, verbose=verbose, plain_format=plain, |
|
0.135.1
by Andy Grimm
Add --baseline option |
685 |
rewrite_tags=rewrite_tag_names, baseline=baseline) |
|
0.64.286
by Jelmer Vernooij
Move command implementations into a separate cmds module. |
686 |
return exporter.run() |