Fix import of single_plural.
[bzr-fastimport.git] / __init__.py
blob2fc555c1cee73b2dc2df6a13d9b144e535c7f0a6
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
17 r"""FastImport Plugin
18 =================
20 The fastimport plugin provides stream-based importing and exporting of
21 data into and out of Bazaar. As well as enabling interchange between
22 multiple VCS tools, fastimport/export can be useful for complex branch
23 operations, e.g. partitioning off part of a code base in order to Open
24 Source it.
26 The normal import recipe is::
28 bzr fast-export-from-xxx SOURCE project.fi
29 bzr fast-import project.fi project.bzr
31 If fast-export-from-xxx doesn't exist yet for the tool you're importing
32 from, the alternative recipe is::
34 front-end > project.fi
35 bzr fast-import project.fi project.bzr
37 In either case, if you wish to save disk space, project.fi can be
38 compressed to gzip format after it is generated like this::
40 (generate project.fi)
41 gzip project.fi
42 bzr fast-import project.fi.gz project.bzr
44 The list of known front-ends and their status is documented on
45 http://bazaar-vcs.org/BzrFastImport/FrontEnds. The fast-export-from-xxx
46 commands provide simplified access to these so that the majority of users
47 can generate a fast-import dump file without needing to study up on all
48 the options - and the best combination of them to use - for the front-end
49 relevant to them. In some cases, a fast-export-from-xxx wrapper will require
50 that certain dependencies are installed so it checks for these before
51 starting. A wrapper may also provide a limited set of options. See the
52 online help for the individual commands for details::
54 bzr help fast-export-from-cvs
55 bzr help fast-export-from-darcs
56 bzr help fast-export-from-hg
57 bzr help fast-export-from-git
58 bzr help fast-export-from-mtn
59 bzr help fast-export-from-p4
60 bzr help fast-export-from-svn
62 Once a fast-import dump file is created, it can be imported into a
63 Bazaar repository using the fast-import command. If required, you can
64 manipulate the stream first using the fast-import-filter command.
65 This is useful for creating a repository with just part of a project
66 or for removing large old binaries (say) from history that are no longer
67 valuable to retain. For further details on importing, manipulating and
68 reporting on fast-import streams, see the online help for the commands::
70 bzr help fast-import
71 bzr help fast-import-filter
72 bzr help fast-import-info
73 bzr help fast-import-query
75 Finally, you may wish to generate a fast-import dump file from a Bazaar
76 repository. The fast-export command is provided for that purpose.
78 To report bugs or publish enhancements, visit the bzr-fastimport project
79 page on Launchpad, https://launchpad.net/bzr-fastimport.
80 """
82 version_info = (0, 10, 0, 'dev', 0)
84 from bzrlib import bzrdir
85 from bzrlib.commands import Command, register_command
86 from bzrlib.option import Option, ListOption, RegistryOption
89 def load_fastimport():
90 """Load the fastimport module or raise an appropriate exception."""
91 try:
92 import fastimport
93 except ImportError, e:
94 from bzrlib.errors import DependencyNotPresent
95 raise DependencyNotPresent("fastimport", e)
98 def test_suite():
99 import tests
100 return tests.test_suite()
103 def _run(source, processor_factory, control, params, verbose,
104 user_map=None):
105 """Create and run a processor.
107 :param source: a filename or '-' for standard input. If the
108 filename ends in .gz, it will be opened as a gzip file and
109 the stream will be implicitly uncompressed
110 :param processor_factory: a callable for creating a processor
111 :param control: the BzrDir of the destination or None if no
112 destination is expected
113 :param user_map: if not None, the file containing the user map.
115 from fastimport import parser
116 stream = _get_source_stream(source)
117 user_mapper = _get_user_mapper(user_map)
118 proc = processor_factory(control, params=params, verbose=verbose)
119 p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
120 return proc.process(p.iter_commands)
123 def _get_source_stream(source):
124 if source == '-':
125 import sys
126 from fastimport import helpers
127 stream = helpers.binary_stream(sys.stdin)
128 elif source.endswith('.gz'):
129 import gzip
130 stream = gzip.open(source, "rb")
131 else:
132 stream = open(source, "rb")
133 return stream
136 def _get_user_mapper(filename):
137 import user_mapper
138 if filename is None:
139 return None
140 f = open(filename)
141 lines = f.readlines()
142 f.close()
143 return user_mapper.UserMapper(lines)
146 class cmd_fast_import(Command):
147 """Backend for fast Bazaar data importers.
149 This command reads a mixed command/data stream and creates
150 branches in a Bazaar repository accordingly. The preferred
151 recipe is::
153 bzr fast-import project.fi project.bzr
155 Numerous commands are provided for generating a fast-import file
156 to use as input. These are named fast-export-from-xxx where xxx
157 is one of cvs, darcs, git, hg, mtn, p4 or svn.
158 To specify standard input as the input stream, use a
159 source name of '-' (instead of project.fi). If the source name
160 ends in '.gz', it is assumed to be compressed in gzip format.
162 project.bzr will be created if it doesn't exist. If it exists
163 already, it should be empty or be an existing Bazaar repository
164 or branch. If not specified, the current directory is assumed.
166 fast-import will intelligently select the format to use when
167 creating a repository or branch. If you are running Bazaar 1.17
168 up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
169 Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
170 is used. If you wish to specify a custom format, use the `--format`
171 option.
173 .. note::
175 To maintain backwards compatibility, fast-import lets you
176 create the target repository or standalone branch yourself.
177 It is recommended though that you let fast-import create
178 these for you instead.
180 :Branch mapping rules:
182 Git reference names are mapped to Bazaar branch names as follows:
184 * refs/heads/foo is mapped to foo
185 * refs/remotes/origin/foo is mapped to foo.remote
186 * refs/tags/foo is mapped to foo.tag
187 * */master is mapped to trunk, trunk.remote, etc.
188 * */trunk is mapped to git-trunk, git-trunk.remote, etc.
190 :Branch creation rules:
192 When a shared repository is created or found at the destination,
193 branches are created inside it. In the simple case of a single
194 branch (refs/heads/master) inside the input file, the branch is
195 project.bzr/trunk.
197 When a standalone branch is found at the destination, the trunk
198 is imported there and warnings are output about any other branches
199 found in the input file.
201 When a branch in a shared repository is found at the destination,
202 that branch is made the trunk and other branches, if any, are
203 created in sister directories.
205 :Working tree updates:
207 The working tree is generated for the trunk branch. If multiple
208 branches are created, a message is output on completion explaining
209 how to create the working trees for other branches.
211 :Custom exporters:
213 The fast-export-from-xxx commands typically call more advanced
214 xxx-fast-export scripts. You are welcome to use the advanced
215 scripts if you prefer.
217 If you wish to write a custom exporter for your project, see
218 http://bazaar-vcs.org/BzrFastImport for the detailed protocol
219 specification. In many cases, exporters can be written quite
220 quickly using whatever scripting/programming language you like.
222 :User mapping:
224 Some source repositories store just the user name while Bazaar
225 prefers a full email address. You can adjust user-ids while
226 importing by using the --user-map option. The argument is a
227 text file with lines in the format::
229 old-id = new-id
231 Blank lines and lines beginning with # are ignored.
232 If old-id has the special value '@', then users without an
233 email address will get one created by using the matching new-id
234 as the domain, unless a more explicit address is given for them.
235 For example, given the user-map of::
237 @ = example.com
238 bill = William Jones <bill@example.com>
240 then user-ids are mapped as follows::
242 maria => maria <maria@example.com>
243 bill => William Jones <bill@example.com>
245 .. note::
247 User mapping is supported by both the fast-import and
248 fast-import-filter commands.
250 :Blob tracking:
252 As some exporters (like git-fast-export) reuse blob data across
253 commits, fast-import makes two passes over the input file by
254 default. In the first pass, it collects data about what blobs are
255 used when, along with some other statistics (e.g. total number of
256 commits). In the second pass, it generates the repository and
257 branches.
259 .. note::
261 The initial pass isn't done if the --info option is used
262 to explicitly pass in information about the input stream.
263 It also isn't done if the source is standard input. In the
264 latter case, memory consumption may be higher than otherwise
265 because some blobs may be kept in memory longer than necessary.
267 :Restarting an import:
269 At checkpoints and on completion, the commit-id -> revision-id
270 map is saved to a file called 'fastimport-id-map' in the control
271 directory for the repository (e.g. .bzr/repository). If the import
272 is interrupted or unexpectedly crashes, it can be started again
273 and this file will be used to skip over already loaded revisions.
274 As long as subsequent exports from the original source begin
275 with exactly the same revisions, you can use this feature to
276 maintain a mirror of a repository managed by a foreign tool.
277 If and when Bazaar is used to manage the repository, this file
278 can be safely deleted.
280 :Examples:
282 Import a Subversion repository into Bazaar::
284 bzr fast-export-from-svn /svn/repo/path project.fi
285 bzr fast-import project.fi project.bzr
287 Import a CVS repository into Bazaar::
289 bzr fast-export-from-cvs /cvs/repo/path project.fi
290 bzr fast-import project.fi project.bzr
292 Import a Git repository into Bazaar::
294 bzr fast-export-from-git /git/repo/path project.fi
295 bzr fast-import project.fi project.bzr
297 Import a Mercurial repository into Bazaar::
299 bzr fast-export-from-hg /hg/repo/path project.fi
300 bzr fast-import project.fi project.bzr
302 Import a Darcs repository into Bazaar::
304 bzr fast-export-from-darcs /darcs/repo/path project.fi
305 bzr fast-import project.fi project.bzr
307 hidden = False
308 _see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
309 takes_args = ['source', 'destination?']
310 takes_options = ['verbose',
311 Option('user-map', type=str,
312 help="Path to file containing a map of user-ids.",
314 Option('info', type=str,
315 help="Path to file containing caching hints.",
317 Option('trees',
318 help="Update all working trees, not just trunk's.",
320 Option('count', type=int,
321 help="Import this many revisions then exit.",
323 Option('checkpoint', type=int,
324 help="Checkpoint automatically every N revisions."
325 " The default is 10000.",
327 Option('autopack', type=int,
328 help="Pack every N checkpoints. The default is 4.",
330 Option('inv-cache', type=int,
331 help="Number of inventories to cache.",
333 RegistryOption.from_kwargs('mode',
334 'The import algorithm to use.',
335 title='Import Algorithm',
336 default='Use the preferred algorithm (inventory deltas).',
337 classic="Use the original algorithm (mutable inventories).",
338 experimental="Enable experimental features.",
339 value_switches=True, enum_switch=False,
341 Option('import-marks', type=str,
342 help="Import marks from file."
344 Option('export-marks', type=str,
345 help="Export marks to file."
347 RegistryOption('format',
348 help='Specify a format for the created repository. See'
349 ' "bzr help formats" for details.',
350 lazy_registry=('bzrlib.bzrdir', 'format_registry'),
351 converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
352 value_switches=False, title='Repository format'),
354 aliases = []
355 def run(self, source, destination='.', verbose=False, info=None,
356 trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
357 mode=None, import_marks=None, export_marks=None, format=None,
358 user_map=None):
359 load_fastimport()
360 from bzrlib.plugins.fastimport.processors import generic_processor
361 from bzrlib.plugins.fastimport.helpers import (
362 open_destination_directory,
364 # If no format is given and the user is running a release
365 # leading up to 2.0, select 2a for them. Otherwise, use
366 # the default format.
367 if format is None:
368 import bzrlib
369 bzr_version = bzrlib.version_info[0:2]
370 if bzr_version in [(1,17), (1,18), (2,0)]:
371 format = bzrdir.format_registry.make_bzrdir('2a')
372 control = open_destination_directory(destination, format=format)
374 # If an information file was given and the source isn't stdin,
375 # generate the information by reading the source file as a first pass
376 if info is None and source != '-':
377 info = self._generate_info(source)
379 # Do the work
380 if mode is None:
381 mode = 'default'
382 params = {
383 'info': info,
384 'trees': trees,
385 'count': count,
386 'checkpoint': checkpoint,
387 'autopack': autopack,
388 'inv-cache': inv_cache,
389 'mode': mode,
390 'import-marks': import_marks,
391 'export-marks': export_marks,
393 return _run(source, generic_processor.GenericProcessor, control,
394 params, verbose, user_map=user_map)
396 def _generate_info(self, source):
397 from cStringIO import StringIO
398 from fastimport import parser
399 from fastimport.processors import info_processor
400 stream = _get_source_stream(source)
401 output = StringIO()
402 try:
403 proc = info_processor.InfoProcessor(verbose=True, outf=output)
404 p = parser.ImportParser(stream)
405 return_code = proc.process(p.iter_commands)
406 lines = output.getvalue().splitlines()
407 finally:
408 output.close()
409 stream.seek(0)
410 return lines
413 class cmd_fast_import_filter(Command):
414 """Filter a fast-import stream to include/exclude files & directories.
416 This command is useful for splitting a subdirectory or bunch of
417 files out from a project to create a new project complete with history
418 for just those files. It can also be used to create a new project
419 repository that removes all references to files that should not have
420 been committed, e.g. security-related information (like passwords),
421 commercially sensitive material, files with an incompatible license or
422 large binary files like CD images.
424 To specify standard input as the input stream, use a source name
425 of '-'. If the source name ends in '.gz', it is assumed to be
426 compressed in gzip format.
428 :File/directory filtering:
430 This is supported by the -i and -x options. Excludes take precedence
431 over includes.
433 When filtering out a subdirectory (or file), the new stream uses the
434 subdirectory (or subdirectory containing the file) as the root. As
435 fast-import doesn't know in advance whether a path is a file or
436 directory in the stream, you need to specify a trailing '/' on
437 directories passed to the `--includes option`. If multiple files or
438 directories are given, the new root is the deepest common directory.
440 Note: If a path has been renamed, take care to specify the *original*
441 path name, not the final name that it ends up with.
443 :User mapping:
445 Some source repositories store just the user name while Bazaar
446 prefers a full email address. You can adjust user-ids
447 by using the --user-map option. The argument is a
448 text file with lines in the format::
450 old-id = new-id
452 Blank lines and lines beginning with # are ignored.
453 If old-id has the special value '@', then users without an
454 email address will get one created by using the matching new-id
455 as the domain, unless a more explicit address is given for them.
456 For example, given the user-map of::
458 @ = example.com
459 bill = William Jones <bill@example.com>
461 then user-ids are mapped as follows::
463 maria => maria <maria@example.com>
464 bill => William Jones <bill@example.com>
466 .. note::
468 User mapping is supported by both the fast-import and
469 fast-import-filter commands.
471 :Examples:
473 Create a new project from a library (note the trailing / on the
474 directory name of the library)::
476 front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
477 bzr fast-import xxx.fi mylibrary.bzr
478 (lib/xxx/foo is now foo)
480 Create a new repository without a sensitive file::
482 front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
483 bzr fast-import clean.fi clean.bzr
485 hidden = False
486 _see_also = ['fast-import']
487 takes_args = ['source']
488 takes_options = ['verbose',
489 ListOption('include_paths', short_name='i', type=str,
490 help="Only include commits affecting these paths."
491 " Directories should have a trailing /."
493 ListOption('exclude_paths', short_name='x', type=str,
494 help="Exclude these paths from commits."
496 Option('user-map', type=str,
497 help="Path to file containing a map of user-ids.",
500 aliases = []
501 encoding_type = 'exact'
502 def run(self, source, verbose=False, include_paths=None,
503 exclude_paths=None, user_map=None):
504 load_fastimport()
505 from fastimport.processors import filter_processor
506 params = {
507 'include_paths': include_paths,
508 'exclude_paths': exclude_paths,
510 return _run(source, filter_processor.FilterProcessor, params,
511 verbose, user_map=user_map)
514 class cmd_fast_import_info(Command):
515 """Output information about a fast-import stream.
517 This command reads a fast-import stream and outputs
518 statistics and interesting properties about what it finds.
519 When run in verbose mode, the information is output as a
520 configuration file that can be passed to fast-import to
521 assist it in intelligently caching objects.
523 To specify standard input as the input stream, use a source name
524 of '-'. If the source name ends in '.gz', it is assumed to be
525 compressed in gzip format.
527 :Examples:
529 Display statistics about the import stream produced by front-end::
531 front-end | bzr fast-import-info -
533 Create a hints file for running fast-import on a large repository::
535 front-end | bzr fast-import-info -v - > front-end.cfg
537 hidden = False
538 _see_also = ['fast-import']
539 takes_args = ['source']
540 takes_options = ['verbose']
541 aliases = []
542 def run(self, source, verbose=False):
543 load_fastimport()
544 from fastimport.processors import info_processor
545 return _run(source, info_processor.InfoProcessor, {}, verbose)
548 class cmd_fast_import_query(Command):
549 """Query a fast-import stream displaying selected commands.
551 To specify standard input as the input stream, use a source name
552 of '-'. If the source name ends in '.gz', it is assumed to be
553 compressed in gzip format.
555 To specify a commit to display, give its mark using the
556 --commit-mark option. The commit will be displayed with
557 file-commands included but with inline blobs hidden.
559 To specify the commands to display, use the -C option one or
560 more times. To specify just some fields for a command, use the
561 syntax::
563 command=field1,...
565 By default, the nominated fields for the nominated commands
566 are displayed tab separated. To see the information in
567 a name:value format, use verbose mode.
569 Note: Binary fields (e.g. data for blobs) are masked out
570 so it is generally safe to view the output in a terminal.
572 :Examples:
574 Show the commit with mark 429::
576 bzr fast-import-query xxx.fi -m429
578 Show all the fields of the reset and tag commands::
580 bzr fast-import-query xxx.fi -Creset -Ctag
582 Show the mark and merge fields of the commit commands::
584 bzr fast-import-query xxx.fi -Ccommit=mark,merge
586 hidden = True
587 _see_also = ['fast-import', 'fast-import-filter']
588 takes_args = ['source']
589 takes_options = ['verbose',
590 Option('commit-mark', short_name='m', type=str,
591 help="Mark of the commit to display."
593 ListOption('commands', short_name='C', type=str,
594 help="Display fields for these commands."
597 aliases = []
598 def run(self, source, verbose=False, commands=None, commit_mark=None):
599 load_fastimport()
600 from fastimport.processors import query_processor
601 from bzrlib.plugins.fastimport import helpers
602 params = helpers.defines_to_dict(commands) or {}
603 if commit_mark:
604 params['commit-mark'] = commit_mark
605 return _run(source, query_processor.QueryProcessor, params,
606 verbose)
609 class cmd_fast_export(Command):
610 """Generate a fast-import stream from a Bazaar branch.
612 This program generates a stream from a Bazaar branch in fast-import
613 format used by tools such as bzr fast-import, git-fast-import and
614 hg-fast-import.
616 If no destination is given or the destination is '-', standard output
617 is used. Otherwise, the destination is the name of a file. If the
618 destination ends in '.gz', the output will be compressed into gzip
619 format.
621 :Round-tripping:
623 Recent versions of the fast-import specification support features
624 that allow effective round-tripping of many Bazaar branches. As
625 such, fast-exporting a branch and fast-importing the data produced
626 will create a new repository with equivalent history, i.e.
627 "bzr log -v -p --include-merges --forward" on the old branch and
628 new branch should produce similar, if not identical, results.
630 .. note::
632 Be aware that the new repository may appear to have similar history
633 but internally it is quite different with new revision-ids and
634 file-ids assigned. As a consequence, the ability to easily merge
635 with branches based on the old repository is lost. Depending on your
636 reasons for producing a new repository, this may or may not be an
637 issue.
639 :Interoperability:
641 fast-export can use the following "extended features" to
642 produce a richer data stream:
644 * *multiple-authors* - if a commit has multiple authors (as commonly
645 occurs in pair-programming), all authors will be included in the
646 output, not just the first author
648 * *commit-properties* - custom metadata per commit that Bazaar stores
649 in revision properties (e.g. branch-nick and bugs fixed by this
650 change) will be included in the output.
652 * *empty-directories* - directories, even the empty ones, will be
653 included in the output.
655 To disable these features and produce output acceptable to git 1.6,
656 use the --plain option. To enable these features, use --no-plain.
657 Currently, --plain is the default but that will change in the near
658 future once the feature names and definitions are formally agreed
659 to by the broader fast-import developer community.
661 :Examples:
663 To produce data destined for import into Bazaar::
665 bzr fast-export --no-plain my-bzr-branch my.fi.gz
667 To produce data destined for Git 1.6::
669 bzr fast-export --plain my-bzr-branch my.fi
671 To import several unmerged but related branches into the same repository,
672 use the --{export,import}-marks options, and specify a name for the git
673 branch like this::
675 bzr fast-export --export-marks=marks.bzr project.dev |
676 GIT_DIR=project/.git git-fast-import --export-marks=marks.git
678 bzr fast-export --import-marks=marks.bzr -b other project.other |
679 GIT_DIR=project/.git git-fast-import --import-marks=marks.git
681 If you get a "Missing space after source" error from git-fast-import,
682 see the top of the commands.py module for a work-around.
684 hidden = False
685 _see_also = ['fast-import', 'fast-import-filter']
686 takes_args = ['source', 'destination?']
687 takes_options = ['verbose', 'revision',
688 Option('git-branch', short_name='b', type=str,
689 argname='FILE',
690 help='Name of the git branch to create (default=master).'
692 Option('checkpoint', type=int, argname='N',
693 help="Checkpoint every N revisions (default=10000)."
695 Option('marks', type=str, argname='FILE',
696 help="Import marks from and export marks to file."
698 Option('import-marks', type=str, argname='FILE',
699 help="Import marks from file."
701 Option('export-marks', type=str, argname='FILE',
702 help="Export marks to file."
704 Option('plain',
705 help="Exclude metadata to maximise interoperability."
708 aliases = []
709 encoding_type = 'exact'
710 def run(self, source, destination=None, verbose=False,
711 git_branch="master", checkpoint=10000, marks=None,
712 import_marks=None, export_marks=None, revision=None,
713 plain=True):
714 load_fastimport()
715 from bzrlib.plugins.fastimport import exporter
717 if marks:
718 import_marks = export_marks = marks
719 exporter = exporter.BzrFastExporter(source,
720 destination=destination,
721 git_branch=git_branch, checkpoint=checkpoint,
722 import_marks_file=import_marks, export_marks_file=export_marks,
723 revision=revision, verbose=verbose, plain_format=plain)
724 return exporter.run()
727 class cmd_fast_export_from_cvs(Command):
728 """Generate a fast-import file from a CVS repository.
730 Destination is a dump file, typically named xxx.fi where xxx is
731 the name of the project. If '-' is given, standard output is used.
733 cvs2svn 2.3 or later must be installed as its cvs2bzr script is used
734 under the covers to do the export.
736 The source must be the path on your filesystem to the part of the
737 repository you wish to convert. i.e. either that path or a parent
738 directory must contain a CVSROOT subdirectory. The path may point to
739 either the top of a repository or to a path within it. In the latter
740 case, only that project within the repository will be converted.
742 .. note::
743 Remote access to the repository is not sufficient - the path
744 must point into a copy of the repository itself. See
745 http://cvs2svn.tigris.org/faq.html#repoaccess for instructions
746 on how to clone a remote CVS repository locally.
748 By default, the trunk, branches and tags are all exported. If you
749 only want the trunk, use the `--trunk-only` option.
751 By default, filenames, log messages and author names are expected
752 to be encoded in ascii. Use the `--encoding` option to specify an
753 alternative. If multiple encodings are used, specify the option
754 multiple times. For a list of valid encoding names, see
755 http://docs.python.org/lib/standard-encodings.html.
757 Windows users need to install GNU sort and use the `--sort`
758 option to specify its location. GNU sort can be downloaded from
759 http://unxutils.sourceforge.net/.
761 hidden = False
762 _see_also = ['fast-import', 'fast-import-filter']
763 takes_args = ['source', 'destination']
764 takes_options = ['verbose',
765 Option('trunk-only',
766 help="Export just the trunk, ignoring tags and branches."
768 ListOption('encoding', type=str, argname='CODEC',
769 help="Encoding used for filenames, commit messages "
770 "and author names if not ascii."
772 Option('sort', type=str, argname='PATH',
773 help="GNU sort program location if not on the path."
776 aliases = []
777 encoding_type = 'exact'
778 def run(self, source, destination, verbose=False, trunk_only=False,
779 encoding=None, sort=None):
780 load_fastimport()
781 from bzrlib.plugins.fastimport.exporters import fast_export_from
782 custom = []
783 if trunk_only:
784 custom.append("--trunk-only")
785 if encoding:
786 for enc in encoding:
787 custom.extend(['--encoding', enc])
788 if sort:
789 custom.extend(['--sort', sort])
790 fast_export_from(source, destination, 'cvs', verbose, custom)
793 class cmd_fast_export_from_darcs(Command):
794 """Generate a fast-import file from a Darcs repository.
796 Destination is a dump file, typically named xxx.fi where xxx is
797 the name of the project. If '-' is given, standard output is used.
799 Darcs 2.2 or later must be installed as various subcommands are
800 used to access the source repository. The source may be a network
801 URL but using a local URL is recommended for performance reasons.
803 hidden = False
804 _see_also = ['fast-import', 'fast-import-filter']
805 takes_args = ['source', 'destination']
806 takes_options = ['verbose',
807 Option('encoding', type=str, argname='CODEC',
808 help="Encoding used for commit messages if not utf-8."
811 aliases = []
812 encoding_type = 'exact'
813 def run(self, source, destination, verbose=False, encoding=None):
814 from bzrlib.plugins.fastimport.exporters import fast_export_from
815 custom = None
816 if encoding is not None:
817 custom = ['--encoding', encoding]
818 fast_export_from(source, destination, 'darcs', verbose, custom)
821 class cmd_fast_export_from_hg(Command):
822 """Generate a fast-import file from a Mercurial repository.
824 Destination is a dump file, typically named xxx.fi where xxx is
825 the name of the project. If '-' is given, standard output is used.
827 Mercurial 1.2 or later must be installed as its libraries are used
828 to access the source repository. Given the APIs currently used,
829 the source repository must be a local file, not a network URL.
831 hidden = False
832 _see_also = ['fast-import', 'fast-import-filter']
833 takes_args = ['source', 'destination']
834 takes_options = ['verbose']
835 aliases = []
836 encoding_type = 'exact'
837 def run(self, source, destination, verbose=False):
838 load_fastimport()
839 from bzrlib.plugins.fastimport.exporters import fast_export_from
840 fast_export_from(source, destination, 'hg', verbose)
843 class cmd_fast_export_from_git(Command):
844 """Generate a fast-import file from a Git repository.
846 Destination is a dump file, typically named xxx.fi where xxx is
847 the name of the project. If '-' is given, standard output is used.
849 Git 1.6 or later must be installed as the git fast-export
850 subcommand is used under the covers to generate the stream.
851 The source must be a local directory.
853 .. note::
855 Earlier versions of Git may also work fine but are
856 likely to receive less active support if problems arise.
858 hidden = False
859 _see_also = ['fast-import', 'fast-import-filter']
860 takes_args = ['source', 'destination']
861 takes_options = ['verbose']
862 aliases = []
863 encoding_type = 'exact'
864 def run(self, source, destination, verbose=False):
865 load_fastimport()
866 from bzrlib.plugins.fastimport.exporters import fast_export_from
867 fast_export_from(source, destination, 'git', verbose)
870 class cmd_fast_export_from_mtn(Command):
871 """Generate a fast-import file from a Monotone repository.
873 Destination is a dump file, typically named xxx.fi where xxx is
874 the name of the project. If '-' is given, standard output is used.
876 Monotone 0.43 or later must be installed as the mtn git_export
877 subcommand is used under the covers to generate the stream.
878 The source must be a local directory.
880 hidden = False
881 _see_also = ['fast-import', 'fast-import-filter']
882 takes_args = ['source', 'destination']
883 takes_options = ['verbose']
884 aliases = []
885 encoding_type = 'exact'
886 def run(self, source, destination, verbose=False):
887 load_fastimport()
888 from bzrlib.plugins.fastimport.exporters import fast_export_from
889 fast_export_from(source, destination, 'mtn', verbose)
892 class cmd_fast_export_from_p4(Command):
893 """Generate a fast-import file from a Perforce repository.
895 Source is a Perforce depot path, e.g., //depot/project
897 Destination is a dump file, typically named xxx.fi where xxx is
898 the name of the project. If '-' is given, standard output is used.
900 bzrp4 must be installed as its p4_fast_export.py module is used under
901 the covers to do the export. bzrp4 can be downloaded from
902 https://launchpad.net/bzrp4/.
904 The P4PORT environment variable must be set, and you must be logged
905 into the Perforce server.
907 By default, only the HEAD changelist is exported. To export all
908 changelists, append '@all' to the source. To export a revision range,
909 append a comma-delimited pair of changelist numbers to the source,
910 e.g., '100,200'.
912 hidden = False
913 _see_also = ['fast-import', 'fast-import-filter']
914 takes_args = ['source', 'destination']
915 takes_options = []
916 aliases = []
917 encoding_type = 'exact'
918 def run(self, source, destination, verbose=False):
919 load_fastimport()
920 from bzrlib.plugins.fastimport.exporters import fast_export_from
921 custom = []
922 fast_export_from(source, destination, 'p4', verbose, custom)
925 class cmd_fast_export_from_svn(Command):
926 """Generate a fast-import file from a Subversion repository.
928 Destination is a dump file, typically named xxx.fi where xxx is
929 the name of the project. If '-' is given, standard output is used.
931 Python-Subversion (Python bindings to the Subversion APIs)
932 1.4 or later must be installed as this library is used to
933 access the source repository. The source may be a network URL
934 but using a local URL is recommended for performance reasons.
936 hidden = False
937 _see_also = ['fast-import', 'fast-import-filter']
938 takes_args = ['source', 'destination']
939 takes_options = ['verbose',
940 Option('trunk-path', type=str, argname="STR",
941 help="Path in repo to /trunk.\n"
942 "May be `regex:/cvs/(trunk)/proj1/(.*)` in "
943 "which case the first group is used as the "
944 "branch name and the second group is used "
945 "to match files.",
947 Option('branches-path', type=str, argname="STR",
948 help="Path in repo to /branches."
950 Option('tags-path', type=str, argname="STR",
951 help="Path in repo to /tags."
954 aliases = []
955 encoding_type = 'exact'
956 def run(self, source, destination, verbose=False, trunk_path=None,
957 branches_path=None, tags_path=None):
958 load_fastimport()
959 from bzrlib.plugins.fastimport.exporters import fast_export_from
960 custom = []
961 if trunk_path is not None:
962 custom.extend(['--trunk-path', trunk_path])
963 if branches_path is not None:
964 custom.extend(['--branches-path', branches_path])
965 if tags_path is not None:
966 custom.extend(['--tags-path', tags_path])
967 fast_export_from(source, destination, 'svn', verbose, custom)
970 register_command(cmd_fast_import)
971 register_command(cmd_fast_import_filter)
972 register_command(cmd_fast_import_info)
973 register_command(cmd_fast_import_query)
974 register_command(cmd_fast_export)
975 register_command(cmd_fast_export_from_cvs)
976 register_command(cmd_fast_export_from_darcs)
977 register_command(cmd_fast_export_from_hg)
978 register_command(cmd_fast_export_from_git)
979 register_command(cmd_fast_export_from_mtn)
980 register_command(cmd_fast_export_from_p4)
981 register_command(cmd_fast_export_from_svn)