237
238
_see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
238
239
takes_args = ['source', 'destination?']
239
240
takes_options = ['verbose',
240
Option('user-map', type=str,
241
help="Path to file containing a map of user-ids.",
243
Option('info', type=str,
244
help="Path to file containing caching hints.",
247
help="Update all working trees, not just trunk's.",
249
Option('count', type=int,
250
help="Import this many revisions then exit.",
252
Option('checkpoint', type=int,
253
help="Checkpoint automatically every N revisions."
254
" The default is 10000.",
256
Option('autopack', type=int,
257
help="Pack every N checkpoints. The default is 4.",
259
Option('inv-cache', type=int,
260
help="Number of inventories to cache.",
262
RegistryOption.from_kwargs('mode',
263
'The import algorithm to use.',
264
title='Import Algorithm',
265
default='Use the preferred algorithm (inventory deltas).',
266
experimental="Enable experimental features.",
267
value_switches=True, enum_switch=False,
269
Option('import-marks', type=str,
270
help="Import marks from file."
272
Option('export-marks', type=str,
273
help="Export marks to file."
275
RegistryOption('format',
276
help='Specify a format for the created repository. See'
277
' "bzr help formats" for details.',
279
'breezy.controldir', 'format_registry'),
280
converter=lambda name: controldir.format_registry.make_controldir(
282
value_switches=False, title='Repository format'),
241
Option('user-map', type=str,
242
help="Path to file containing a map of user-ids.",
244
Option('info', type=str,
245
help="Path to file containing caching hints.",
248
help="Update all working trees, not just trunk's.",
250
Option('count', type=int,
251
help="Import this many revisions then exit.",
253
Option('checkpoint', type=int,
254
help="Checkpoint automatically every N revisions."
255
" The default is 10000.",
257
Option('autopack', type=int,
258
help="Pack every N checkpoints. The default is 4.",
260
Option('inv-cache', type=int,
261
help="Number of inventories to cache.",
263
RegistryOption.from_kwargs('mode',
264
'The import algorithm to use.',
265
title='Import Algorithm',
266
default='Use the preferred algorithm (inventory deltas).',
267
classic="Use the original algorithm (mutable inventories).",
268
experimental="Enable experimental features.",
269
value_switches=True, enum_switch=False,
271
Option('import-marks', type=str,
272
help="Import marks from file."
274
Option('export-marks', type=str,
275
help="Export marks to file."
277
RegistryOption('format',
278
help='Specify a format for the created repository. See'
279
' "bzr help formats" for details.',
280
lazy_registry=('breezy.controldir', 'format_registry'),
281
converter=lambda name: controldir.format_registry.make_bzrdir(name),
282
value_switches=False, title='Repository format'),
285
284
def run(self, source, destination='.', verbose=False, info=None,
286
trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
287
mode=None, import_marks=None, export_marks=None, format=None,
285
trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
286
mode=None, import_marks=None, export_marks=None, format=None,
289
288
load_fastimport()
290
289
from .processors import generic_processor
291
290
from .helpers import (
340
class cmd_fast_import_filter(Command):
341
"""Filter a fast-import stream to include/exclude files & directories.
343
This command is useful for splitting a subdirectory or bunch of
344
files out from a project to create a new project complete with history
345
for just those files. It can also be used to create a new project
346
repository that removes all references to files that should not have
347
been committed, e.g. security-related information (like passwords),
348
commercially sensitive material, files with an incompatible license or
349
large binary files like CD images.
351
To specify standard input as the input stream, use a source name
352
of '-'. If the source name ends in '.gz', it is assumed to be
353
compressed in gzip format.
355
:File/directory filtering:
357
This is supported by the -i and -x options. Excludes take precedence
360
When filtering out a subdirectory (or file), the new stream uses the
361
subdirectory (or subdirectory containing the file) as the root. As
362
fast-import doesn't know in advance whether a path is a file or
363
directory in the stream, you need to specify a trailing '/' on
364
directories passed to the `--includes option`. If multiple files or
365
directories are given, the new root is the deepest common directory.
367
Note: If a path has been renamed, take care to specify the *original*
368
path name, not the final name that it ends up with.
372
Some source repositories store just the user name while Bazaar
373
prefers a full email address. You can adjust user-ids
374
by using the --user-map option. The argument is a
375
text file with lines in the format::
379
Blank lines and lines beginning with # are ignored.
380
If old-id has the special value '@', then users without an
381
email address will get one created by using the matching new-id
382
as the domain, unless a more explicit address is given for them.
383
For example, given the user-map of::
386
bill = William Jones <bill@example.com>
388
then user-ids are mapped as follows::
390
maria => maria <maria@example.com>
391
bill => William Jones <bill@example.com>
395
User mapping is supported by both the fast-import and
396
fast-import-filter commands.
400
By default fast-import-filter does quite aggressive history rewriting.
401
Empty commits (or commits which had all their content filtered out) will
402
be removed, and so are the references to commits not included in the stream.
404
Flag --dont-squash-empty-commits reverses this behavior and makes it possible to
405
use fast-import-filter on incremental streams.
409
Create a new project from a library (note the trailing / on the
410
directory name of the library)::
412
front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
413
bzr fast-import xxx.fi mylibrary.bzr
414
(lib/xxx/foo is now foo)
416
Create a new repository without a sensitive file::
418
front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
419
bzr fast-import clean.fi clean.bzr
422
_see_also = ['fast-import']
423
takes_args = ['source?']
424
takes_options = ['verbose',
425
ListOption('include_paths', short_name='i', type=str,
426
help="Only include commits affecting these paths."
427
" Directories should have a trailing /."
429
ListOption('exclude_paths', short_name='x', type=str,
430
help="Exclude these paths from commits."
432
Option('user-map', type=str,
433
help="Path to file containing a map of user-ids.",
435
Option('dont-squash-empty-commits',
436
help="Preserve all commits and links between them"
439
encoding_type = 'exact'
440
def run(self, source=None, verbose=False, include_paths=None,
441
exclude_paths=None, user_map=None, dont_squash_empty_commits=False):
442
from ...errors import BzrCommandError
444
from fastimport.processors import filter_processor
446
'include_paths': include_paths,
447
'exclude_paths': exclude_paths,
449
if ('squash_empty_commits' in
450
filter_processor.FilterProcessor.known_params):
451
params['squash_empty_commits'] = (not dont_squash_empty_commits)
453
if dont_squash_empty_commits:
454
raise BzrCommandError("installed python-fastimport does not "
455
"support not squashing empty commits. Please install "
456
" a newer python-fastimport to use "
457
"--dont-squash-empty-commits")
459
from fastimport.errors import ParsingError
460
from fastimport import parser
461
stream = _get_source_stream(source)
462
user_mapper = _get_user_mapper(user_map)
463
proc = filter_processor.FilterProcessor(params=params, verbose=verbose)
464
p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
466
return proc.process(p.iter_commands)
467
except ParsingError, e:
468
raise BzrCommandError("%d: Parse error: %s" % (e.lineno, e))
471
class cmd_fast_import_info(Command):
472
"""Output information about a fast-import stream.
474
This command reads a fast-import stream and outputs
475
statistics and interesting properties about what it finds.
476
When run in verbose mode, the information is output as a
477
configuration file that can be passed to fast-import to
478
assist it in intelligently caching objects.
480
To specify standard input as the input stream, use a source name
481
of '-'. If the source name ends in '.gz', it is assumed to be
482
compressed in gzip format.
486
Display statistics about the import stream produced by front-end::
488
front-end | bzr fast-import-info -
490
Create a hints file for running fast-import on a large repository::
492
front-end | bzr fast-import-info -v - > front-end.cfg
495
_see_also = ['fast-import']
496
takes_args = ['source']
497
takes_options = ['verbose']
498
def run(self, source, verbose=False):
500
from .processors import info_processor
501
return _run(source, info_processor.InfoProcessor, verbose=verbose)
504
class cmd_fast_import_query(Command):
505
"""Query a fast-import stream displaying selected commands.
507
To specify standard input as the input stream, use a source name
508
of '-'. If the source name ends in '.gz', it is assumed to be
509
compressed in gzip format.
511
To specify a commit to display, give its mark using the
512
--commit-mark option. The commit will be displayed with
513
file-commands included but with inline blobs hidden.
515
To specify the commands to display, use the -C option one or
516
more times. To specify just some fields for a command, use the
521
By default, the nominated fields for the nominated commands
522
are displayed tab separated. To see the information in
523
a name:value format, use verbose mode.
525
Note: Binary fields (e.g. data for blobs) are masked out
526
so it is generally safe to view the output in a terminal.
530
Show the commit with mark 429::
532
bzr fast-import-query xxx.fi -m429
534
Show all the fields of the reset and tag commands::
536
bzr fast-import-query xxx.fi -Creset -Ctag
538
Show the mark and merge fields of the commit commands::
540
bzr fast-import-query xxx.fi -Ccommit=mark,merge
543
_see_also = ['fast-import', 'fast-import-filter']
544
takes_args = ['source']
545
takes_options = ['verbose',
546
Option('commit-mark', short_name='m', type=str,
547
help="Mark of the commit to display."
549
ListOption('commands', short_name='C', type=str,
550
help="Display fields for these commands."
553
def run(self, source, verbose=False, commands=None, commit_mark=None):
555
from fastimport.processors import query_processor
556
from . import helpers
557
params = helpers.defines_to_dict(commands) or {}
559
params['commit-mark'] = commit_mark
560
return _run(source, query_processor.QueryProcessor, params=params,
341
564
class cmd_fast_export(Command):
342
565
"""Generate a fast-import stream from a Bazaar branch.
443
666
_see_also = ['fast-import', 'fast-import-filter']
444
667
takes_args = ['source?', 'destination?']
445
668
takes_options = ['verbose', 'revision',
446
Option('git-branch', short_name='b', type=str,
448
help='Name of the git branch to create (default=master).'
450
Option('checkpoint', type=int, argname='N',
451
help="Checkpoint every N revisions (default=10000)."
453
Option('marks', type=str, argname='FILE',
454
help="Import marks from and export marks to file."
456
Option('import-marks', type=str, argname='FILE',
457
help="Import marks from file."
459
Option('export-marks', type=str, argname='FILE',
460
help="Export marks to file."
463
help="Exclude metadata to maximise interoperability."
465
Option('rewrite-tag-names',
466
help="Replace characters invalid in git with '_'"
467
" (plain mode only).",
470
help="Export an 'absolute' baseline commit prior to"
471
"the first relative commit",
474
help="Don't export tags"
669
Option('git-branch', short_name='b', type=str,
671
help='Name of the git branch to create (default=master).'
673
Option('checkpoint', type=int, argname='N',
674
help="Checkpoint every N revisions (default=10000)."
676
Option('marks', type=str, argname='FILE',
677
help="Import marks from and export marks to file."
679
Option('import-marks', type=str, argname='FILE',
680
help="Import marks from file."
682
Option('export-marks', type=str, argname='FILE',
683
help="Export marks to file."
686
help="Exclude metadata to maximise interoperability."
688
Option('rewrite-tag-names',
689
help="Replace characters invalid in git with '_'"
690
" (plain mode only).",
693
help="Export an 'absolute' baseline commit prior to"
694
"the first relative commit",
697
help="Don't export tags"
477
700
encoding_type = 'exact'
479
701
def run(self, source=None, destination=None, verbose=False,
480
git_branch="master", checkpoint=10000, marks=None,
481
import_marks=None, export_marks=None, revision=None,
482
plain=True, rewrite_tag_names=False, no_tags=False, baseline=False):
702
git_branch="master", checkpoint=10000, marks=None,
703
import_marks=None, export_marks=None, revision=None,
704
plain=True, rewrite_tag_names=False, no_tags=False, baseline=False):
483
705
load_fastimport()
484
706
from ...branch import Branch
485
707
from . import exporter