fix timezones in darcs-fast-export, take 2
[bzr-fastimport/rorcz.git] / __init__.py
blob8e1660d2560feab567b930fb31b24146936e72b2
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-mnt
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, 9, 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 test_suite():
90 import tests
91 return tests.test_suite()
94 def _run(source, processor_factory, control, params, verbose,
95 user_map=None):
96 """Create and run a processor.
98 :param source: a filename or '-' for standard input. If the
99 filename ends in .gz, it will be opened as a gzip file and
100 the stream will be implicitly uncompressed
101 :param processor_factory: a callable for creating a processor
102 :param control: the BzrDir of the destination or None if no
103 destination is expected
104 :param user_map: if not None, the file containing the user map.
106 import parser
107 stream = _get_source_stream(source)
108 user_mapper = _get_user_mapper(user_map)
109 proc = processor_factory(control, params=params, verbose=verbose)
110 p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
111 return proc.process(p.iter_commands)
114 def _get_source_stream(source):
115 if source == '-':
116 import sys
117 stream = helpers.binary_stream(sys.stdin)
118 elif source.endswith('.gz'):
119 import gzip
120 stream = gzip.open(source, "rb")
121 else:
122 stream = open(source, "rb")
123 return stream
126 def _get_user_mapper(filename):
127 import user_mapper
128 if filename is None:
129 return None
130 f = open(filename)
131 lines = f.readlines()
132 f.close()
133 return user_mapper.UserMapper(lines)
136 class cmd_fast_import(Command):
137 """Backend for fast Bazaar data importers.
139 This command reads a mixed command/data stream and creates
140 branches in a Bazaar repository accordingly. The preferred
141 recipe is::
143 bzr fast-import project.fi project.bzr
145 Numerous commands are provided for generating a fast-import file
146 to use as input. These are named fast-export-from-xxx where xxx
147 is one of cvs, darcs, git, hg, mnt, p4 or svn.
148 To specify standard input as the input stream, use a
149 source name of '-' (instead of project.fi). If the source name
150 ends in '.gz', it is assumed to be compressed in gzip format.
152 project.bzr will be created if it doesn't exist. If it exists
153 already, it should be empty or be an existing Bazaar repository
154 or branch. If not specified, the current directory is assumed.
156 fast-import will intelligently select the format to use when
157 creating a repository or branch. If you are running Bazaar 1.17
158 up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
159 Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
160 is used. If you wish to specify a custom format, use the `--format`
161 option.
163 .. note::
165 To maintain backwards compatibility, fast-import lets you
166 create the target repository or standalone branch yourself.
167 It is recommended though that you let fast-import create
168 these for you instead.
170 :Branch mapping rules:
172 Git reference names are mapped to Bazaar branch names as follows:
174 * refs/heads/foo is mapped to foo
175 * refs/remotes/origin/foo is mapped to foo.remote
176 * refs/tags/foo is mapped to foo.tag
177 * */master is mapped to trunk, trunk.remote, etc.
178 * */trunk is mapped to git-trunk, git-trunk.remote, etc.
180 :Branch creation rules:
182 When a shared repository is created or found at the destination,
183 branches are created inside it. In the simple case of a single
184 branch (refs/heads/master) inside the input file, the branch is
185 project.bzr/trunk.
187 When a standalone branch is found at the destination, the trunk
188 is imported there and warnings are output about any other branches
189 found in the input file.
191 When a branch in a shared repository is found at the destination,
192 that branch is made the trunk and other branches, if any, are
193 created in sister directories.
195 :Working tree updates:
197 The working tree is generated for the trunk branch. If multiple
198 branches are created, a message is output on completion explaining
199 how to create the working trees for other branches.
201 :Custom exporters:
203 The fast-export-from-xxx commands typically call more advanced
204 xxx-fast-export scripts. You are welcome to use the advanced
205 scripts if you prefer.
207 If you wish to write a custom exporter for your project, see
208 http://bazaar-vcs.org/BzrFastImport for the detailed protocol
209 specification. In many cases, exporters can be written quite
210 quickly using whatever scripting/programming language you like.
212 :User mapping:
214 Some source repositories store just the user name while Bazaar
215 prefers a full email address. You can adjust user-ids while
216 importing by using the --user-map option. The argument is a
217 text file with lines in the format::
219 old-id = new-id
221 Blank lines and lines beginning with # are ignored.
222 If old-id has the special value '@', then users without an
223 email address will get one created by using the matching new-id
224 as the domain, unless a more explicit address is given for them.
225 For example, given the user-map of::
227 @ = example.com
228 bill = William Jones <bill@example.com>
230 then user-ids are mapped as follows::
232 maria => maria <maria@example.com>
233 bill => William Jones <bill@example.com>
235 .. note::
237 User mapping is supported by both the fast-import and
238 fast-import-filter commands.
240 :Blob tracking:
242 As some exporters (like git-fast-export) reuse blob data across
243 commits, fast-import makes two passes over the input file by
244 default. In the first pass, it collects data about what blobs are
245 used when, along with some other statistics (e.g. total number of
246 commits). In the second pass, it generates the repository and
247 branches.
249 .. note::
251 The initial pass isn't done if the --info option is used
252 to explicitly pass in information about the input stream.
253 It also isn't done if the source is standard input. In the
254 latter case, memory consumption may be higher than otherwise
255 because some blobs may be kept in memory longer than necessary.
257 :Restarting an import:
259 At checkpoints and on completion, the commit-id -> revision-id
260 map is saved to a file called 'fastimport-id-map' in the control
261 directory for the repository (e.g. .bzr/repository). If the import
262 is interrupted or unexpectedly crashes, it can be started again
263 and this file will be used to skip over already loaded revisions.
264 As long as subsequent exports from the original source begin
265 with exactly the same revisions, you can use this feature to
266 maintain a mirror of a repository managed by a foreign tool.
267 If and when Bazaar is used to manage the repository, this file
268 can be safely deleted.
270 :Examples:
272 Import a Subversion repository into Bazaar::
274 bzr fast-export-from-svn /svn/repo/path project.fi
275 bzr fast-import project.fi project.bzr
277 Import a CVS repository into Bazaar::
279 bzr fast-export-from-cvs /cvs/repo/path project.fi
280 bzr fast-import project.fi project.bzr
282 Import a Git repository into Bazaar::
284 bzr fast-export-from-git /git/repo/path project.fi
285 bzr fast-import project.fi project.bzr
287 Import a Mercurial repository into Bazaar::
289 bzr fast-export-from-hg /hg/repo/path project.fi
290 bzr fast-import project.fi project.bzr
292 Import a Darcs repository into Bazaar::
294 bzr fast-export-from-darcs /darcs/repo/path project.fi
295 bzr fast-import project.fi project.bzr
297 hidden = False
298 _see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
299 takes_args = ['source', 'destination?']
300 takes_options = ['verbose',
301 Option('user-map', type=str,
302 help="Path to file containing a map of user-ids.",
304 Option('info', type=str,
305 help="Path to file containing caching hints.",
307 Option('trees',
308 help="Update all working trees, not just trunk's.",
310 Option('count', type=int,
311 help="Import this many revisions then exit.",
313 Option('checkpoint', type=int,
314 help="Checkpoint automatically every N revisions."
315 " The default is 10000.",
317 Option('autopack', type=int,
318 help="Pack every N checkpoints. The default is 4.",
320 Option('inv-cache', type=int,
321 help="Number of inventories to cache.",
323 RegistryOption.from_kwargs('mode',
324 'The import algorithm to use.',
325 title='Import Algorithm',
326 default='Use the preferred algorithm (inventory deltas).',
327 classic="Use the original algorithm (mutable inventories).",
328 experimental="Enable experimental features.",
329 value_switches=True, enum_switch=False,
331 Option('import-marks', type=str,
332 help="Import marks from file."
334 Option('export-marks', type=str,
335 help="Export marks to file."
337 RegistryOption('format',
338 help='Specify a format for the created repository. See'
339 ' "bzr help formats" for details.',
340 lazy_registry=('bzrlib.bzrdir', 'format_registry'),
341 converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
342 value_switches=False, title='Repository format'),
344 aliases = []
345 def run(self, source, destination='.', verbose=False, info=None,
346 trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
347 mode=None, import_marks=None, export_marks=None, format=None,
348 user_map=None):
349 from bzrlib.errors import BzrCommandError, NotBranchError
350 from bzrlib.plugins.fastimport.processors import generic_processor
351 from bzrlib.plugins.fastimport.helpers import (
352 open_destination_directory,
354 # If no format is given and the user is running a release
355 # leading up to 2.0, select 2a for them. Otherwise, use
356 # the default format.
357 if format is None:
358 import bzrlib
359 bzr_version = bzrlib.version_info[0:2]
360 if bzr_version in [(1,17), (1,18), (2,0)]:
361 format = bzrdir.format_registry.make_bzrdir('2a')
362 control = open_destination_directory(destination, format=format)
364 # If an information file was given and the source isn't stdin,
365 # generate the information by reading the source file as a first pass
366 if info is None and source != '-':
367 info = self._generate_info(source)
369 # Do the work
370 if mode is None:
371 mode = 'default'
372 params = {
373 'info': info,
374 'trees': trees,
375 'count': count,
376 'checkpoint': checkpoint,
377 'autopack': autopack,
378 'inv-cache': inv_cache,
379 'mode': mode,
380 'import-marks': import_marks,
381 'export-marks': export_marks,
383 return _run(source, generic_processor.GenericProcessor, control,
384 params, verbose, user_map=user_map)
386 def _generate_info(self, source):
387 from cStringIO import StringIO
388 import parser
389 from bzrlib.plugins.fastimport.processors import info_processor
390 stream = _get_source_stream(source)
391 output = StringIO()
392 try:
393 proc = info_processor.InfoProcessor(verbose=True, outf=output)
394 p = parser.ImportParser(stream)
395 return_code = proc.process(p.iter_commands)
396 lines = output.getvalue().splitlines()
397 finally:
398 output.close()
399 stream.seek(0)
400 return lines
403 class cmd_fast_import_filter(Command):
404 """Filter a fast-import stream to include/exclude files & directories.
406 This command is useful for splitting a subdirectory or bunch of
407 files out from a project to create a new project complete with history
408 for just those files. It can also be used to create a new project
409 repository that removes all references to files that should not have
410 been committed, e.g. security-related information (like passwords),
411 commercially sensitive material, files with an incompatible license or
412 large binary files like CD images.
414 To specify standard input as the input stream, use a source name
415 of '-'. If the source name ends in '.gz', it is assumed to be
416 compressed in gzip format.
418 :File/directory filtering:
420 This is supported by the -i and -x options. Excludes take precedence
421 over includes.
423 When filtering out a subdirectory (or file), the new stream uses the
424 subdirectory (or subdirectory containing the file) as the root. As
425 fast-import doesn't know in advance whether a path is a file or
426 directory in the stream, you need to specify a trailing '/' on
427 directories passed to the `--includes option`. If multiple files or
428 directories are given, the new root is the deepest common directory.
430 Note: If a path has been renamed, take care to specify the *original*
431 path name, not the final name that it ends up with.
433 :User mapping:
435 Some source repositories store just the user name while Bazaar
436 prefers a full email address. You can adjust user-ids
437 by using the --user-map option. The argument is a
438 text file with lines in the format::
440 old-id = new-id
442 Blank lines and lines beginning with # are ignored.
443 If old-id has the special value '@', then users without an
444 email address will get one created by using the matching new-id
445 as the domain, unless a more explicit address is given for them.
446 For example, given the user-map of::
448 @ = example.com
449 bill = William Jones <bill@example.com>
451 then user-ids are mapped as follows::
453 maria => maria <maria@example.com>
454 bill => William Jones <bill@example.com>
456 .. note::
458 User mapping is supported by both the fast-import and
459 fast-import-filter commands.
461 :Examples:
463 Create a new project from a library (note the trailing / on the
464 directory name of the library)::
466 front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
467 bzr fast-import xxx.fi mylibrary.bzr
468 (lib/xxx/foo is now foo)
470 Create a new repository without a sensitive file::
472 front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
473 bzr fast-import clean.fi clean.bzr
475 hidden = False
476 _see_also = ['fast-import']
477 takes_args = ['source']
478 takes_options = ['verbose',
479 ListOption('include_paths', short_name='i', type=str,
480 help="Only include commits affecting these paths."
481 " Directories should have a trailing /."
483 ListOption('exclude_paths', short_name='x', type=str,
484 help="Exclude these paths from commits."
486 Option('user-map', type=str,
487 help="Path to file containing a map of user-ids.",
490 aliases = []
491 encoding_type = 'exact'
492 def run(self, source, verbose=False, include_paths=None,
493 exclude_paths=None, user_map=None):
494 from bzrlib.plugins.fastimport.processors import filter_processor
495 params = {
496 'include_paths': include_paths,
497 'exclude_paths': exclude_paths,
499 return _run(source, filter_processor.FilterProcessor, None, params,
500 verbose, user_map=user_map)
503 class cmd_fast_import_info(Command):
504 """Output information about a fast-import stream.
506 This command reads a fast-import stream and outputs
507 statistics and interesting properties about what it finds.
508 When run in verbose mode, the information is output as a
509 configuration file that can be passed to fast-import to
510 assist it in intelligently caching objects.
512 To specify standard input as the input stream, use a source name
513 of '-'. If the source name ends in '.gz', it is assumed to be
514 compressed in gzip format.
516 :Examples:
518 Display statistics about the import stream produced by front-end::
520 front-end | bzr fast-import-info -
522 Create a hints file for running fast-import on a large repository::
524 front-end | bzr fast-import-info -v - > front-end.cfg
526 hidden = False
527 _see_also = ['fast-import']
528 takes_args = ['source']
529 takes_options = ['verbose']
530 aliases = []
531 def run(self, source, verbose=False):
532 from bzrlib.plugins.fastimport.processors import info_processor
533 return _run(source, info_processor.InfoProcessor, None, {}, verbose)
536 class cmd_fast_import_query(Command):
537 """Query a fast-import stream displaying selected commands.
539 To specify standard input as the input stream, use a source name
540 of '-'. If the source name ends in '.gz', it is assumed to be
541 compressed in gzip format.
543 To specify a commit to display, give its mark using the
544 --commit-mark option. The commit will be displayed with
545 file-commands included but with inline blobs hidden.
547 To specify the commands to display, use the -C option one or
548 more times. To specify just some fields for a command, use the
549 syntax::
551 command=field1,...
553 By default, the nominated fields for the nominated commands
554 are displayed tab separated. To see the information in
555 a name:value format, use verbose mode.
557 Note: Binary fields (e.g. data for blobs) are masked out
558 so it is generally safe to view the output in a terminal.
560 :Examples:
562 Show the commit with mark 429::
564 bzr fast-import-query xxx.fi -m429
566 Show all the fields of the reset and tag commands::
568 bzr fast-import-query xxx.fi -Creset -Ctag
570 Show the mark and merge fields of the commit commands::
572 bzr fast-import-query xxx.fi -Ccommit=mark,merge
574 hidden = True
575 _see_also = ['fast-import', 'fast-import-filter']
576 takes_args = ['source']
577 takes_options = ['verbose',
578 Option('commit-mark', short_name='m', type=str,
579 help="Mark of the commit to display."
581 ListOption('commands', short_name='C', type=str,
582 help="Display fields for these commands."
585 aliases = []
586 def run(self, source, verbose=False, commands=None, commit_mark=None):
587 from bzrlib.plugins.fastimport.processors import query_processor
588 from bzrlib.plugins.fastimport import helpers
589 params = helpers.defines_to_dict(commands) or {}
590 if commit_mark:
591 params['commit-mark'] = commit_mark
592 return _run(source, query_processor.QueryProcessor, None, params,
593 verbose)
596 class cmd_fast_export(Command):
597 """Generate a fast-import stream from a Bazaar branch.
599 This program generates a stream from a Bazaar branch in fast-import
600 format used by tools such as bzr fast-import, git-fast-import and
601 hg-fast-import.
603 If no destination is given or the destination is '-', standard output
604 is used. Otherwise, the destination is the name of a file. If the
605 destination ends in '.gz', the output will be compressed into gzip
606 format.
608 :Round-tripping:
610 Recent versions of the fast-import specification support features
611 that allow effective round-tripping of many Bazaar branches. As
612 such, fast-exporting a branch and fast-importing the data produced
613 will create a new repository with equivalent history, i.e.
614 "bzr log -v -p --include-merges --forward" on the old branch and
615 new branch should produce similar, if not identical, results.
617 .. note::
619 Be aware that the new repository may appear to have similar history
620 but internally it is quite different with new revision-ids and
621 file-ids assigned. As a consequence, the ability to easily merge
622 with branches based on the old repository is lost. Depending on your
623 reasons for producing a new repository, this may or may not be an
624 issue.
626 :Interoperability:
628 fast-export can use the following "extended features" to
629 produce a richer data stream:
631 * *multiple-authors* - if a commit has multiple authors (as commonly
632 occurs in pair-programming), all authors will be included in the
633 output, not just the first author
635 * *commit-properties* - custom metadata per commit that Bazaar stores
636 in revision properties (e.g. branch-nick and bugs fixed by this
637 change) will be included in the output.
639 * *empty-directories* - directories, even the empty ones, will be
640 included in the output.
642 To disable these features and produce output acceptable to git 1.6,
643 use the --plain option. To enable these features, use --no-plain.
644 Currently, --plain is the default but that will change in the near
645 future once the feature names and definitions are formally agreed
646 to by the broader fast-import developer community.
648 :Examples:
650 To produce data destined for import into Bazaar::
652 bzr fast-export --no-plain my-bzr-branch my.fi.gz
654 To produce data destined for Git 1.6::
656 bzr fast-export --plain my-bzr-branch my.fi
658 To import several unmerged but related branches into the same repository,
659 use the --{export,import}-marks options, and specify a name for the git
660 branch like this::
662 bzr fast-export --export-marks=marks.bzr project.dev |
663 GIT_DIR=project/.git git-fast-import --export-marks=marks.git
665 bzr fast-export --import-marks=marks.bzr -b other project.other |
666 GIT_DIR=project/.git git-fast-import --import-marks=marks.git
668 If you get a "Missing space after source" error from git-fast-import,
669 see the top of the commands.py module for a work-around.
671 hidden = False
672 _see_also = ['fast-import', 'fast-import-filter']
673 takes_args = ['source', 'destination?']
674 takes_options = ['verbose', 'revision',
675 Option('git-branch', short_name='b', type=str,
676 argname='FILE',
677 help='Name of the git branch to create (default=master).'
679 Option('checkpoint', type=int, argname='N',
680 help="Checkpoint every N revisions (default=10000)."
682 Option('marks', type=str, argname='FILE',
683 help="Import marks from and export marks to file."
685 Option('import-marks', type=str, argname='FILE',
686 help="Import marks from file."
688 Option('export-marks', type=str, argname='FILE',
689 help="Export marks to file."
691 Option('plain',
692 help="Exclude metadata to maximise interoperability."
695 aliases = []
696 encoding_type = 'exact'
697 def run(self, source, destination=None, verbose=False,
698 git_branch="master", checkpoint=10000, marks=None,
699 import_marks=None, export_marks=None, revision=None,
700 plain=True):
701 from bzrlib.plugins.fastimport import bzr_exporter
703 if marks:
704 import_marks = export_marks = marks
705 exporter = bzr_exporter.BzrFastExporter(source,
706 destination=destination,
707 git_branch=git_branch, checkpoint=checkpoint,
708 import_marks_file=import_marks, export_marks_file=export_marks,
709 revision=revision, verbose=verbose, plain_format=plain)
710 return exporter.run()
713 class cmd_fast_export_from_cvs(Command):
714 """Generate a fast-import file from a CVS repository.
716 Destination is a dump file, typically named xxx.fi where xxx is
717 the name of the project. If '-' is given, standard output is used.
719 cvs2svn 2.3 or later must be installed as its cvs2bzr script is used
720 under the covers to do the export.
722 The source must be the path on your filesystem to the part of the
723 repository you wish to convert. i.e. either that path or a parent
724 directory must contain a CVSROOT subdirectory. The path may point to
725 either the top of a repository or to a path within it. In the latter
726 case, only that project within the repository will be converted.
728 .. note::
729 Remote access to the repository is not sufficient - the path
730 must point into a copy of the repository itself. See
731 http://cvs2svn.tigris.org/faq.html#repoaccess for instructions
732 on how to clone a remote CVS repository locally.
734 By default, the trunk, branches and tags are all exported. If you
735 only want the trunk, use the `--trunk-only` option.
737 By default, filenames, log messages and author names are expected
738 to be encoded in ascii. Use the `--encoding` option to specify an
739 alternative. If multiple encodings are used, specify the option
740 multiple times. For a list of valid encoding names, see
741 http://docs.python.org/lib/standard-encodings.html.
743 Windows users need to install GNU sort and use the `--sort`
744 option to specify its location. GNU sort can be downloaded from
745 http://unxutils.sourceforge.net/.
747 hidden = False
748 _see_also = ['fast-import', 'fast-import-filter']
749 takes_args = ['source', 'destination']
750 takes_options = ['verbose',
751 Option('trunk-only',
752 help="Export just the trunk, ignoring tags and branches."
754 ListOption('encoding', type=str, argname='CODEC',
755 help="Encoding used for filenames, commit messages "
756 "and author names if not ascii."
758 Option('sort', type=str, argname='PATH',
759 help="GNU sort program location if not on the path."
762 aliases = []
763 encoding_type = 'exact'
764 def run(self, source, destination, verbose=False, trunk_only=False,
765 encoding=None, sort=None):
766 from bzrlib.plugins.fastimport.exporters import fast_export_from
767 custom = []
768 if trunk_only:
769 custom.append("--trunk-only")
770 if encoding:
771 for enc in encoding:
772 custom.extend(['--encoding', enc])
773 if sort:
774 custom.extend(['--sort', sort])
775 fast_export_from(source, destination, 'cvs', verbose, custom)
778 class cmd_fast_export_from_darcs(Command):
779 """Generate a fast-import file from a Darcs repository.
781 Destination is a dump file, typically named xxx.fi where xxx is
782 the name of the project. If '-' is given, standard output is used.
784 Darcs 2.2 or later must be installed as various subcommands are
785 used to access the source repository. The source may be a network
786 URL but using a local URL is recommended for performance reasons.
788 hidden = False
789 _see_also = ['fast-import', 'fast-import-filter']
790 takes_args = ['source', 'destination']
791 takes_options = ['verbose',
792 Option('encoding', type=str, argname='CODEC',
793 help="Encoding used for commit messages if not utf-8."
796 aliases = []
797 encoding_type = 'exact'
798 def run(self, source, destination, verbose=False, encoding=None):
799 from bzrlib.plugins.fastimport.exporters import fast_export_from
800 custom = None
801 if encoding is not None:
802 custom = ['--encoding', encoding]
803 fast_export_from(source, destination, 'darcs', verbose, custom)
806 class cmd_fast_export_from_hg(Command):
807 """Generate a fast-import file from a Mercurial repository.
809 Destination is a dump file, typically named xxx.fi where xxx is
810 the name of the project. If '-' is given, standard output is used.
812 Mercurial 1.2 or later must be installed as its libraries are used
813 to access the source repository. Given the APIs currently used,
814 the source repository must be a local file, not a network URL.
816 hidden = False
817 _see_also = ['fast-import', 'fast-import-filter']
818 takes_args = ['source', 'destination']
819 takes_options = ['verbose']
820 aliases = []
821 encoding_type = 'exact'
822 def run(self, source, destination, verbose=False):
823 from bzrlib.plugins.fastimport.exporters import fast_export_from
824 fast_export_from(source, destination, 'hg', verbose)
827 class cmd_fast_export_from_git(Command):
828 """Generate a fast-import file from a Git repository.
830 Destination is a dump file, typically named xxx.fi where xxx is
831 the name of the project. If '-' is given, standard output is used.
833 Git 1.6 or later must be installed as the git fast-export
834 subcommand is used under the covers to generate the stream.
835 The source must be a local directory.
837 .. note::
839 Earlier versions of Git may also work fine but are
840 likely to receive less active support if problems arise.
842 hidden = False
843 _see_also = ['fast-import', 'fast-import-filter']
844 takes_args = ['source', 'destination']
845 takes_options = ['verbose']
846 aliases = []
847 encoding_type = 'exact'
848 def run(self, source, destination, verbose=False):
849 from bzrlib.plugins.fastimport.exporters import fast_export_from
850 fast_export_from(source, destination, 'git', verbose)
853 class cmd_fast_export_from_mnt(Command):
854 """Generate a fast-import file from a Monotone repository.
856 Destination is a dump file, typically named xxx.fi where xxx is
857 the name of the project. If '-' is given, standard output is used.
859 Monotone 0.43 or later must be installed as the mnt git_export
860 subcommand is used under the covers to generate the stream.
861 The source must be a local directory.
863 hidden = False
864 _see_also = ['fast-import', 'fast-import-filter']
865 takes_args = ['source', 'destination']
866 takes_options = ['verbose']
867 aliases = []
868 encoding_type = 'exact'
869 def run(self, source, destination, verbose=False):
870 from bzrlib.plugins.fastimport.exporters import fast_export_from
871 fast_export_from(source, destination, 'mnt', verbose)
874 class cmd_fast_export_from_p4(Command):
875 """Generate a fast-import file from a Perforce repository.
877 Source is a Perforce depot path, e.g., //depot/project
879 Destination is a dump file, typically named xxx.fi where xxx is
880 the name of the project. If '-' is given, standard output is used.
882 bzrp4 must be installed as its p4_fast_export.py module is used under
883 the covers to do the export. bzrp4 can be downloaded from
884 https://launchpad.net/bzrp4/.
886 The P4PORT environment variable must be set, and you must be logged
887 into the Perforce server.
889 By default, only the HEAD changelist is exported. To export all
890 changelists, append '@all' to the source. To export a revision range,
891 append a comma-delimited pair of changelist numbers to the source,
892 e.g., '100,200'.
894 hidden = False
895 _see_also = ['fast-import', 'fast-import-filter']
896 takes_args = ['source', 'destination']
897 takes_options = []
898 aliases = []
899 encoding_type = 'exact'
900 def run(self, source, destination, verbose=False):
901 from bzrlib.plugins.fastimport.exporters import fast_export_from
902 custom = []
903 fast_export_from(source, destination, 'p4', verbose, custom)
906 class cmd_fast_export_from_svn(Command):
907 """Generate a fast-import file from a Subversion repository.
909 Destination is a dump file, typically named xxx.fi where xxx is
910 the name of the project. If '-' is given, standard output is used.
912 Python-Subversion (Python bindings to the Subversion APIs)
913 1.4 or later must be installed as this library is used to
914 access the source repository. The source may be a network URL
915 but using a local URL is recommended for performance reasons.
917 hidden = False
918 _see_also = ['fast-import', 'fast-import-filter']
919 takes_args = ['source', 'destination']
920 takes_options = ['verbose',
921 Option('trunk-path', type=str, argname="STR",
922 help="Path in repo to /trunk.\n"
923 "May be `regex:/cvs/(trunk)/proj1/(.*)` in "
924 "which case the first group is used as the "
925 "branch name and the second group is used "
926 "to match files.",
928 Option('branches-path', type=str, argname="STR",
929 help="Path in repo to /branches."
931 Option('tags-path', type=str, argname="STR",
932 help="Path in repo to /tags."
935 aliases = []
936 encoding_type = 'exact'
937 def run(self, source, destination, verbose=False, trunk_path=None,
938 branches_path=None, tags_path=None):
939 from bzrlib.plugins.fastimport.exporters import fast_export_from
940 custom = []
941 if trunk_path is not None:
942 custom.extend(['--trunk-path', trunk_path])
943 if branches_path is not None:
944 custom.extend(['--branches-path', branches_path])
945 if tags_path is not None:
946 custom.extend(['--tags-path', tags_path])
947 fast_export_from(source, destination, 'svn', verbose, custom)
950 register_command(cmd_fast_import)
951 register_command(cmd_fast_import_filter)
952 register_command(cmd_fast_import_info)
953 register_command(cmd_fast_import_query)
954 register_command(cmd_fast_export)
955 register_command(cmd_fast_export_from_cvs)
956 register_command(cmd_fast_export_from_darcs)
957 register_command(cmd_fast_export_from_hg)
958 register_command(cmd_fast_export_from_git)
959 register_command(cmd_fast_export_from_mnt)
960 register_command(cmd_fast_export_from_p4)
961 register_command(cmd_fast_export_from_svn)