summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2018-03-30 18:24:19 +0100
committerJelmer Vernooij <jelmer@jelmer.uk>2018-03-30 18:24:19 +0100
commitfe5b3d2b2d1f4298342c1b1a1d5631dbbf9270ce (patch)
treedba1340fb42fcf39acf3d9e05685ae2d5dd15ee8 /bin
parentb65623b0ddba5a4ec99d5576e4888fcc1200de97 (diff)
downloadpython-fastimport-git-fe5b3d2b2d1f4298342c1b1a1d5631dbbf9270ce.tar.gz
Add fast-import-{filter,query,info} scripts.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fast-import-filter100
-rwxr-xr-xbin/fast-import-info53
-rwxr-xr-xbin/fast-import-query77
3 files changed, 230 insertions, 0 deletions
diff --git a/bin/fast-import-filter b/bin/fast-import-filter
new file mode 100755
index 0000000..03dbd01
--- /dev/null
+++ b/bin/fast-import-filter
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+
+__doc__ = """Filter a fast-import stream to include/exclude files & directories.
+
+This command is useful for splitting a subdirectory or bunch of
+files out from a project to create a new project complete with history
+for just those files. It can also be used to create a new project
+repository that removes all references to files that should not have
+been committed, e.g. security-related information (like passwords),
+commercially sensitive material, files with an incompatible license or
+large binary files like CD images.
+
+To specify standard input as the input stream, use a source name
+of '-'. If the source name ends in '.gz', it is assumed to be
+compressed in gzip format.
+
+:File/directory filtering:
+
+ This is supported by the -i and -x options. Excludes take precedence
+ over includes.
+
+ When filtering out a subdirectory (or file), the new stream uses the
+ subdirectory (or subdirectory containing the file) as the root. As
+ fast-import doesn't know in advance whether a path is a file or
+ directory in the stream, you need to specify a trailing '/' on
+ directories passed to the `--includes option`. If multiple files or
+ directories are given, the new root is the deepest common directory.
+
+ Note: If a path has been renamed, take care to specify the *original*
+ path name, not the final name that it ends up with.
+
+:History rewriting:
+
+ By default fast-import-filter does quite aggressive history rewriting.
+ Empty commits (or commits which had all their content filtered out) will
+ be removed, and so are the references to commits not included in the stream.
+
+ Flag --dont-squash-empty-commits reverses this behavior and makes it possible to
+ use fast-import-filter on incremental streams.
+
+:Examples:
+
+ Create a new project from a library (note the trailing / on the
+ directory name of the library)::
+
+ front-end | fast-import-filter -i lib/xxx/ > xxx.fi
+ fast-import xxx.fi mylibrary.bzr
+ (lib/xxx/foo is now foo)
+
+ Create a new repository without a sensitive file::
+
+ front-end | fast-import-filter -x missile-codes.txt > clean.fi
+ fast-import clean.fi clean.bzr
+"""
+
+import optparse
+import sys
+
+parser = optparse.OptionParser('fast-import-filter [options] SOURCE?')
+
+parser.add_option('-v', '--verbose', dest="verbose", action="store_true",
+ help="Be verbose.", default=False)
+parser.add_option('-i', '--include-paths', dest="include_paths",
+ action="append", type=str,
+ help="Only include commits affecting these paths."
+ " Directories should have a trailing /.")
+parser.add_option('-x', '--exclude-paths', dest="exclude_paths",
+ type=str, help="Exclude these paths from commits.")
+parser.add_option('--dont-squash-empty-commits',
+ dest="dont_squash_empty_commits", action="store_true",
+ help="Preserve all commits and links between them",
+ default=False)
+
+(opts, args) = parser.parse_args()
+
+if len(args) == 0:
+ source_path = "-"
+elif len(args) == 1:
+ source_path = args[0]
+else:
+ parser.print_usage()
+
+from fastimport.processors import filter_processor
+params = {
+ 'include_paths': opts.include_paths,
+ 'exclude_paths': opts.exclude_paths,
+ }
+params['squash_empty_commits'] = (not opts.dont_squash_empty_commits)
+
+from fastimport.errors import ParsingError
+from fastimport import parser
+from fastimport.helpers import get_source_stream
+stream = get_source_stream(source_path)
+proc = filter_processor.FilterProcessor(params=params, verbose=opts.verbose)
+p = parser.ImportParser(stream, verbose=opts.verbose)
+try:
+ sys.exit(proc.process(p.iter_commands))
+except ParsingError as e:
+ sys.stderr.write("%d: Parse error: %s\n" % (e.lineno, e))
+ sys.exit(1)
diff --git a/bin/fast-import-info b/bin/fast-import-info
new file mode 100755
index 0000000..6f67443
--- /dev/null
+++ b/bin/fast-import-info
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+__doc__ = """Output information about a fast-import stream.
+
+This command reads a fast-import stream and outputs
+statistics and interesting properties about what it finds.
+When run in verbose mode, the information is output as a
+configuration file that can be passed to fast-import to
+assist it in intelligently caching objects.
+
+To specify standard input as the input stream, use a source name
+of '-'. If the source name ends in '.gz', it is assumed to be
+compressed in gzip format.
+
+:Examples:
+
+ Display statistics about the import stream produced by front-end::
+
+ front-end | fast-import-info -
+
+ Create a hints file for running fast-import on a large repository::
+
+ front-end | fast-import-info -v - > front-end.cfg
+"""
+
+import optparse
+import sys
+
+parser = optparse.OptionParser('fast-import-info [options] SOURCE')
+
+parser.add_option('-v', '--verbose', dest="verbose",
+ help="Be verbose.")
+
+(options, args) = parser.parse_args()
+
+if len(args) == 0:
+ source_path = "-"
+elif len(args) == 1:
+ source_path = args[0]
+else:
+ parser.print_usage()
+
+from fastimport.processors import info_processor
+from fastimport.errors import ParsingError
+from fastimport.helpers import get_source_stream
+from fastimport import parser
+stream = get_source_stream(source_path)
+proc = info_processor.InfoProcessor(verbose=options.verbose)
+p = parser.ImportParser(stream, verbose=options.verbose)
+try:
+ sys.exit(proc.process(p.iter_commands))
+except ParsingError as e:
+ sys.stderr.write("%d: Parse error: %s\n" % (e.lineno, e))
+ sys.exit(1)
diff --git a/bin/fast-import-query b/bin/fast-import-query
new file mode 100755
index 0000000..6be68c4
--- /dev/null
+++ b/bin/fast-import-query
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+__doc__ = """Query a fast-import stream displaying selected commands.
+
+To specify standard input as the input stream, use a source name
+of '-'. If the source name ends in '.gz', it is assumed to be
+compressed in gzip format.
+
+To specify a commit to display, give its mark using the
+--commit-mark option. The commit will be displayed with
+file-commands included but with inline blobs hidden.
+
+To specify the commands to display, use the -C option one or
+more times. To specify just some fields for a command, use the
+syntax::
+
+ command=field1,...
+
+By default, the nominated fields for the nominated commands
+are displayed tab separated. To see the information in
+a name:value format, use verbose mode.
+
+Note: Binary fields (e.g. data for blobs) are masked out
+so it is generally safe to view the output in a terminal.
+
+:Examples:
+
+ Show the commit with mark 429::
+
+ fast-import-query xxx.fi -m429
+
+ Show all the fields of the reset and tag commands::
+
+ fast-import-query xxx.fi -Creset -Ctag
+
+ Show the mark and merge fields of the commit commands::
+
+ fast-import-query xxx.fi -Ccommit=mark,merge
+"""
+
+import optparse
+import sys
+
+parser = optparse.OptionParser('fast-import-query [options] SOURCE?')
+
+parser.add_option('-v', '--verbose', dest="verbose",
+ action="store_true", help="Be verbose")
+parser.add_option('-m', '--commit-mark', dest="commit_mark",
+ type=str, help="Mark of the commit to display.")
+parser.add_option('-C', '--commands', type=str,
+ help="Display fields for these commands.")
+
+(opts, args) = parser.parse_args()
+
+if len(args) == 0:
+ source_path = "-"
+elif len(args) == 1:
+ source_path = args[0]
+else:
+ parser.print_usage()
+
+from fastimport.processors import query_processor
+from fastimport.helpers import defines_to_dict, get_source_stream
+from fastimport.errors import ParsingError
+from fastimport import parser
+
+params = defines_to_dict(opts.commands) or {}
+if opts.commit_mark:
+ params['commit-mark'] = opts.commit_mark
+
+stream = get_source_stream(source_path)
+proc = query_processor.QueryProcessor(verbose=opts.verbose, params=params)
+p = parser.ImportParser(stream, verbose=opts.verbose)
+try:
+ sys.exit(proc.process(p.iter_commands))
+except ParsingError as e:
+ sys.stderr.write("%d: Parse error: %s\n" % (e.lineno, e))
+ sys.exit(1)