344
class cmd_fast_import_filter(Command):
345
"""Filter a fast-import stream to include/exclude files & directories.
347
This command is useful for splitting a subdirectory or bunch of
348
files out from a project to create a new project complete with history
349
for just those files. It can also be used to create a new project
350
repository that removes all references to files that should not have
351
been committed, e.g. security-related information (like passwords),
352
commercially sensitive material, files with an incompatible license or
353
large binary files like CD images.
355
To specify standard input as the input stream, use a source name
356
of '-'. If the source name ends in '.gz', it is assumed to be
357
compressed in gzip format.
359
:File/directory filtering:
361
This is supported by the -i and -x options. Excludes take precedence
364
When filtering out a subdirectory (or file), the new stream uses the
365
subdirectory (or subdirectory containing the file) as the root. As
366
fast-import doesn't know in advance whether a path is a file or
367
directory in the stream, you need to specify a trailing '/' on
368
directories passed to the `--includes option`. If multiple files or
369
directories are given, the new root is the deepest common directory.
371
Note: If a path has been renamed, take care to specify the *original*
372
path name, not the final name that it ends up with.
376
Some source repositories store just the user name while Bazaar
377
prefers a full email address. You can adjust user-ids
378
by using the --user-map option. The argument is a
379
text file with lines in the format::
383
Blank lines and lines beginning with # are ignored.
384
If old-id has the special value '@', then users without an
385
email address will get one created by using the matching new-id
386
as the domain, unless a more explicit address is given for them.
387
For example, given the user-map of::
390
bill = William Jones <bill@example.com>
392
then user-ids are mapped as follows::
394
maria => maria <maria@example.com>
395
bill => William Jones <bill@example.com>
399
User mapping is supported by both the fast-import and
400
fast-import-filter commands.
404
By default fast-import-filter does quite aggressive history rewriting.
405
Empty commits (or commits which had all their content filtered out) will
406
be removed, and so are the references to commits not included in the stream.
408
Flag --dont-squash-empty-commits reverses this behavior and makes it possible to
409
use fast-import-filter on incremental streams.
413
Create a new project from a library (note the trailing / on the
414
directory name of the library)::
416
front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
417
bzr fast-import xxx.fi mylibrary.bzr
418
(lib/xxx/foo is now foo)
420
Create a new repository without a sensitive file::
422
front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
423
bzr fast-import clean.fi clean.bzr
426
_see_also = ['fast-import']
427
takes_args = ['source?']
428
takes_options = ['verbose',
429
ListOption('include_paths', short_name='i', type=text_type,
430
help="Only include commits affecting these paths."
431
" Directories should have a trailing /."
433
ListOption('exclude_paths', short_name='x', type=text_type,
434
help="Exclude these paths from commits."
436
Option('user-map', type=text_type,
437
help="Path to file containing a map of user-ids.",
439
Option('dont-squash-empty-commits',
440
help="Preserve all commits and links between them"
443
encoding_type = 'exact'
444
def run(self, source=None, verbose=False, include_paths=None,
445
exclude_paths=None, user_map=None, dont_squash_empty_commits=False):
446
from ...errors import BzrCommandError
448
from fastimport.processors import filter_processor
450
'include_paths': include_paths,
451
'exclude_paths': exclude_paths,
453
if ('squash_empty_commits' in
454
filter_processor.FilterProcessor.known_params):
455
params['squash_empty_commits'] = (not dont_squash_empty_commits)
457
if dont_squash_empty_commits:
458
raise BzrCommandError("installed python-fastimport does not "
459
"support not squashing empty commits. Please install "
460
" a newer python-fastimport to use "
461
"--dont-squash-empty-commits")
463
from fastimport.errors import ParsingError
464
from fastimport import parser
465
stream = _get_source_stream(source)
466
user_mapper = _get_user_mapper(user_map)
467
proc = filter_processor.FilterProcessor(params=params, verbose=verbose)
468
p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
470
return proc.process(p.iter_commands)
471
except ParsingError as e:
472
raise BzrCommandError("%d: Parse error: %s" % (e.lineno, e))
475
class cmd_fast_import_info(Command):
476
"""Output information about a fast-import stream.
478
This command reads a fast-import stream and outputs
479
statistics and interesting properties about what it finds.
480
When run in verbose mode, the information is output as a
481
configuration file that can be passed to fast-import to
482
assist it in intelligently caching objects.
484
To specify standard input as the input stream, use a source name
485
of '-'. If the source name ends in '.gz', it is assumed to be
486
compressed in gzip format.
490
Display statistics about the import stream produced by front-end::
492
front-end | bzr fast-import-info -
494
Create a hints file for running fast-import on a large repository::
496
front-end | bzr fast-import-info -v - > front-end.cfg
499
_see_also = ['fast-import']
500
takes_args = ['source']
501
takes_options = ['verbose']
502
def run(self, source, verbose=False):
504
from .processors import info_processor
505
return _run(source, info_processor.InfoProcessor, verbose=verbose)
508
class cmd_fast_import_query(Command):
509
"""Query a fast-import stream displaying selected commands.
511
To specify standard input as the input stream, use a source name
512
of '-'. If the source name ends in '.gz', it is assumed to be
513
compressed in gzip format.
515
To specify a commit to display, give its mark using the
516
--commit-mark option. The commit will be displayed with
517
file-commands included but with inline blobs hidden.
519
To specify the commands to display, use the -C option one or
520
more times. To specify just some fields for a command, use the
525
By default, the nominated fields for the nominated commands
526
are displayed tab separated. To see the information in
527
a name:value format, use verbose mode.
529
Note: Binary fields (e.g. data for blobs) are masked out
530
so it is generally safe to view the output in a terminal.
534
Show the commit with mark 429::
536
bzr fast-import-query xxx.fi -m429
538
Show all the fields of the reset and tag commands::
540
bzr fast-import-query xxx.fi -Creset -Ctag
542
Show the mark and merge fields of the commit commands::
544
bzr fast-import-query xxx.fi -Ccommit=mark,merge
547
_see_also = ['fast-import', 'fast-import-filter']
548
takes_args = ['source']
549
takes_options = ['verbose',
550
Option('commit-mark', short_name='m', type=text_type,
551
help="Mark of the commit to display."
553
ListOption('commands', short_name='C', type=text_type,
554
help="Display fields for these commands."
557
def run(self, source, verbose=False, commands=None, commit_mark=None):
559
from fastimport.processors import query_processor
560
from . import helpers
561
params = helpers.defines_to_dict(commands) or {}
563
params['commit-mark'] = commit_mark
564
return _run(source, query_processor.QueryProcessor, params=params,
568
344
class cmd_fast_export(Command):
569
345
"""Generate a fast-import stream from a Bazaar branch.