/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
1
# Copyright (C) 2008 Canonical Ltd
2
#
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.
7
#
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.
12
#
13
# You should have received a copy of the GNU General Public License
0.64.334 by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan.
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
15
16
"""Fastimport/fastexport commands."""
17
18
from bzrlib import bzrdir
19
from bzrlib.commands import Command
20
from bzrlib.option import Option, ListOption, RegistryOption
21
22
from bzrlib.plugins.fastimport import load_fastimport
23
24
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
25
def _run(source, processor_factory, verbose=False, user_map=None, **kwargs):
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
26
    """Create and run a processor.
27
28
    :param source: a filename or '-' for standard input. If the
29
      filename ends in .gz, it will be opened as a gzip file and
30
      the stream will be implicitly uncompressed
31
    :param processor_factory: a callable for creating a processor
32
    :param user_map: if not None, the file containing the user map.
33
    """
34
    from fastimport import parser
35
    stream = _get_source_stream(source)
36
    user_mapper = _get_user_mapper(user_map)
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
37
    proc = processor_factory(verbose=verbose, **kwargs)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
38
    p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
39
    return proc.process(p.iter_commands)
40
41
42
def _get_source_stream(source):
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
43
    if source == '-' or source is None:
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
44
        import sys
45
        from fastimport import helpers
46
        stream = helpers.binary_stream(sys.stdin)
47
    elif source.endswith('.gz'):
48
        import gzip
49
        stream = gzip.open(source, "rb")
50
    else:
51
        stream = open(source, "rb")
52
    return stream
53
54
55
def _get_user_mapper(filename):
56
    import user_mapper
57
    if filename is None:
58
        return None
59
    f = open(filename)
60
    lines = f.readlines()
61
    f.close()
62
    return user_mapper.UserMapper(lines)
63
64
65
class cmd_fast_import(Command):
66
    """Backend for fast Bazaar data importers.
67
68
    This command reads a mixed command/data stream and creates
69
    branches in a Bazaar repository accordingly. The preferred
70
    recipe is::
71
72
      bzr fast-import project.fi project.bzr
73
74
    Numerous commands are provided for generating a fast-import file
75
    to use as input. These are named fast-export-from-xxx where xxx
76
    is one of cvs, darcs, git, hg, mtn, p4 or svn.
77
    To specify standard input as the input stream, use a
78
    source name of '-' (instead of project.fi). If the source name
79
    ends in '.gz', it is assumed to be compressed in gzip format.
80
    
81
    project.bzr will be created if it doesn't exist. If it exists
82
    already, it should be empty or be an existing Bazaar repository
83
    or branch. If not specified, the current directory is assumed.
84
 
85
    fast-import will intelligently select the format to use when
86
    creating a repository or branch. If you are running Bazaar 1.17
87
    up to Bazaar 2.0, the default format for Bazaar 2.x ("2a") is used.
88
    Otherwise, the current default format ("pack-0.92" for Bazaar 1.x)
89
    is used. If you wish to specify a custom format, use the `--format`
90
    option.
91
92
     .. note::
93
     
94
        To maintain backwards compatibility, fast-import lets you
95
        create the target repository or standalone branch yourself.
96
        It is recommended though that you let fast-import create
97
        these for you instead.
98
99
    :Branch mapping rules:
100
101
     Git reference names are mapped to Bazaar branch names as follows:
102
      
103
     * refs/heads/foo is mapped to foo
104
     * refs/remotes/origin/foo is mapped to foo.remote
105
     * refs/tags/foo is mapped to foo.tag
106
     * */master is mapped to trunk, trunk.remote, etc.
107
     * */trunk is mapped to git-trunk, git-trunk.remote, etc.
108
109
    :Branch creation rules:
110
111
     When a shared repository is created or found at the destination,
112
     branches are created inside it. In the simple case of a single
113
     branch (refs/heads/master) inside the input file, the branch is
114
     project.bzr/trunk.
115
116
     When a standalone branch is found at the destination, the trunk
117
     is imported there and warnings are output about any other branches
118
     found in the input file.
119
120
     When a branch in a shared repository is found at the destination,
121
     that branch is made the trunk and other branches, if any, are
122
     created in sister directories.
123
124
    :Working tree updates:
125
126
     The working tree is generated for the trunk branch. If multiple
127
     branches are created, a message is output on completion explaining
128
     how to create the working trees for other branches.
129
130
    :Custom exporters:
131
132
     The fast-export-from-xxx commands typically call more advanced
133
     xxx-fast-export scripts. You are welcome to use the advanced
134
     scripts if you prefer.
135
136
     If you wish to write a custom exporter for your project, see
137
     http://bazaar-vcs.org/BzrFastImport for the detailed protocol
138
     specification. In many cases, exporters can be written quite
139
     quickly using whatever scripting/programming language you like.
140
141
    :User mapping:
142
143
     Some source repositories store just the user name while Bazaar
144
     prefers a full email address. You can adjust user-ids while
145
     importing by using the --user-map option. The argument is a
146
     text file with lines in the format::
147
148
       old-id = new-id
149
150
     Blank lines and lines beginning with # are ignored.
151
     If old-id has the special value '@', then users without an
152
     email address will get one created by using the matching new-id
153
     as the domain, unless a more explicit address is given for them.
154
     For example, given the user-map of::
155
156
       @ = example.com
157
       bill = William Jones <bill@example.com>
158
159
     then user-ids are mapped as follows::
160
     
161
      maria => maria <maria@example.com>
162
      bill => William Jones <bill@example.com>
163
164
     .. note::
165
     
166
        User mapping is supported by both the fast-import and
167
        fast-import-filter commands.
168
169
    :Blob tracking:
170
171
     As some exporters (like git-fast-export) reuse blob data across
172
     commits, fast-import makes two passes over the input file by
173
     default. In the first pass, it collects data about what blobs are
174
     used when, along with some other statistics (e.g. total number of
175
     commits). In the second pass, it generates the repository and
176
     branches.
177
     
178
     .. note::
179
     
180
        The initial pass isn't done if the --info option is used
181
        to explicitly pass in information about the input stream.
182
        It also isn't done if the source is standard input. In the
183
        latter case, memory consumption may be higher than otherwise
184
        because some blobs may be kept in memory longer than necessary.
185
186
    :Restarting an import:
187
188
     At checkpoints and on completion, the commit-id -> revision-id
189
     map is saved to a file called 'fastimport-id-map' in the control
190
     directory for the repository (e.g. .bzr/repository). If the import
191
     is interrupted or unexpectedly crashes, it can be started again
192
     and this file will be used to skip over already loaded revisions.
193
     As long as subsequent exports from the original source begin
194
     with exactly the same revisions, you can use this feature to
195
     maintain a mirror of a repository managed by a foreign tool.
196
     If and when Bazaar is used to manage the repository, this file
197
     can be safely deleted.
198
199
    :Examples:
200
201
     Import a Subversion repository into Bazaar::
202
203
       bzr fast-export-from-svn /svn/repo/path project.fi
204
       bzr fast-import project.fi project.bzr
205
206
     Import a CVS repository into Bazaar::
207
208
       bzr fast-export-from-cvs /cvs/repo/path project.fi
209
       bzr fast-import project.fi project.bzr
210
211
     Import a Git repository into Bazaar::
212
213
       bzr fast-export-from-git /git/repo/path project.fi
214
       bzr fast-import project.fi project.bzr
215
216
     Import a Mercurial repository into Bazaar::
217
218
       bzr fast-export-from-hg /hg/repo/path project.fi
219
       bzr fast-import project.fi project.bzr
220
221
     Import a Darcs repository into Bazaar::
222
223
       bzr fast-export-from-darcs /darcs/repo/path project.fi
224
       bzr fast-import project.fi project.bzr
225
    """
226
    hidden = False
227
    _see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
228
    takes_args = ['source', 'destination?']
229
    takes_options = ['verbose',
230
                    Option('user-map', type=str,
231
                        help="Path to file containing a map of user-ids.",
232
                        ),
233
                    Option('info', type=str,
234
                        help="Path to file containing caching hints.",
235
                        ),
236
                    Option('trees',
237
                        help="Update all working trees, not just trunk's.",
238
                        ),
239
                    Option('count', type=int,
240
                        help="Import this many revisions then exit.",
241
                        ),
242
                    Option('checkpoint', type=int,
243
                        help="Checkpoint automatically every N revisions."
244
                             " The default is 10000.",
245
                        ),
246
                    Option('autopack', type=int,
247
                        help="Pack every N checkpoints. The default is 4.",
248
                        ),
249
                    Option('inv-cache', type=int,
250
                        help="Number of inventories to cache.",
251
                        ),
252
                    RegistryOption.from_kwargs('mode',
253
                        'The import algorithm to use.',
254
                        title='Import Algorithm',
255
                        default='Use the preferred algorithm (inventory deltas).',
256
                        classic="Use the original algorithm (mutable inventories).",
257
                        experimental="Enable experimental features.",
258
                        value_switches=True, enum_switch=False,
259
                        ),
260
                    Option('import-marks', type=str,
261
                        help="Import marks from file."
262
                        ),
263
                    Option('export-marks', type=str,
264
                        help="Export marks to file."
265
                        ),
266
                    RegistryOption('format',
267
                            help='Specify a format for the created repository. See'
268
                                 ' "bzr help formats" for details.',
269
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
270
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
271
                            value_switches=False, title='Repository format'),
272
                     ]
273
    def run(self, source, destination='.', verbose=False, info=None,
274
        trees=False, count=-1, checkpoint=10000, autopack=4, inv_cache=-1,
275
        mode=None, import_marks=None, export_marks=None, format=None,
276
        user_map=None):
277
        load_fastimport()
278
        from bzrlib.plugins.fastimport.processors import generic_processor
279
        from bzrlib.plugins.fastimport.helpers import (
280
            open_destination_directory,
281
            )
282
        # If no format is given and the user is running a release
283
        # leading up to 2.0, select 2a for them. Otherwise, use
284
        # the default format.
285
        if format is None:
286
            import bzrlib
287
            bzr_version = bzrlib.version_info[0:2]
288
            if bzr_version in [(1,17), (1,18), (2,0)]:
289
                format = bzrdir.format_registry.make_bzrdir('2a')
290
        control = open_destination_directory(destination, format=format)
291
292
        # If an information file was given and the source isn't stdin,
293
        # generate the information by reading the source file as a first pass
294
        if info is None and source != '-':
295
            info = self._generate_info(source)
296
297
        # Do the work
298
        if mode is None:
299
            mode = 'default'
300
        params = {
301
            'info': info,
302
            'trees': trees,
303
            'count': count,
304
            'checkpoint': checkpoint,
305
            'autopack': autopack,
306
            'inv-cache': inv_cache,
307
            'mode': mode,
308
            'import-marks': import_marks,
309
            'export-marks': export_marks,
310
            }
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
311
        return _run(source, generic_processor.GenericProcessor,
0.131.2 by Jelmer Vernooij
Fix 'bzr fast-import' bzrdir argument and add a blackbox test.
312
                bzrdir=control, params=params, verbose=verbose,
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
313
                user_map=user_map)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
314
315
    def _generate_info(self, source):
316
        from cStringIO import StringIO
317
        from fastimport import parser
318
        from fastimport.processors import info_processor
319
        stream = _get_source_stream(source)
320
        output = StringIO()
321
        try:
322
            proc = info_processor.InfoProcessor(verbose=True, outf=output)
323
            p = parser.ImportParser(stream)
324
            return_code = proc.process(p.iter_commands)
325
            lines = output.getvalue().splitlines()
326
        finally:
327
            output.close()
328
            stream.seek(0)
329
        return lines
330
331
332
class cmd_fast_import_filter(Command):
333
    """Filter a fast-import stream to include/exclude files & directories.
334
335
    This command is useful for splitting a subdirectory or bunch of
336
    files out from a project to create a new project complete with history
337
    for just those files. It can also be used to create a new project
338
    repository that removes all references to files that should not have
339
    been committed, e.g. security-related information (like passwords),
340
    commercially sensitive material, files with an incompatible license or
341
    large binary files like CD images.
342
343
    To specify standard input as the input stream, use a source name
344
    of '-'. If the source name ends in '.gz', it is assumed to be
345
    compressed in gzip format.
346
347
    :File/directory filtering:
348
349
     This is supported by the -i and -x options. Excludes take precedence
350
     over includes.
351
352
     When filtering out a subdirectory (or file), the new stream uses the
353
     subdirectory (or subdirectory containing the file) as the root. As
354
     fast-import doesn't know in advance whether a path is a file or
355
     directory in the stream, you need to specify a trailing '/' on
356
     directories passed to the `--includes option`. If multiple files or
357
     directories are given, the new root is the deepest common directory.
358
359
     Note: If a path has been renamed, take care to specify the *original*
360
     path name, not the final name that it ends up with.
361
362
    :User mapping:
363
364
     Some source repositories store just the user name while Bazaar
365
     prefers a full email address. You can adjust user-ids
366
     by using the --user-map option. The argument is a
367
     text file with lines in the format::
368
369
       old-id = new-id
370
371
     Blank lines and lines beginning with # are ignored.
372
     If old-id has the special value '@', then users without an
373
     email address will get one created by using the matching new-id
374
     as the domain, unless a more explicit address is given for them.
375
     For example, given the user-map of::
376
377
       @ = example.com
378
       bill = William Jones <bill@example.com>
379
380
     then user-ids are mapped as follows::
381
     
382
      maria => maria <maria@example.com>
383
      bill => William Jones <bill@example.com>
384
385
     .. note::
386
     
387
        User mapping is supported by both the fast-import and
388
        fast-import-filter commands.
389
0.134.1 by Oleksandr Usov
Add preserve_all_history flag fast-import-filter
390
    :History rewriting:
391
392
     By default fast-import-filter does quite aggressive history rewriting.
393
     Empty commits (or commits which had all their content filtered out) will
394
     be removed, and so are the references to commits not included in the stream.
395
0.134.2 by Oleksandr Usov
Command-line flag renamed to --dont-squash-empty-commits
396
     Flag --dont-squash-empty-commits reverses this behavior and makes it possible to
0.134.1 by Oleksandr Usov
Add preserve_all_history flag fast-import-filter
397
     use fast-import-filter on incremental streams.
398
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
399
    :Examples:
400
401
     Create a new project from a library (note the trailing / on the
402
     directory name of the library)::
403
404
       front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
405
       bzr fast-import xxx.fi mylibrary.bzr
406
       (lib/xxx/foo is now foo)
407
408
     Create a new repository without a sensitive file::
409
410
       front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
411
       bzr fast-import clean.fi clean.bzr
412
    """
413
    hidden = False
414
    _see_also = ['fast-import']
0.64.293 by Jelmer Vernooij
SOURCE argument to bzr fast-import-filter is now optional, consistent with examples.
415
    takes_args = ['source?']
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
416
    takes_options = ['verbose',
417
                    ListOption('include_paths', short_name='i', type=str,
418
                        help="Only include commits affecting these paths."
419
                             " Directories should have a trailing /."
420
                        ),
421
                    ListOption('exclude_paths', short_name='x', type=str,
422
                        help="Exclude these paths from commits."
423
                        ),
424
                    Option('user-map', type=str,
425
                        help="Path to file containing a map of user-ids.",
426
                        ),
0.134.2 by Oleksandr Usov
Command-line flag renamed to --dont-squash-empty-commits
427
                    Option('dont-squash-empty-commits',
0.134.1 by Oleksandr Usov
Add preserve_all_history flag fast-import-filter
428
                        help="Preserve all commits and links between them"
429
                        ),
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
430
                     ]
431
    encoding_type = 'exact'
0.64.293 by Jelmer Vernooij
SOURCE argument to bzr fast-import-filter is now optional, consistent with examples.
432
    def run(self, source=None, verbose=False, include_paths=None,
0.134.2 by Oleksandr Usov
Command-line flag renamed to --dont-squash-empty-commits
433
        exclude_paths=None, user_map=None, dont_squash_empty_commits=False):
0.64.338 by Jelmer Vernooij
Merge in support for --dont-squash-empty-commits.
434
        from bzrlib.errors import BzrCommandError
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
435
        load_fastimport()
436
        from fastimport.processors import filter_processor
437
        params = {
438
            'include_paths': include_paths,
439
            'exclude_paths': exclude_paths,
440
            }
0.64.338 by Jelmer Vernooij
Merge in support for --dont-squash-empty-commits.
441
        if ('squash_empty_commits' in
442
                filter_processor.FilterProcessor.known_params):
443
            params['squash_empty_commits'] = (not dont_squash_empty_commits)
444
        else:
445
            if dont_squash_empty_commits:
446
                raise BzrCommandError("installed python-fastimport does not "
447
                    "support not squashing empty commits. Please install "
448
                    " a newer python-fastimport to use "
449
                    "--dont-squash-empty-commits")
450
0.64.287 by Jelmer Vernooij
Fix fast-import-filter.
451
        from fastimport import parser
452
        stream = _get_source_stream(source)
453
        user_mapper = _get_user_mapper(user_map)
454
        proc = filter_processor.FilterProcessor(params=params, verbose=verbose)
455
        p = parser.ImportParser(stream, verbose=verbose, user_mapper=user_mapper)
456
        return proc.process(p.iter_commands)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
457
458
459
class cmd_fast_import_info(Command):
460
    """Output information about a fast-import stream.
461
462
    This command reads a fast-import stream and outputs
463
    statistics and interesting properties about what it finds.
464
    When run in verbose mode, the information is output as a
465
    configuration file that can be passed to fast-import to
466
    assist it in intelligently caching objects.
467
468
    To specify standard input as the input stream, use a source name
469
    of '-'. If the source name ends in '.gz', it is assumed to be
470
    compressed in gzip format.
471
472
    :Examples:
473
474
     Display statistics about the import stream produced by front-end::
475
476
      front-end | bzr fast-import-info -
477
478
     Create a hints file for running fast-import on a large repository::
479
480
       front-end | bzr fast-import-info -v - > front-end.cfg
481
    """
482
    hidden = False
483
    _see_also = ['fast-import']
484
    takes_args = ['source']
485
    takes_options = ['verbose']
486
    def run(self, source, verbose=False):
487
        load_fastimport()
488
        from fastimport.processors import info_processor
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
489
        return _run(source, info_processor.InfoProcessor, verbose=verbose)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
490
491
492
class cmd_fast_import_query(Command):
493
    """Query a fast-import stream displaying selected commands.
494
495
    To specify standard input as the input stream, use a source name
496
    of '-'. If the source name ends in '.gz', it is assumed to be
497
    compressed in gzip format.
498
499
    To specify a commit to display, give its mark using the
500
    --commit-mark option. The commit will be displayed with
501
    file-commands included but with inline blobs hidden.
502
503
    To specify the commands to display, use the -C option one or
504
    more times. To specify just some fields for a command, use the
505
    syntax::
506
507
      command=field1,...
508
509
    By default, the nominated fields for the nominated commands
510
    are displayed tab separated. To see the information in
511
    a name:value format, use verbose mode.
512
513
    Note: Binary fields (e.g. data for blobs) are masked out
514
    so it is generally safe to view the output in a terminal.
515
516
    :Examples:
517
518
     Show the commit with mark 429::
519
520
      bzr fast-import-query xxx.fi -m429
521
522
     Show all the fields of the reset and tag commands::
523
524
      bzr fast-import-query xxx.fi -Creset -Ctag
525
526
     Show the mark and merge fields of the commit commands::
527
528
      bzr fast-import-query xxx.fi -Ccommit=mark,merge
529
    """
530
    hidden = True
531
    _see_also = ['fast-import', 'fast-import-filter']
532
    takes_args = ['source']
533
    takes_options = ['verbose',
534
                    Option('commit-mark', short_name='m', type=str,
535
                        help="Mark of the commit to display."
536
                        ),
537
                    ListOption('commands', short_name='C', type=str,
538
                        help="Display fields for these commands."
539
                        ),
540
                     ]
541
    def run(self, source, verbose=False, commands=None, commit_mark=None):
542
        load_fastimport()
543
        from fastimport.processors import query_processor
544
        from bzrlib.plugins.fastimport import helpers
545
        params = helpers.defines_to_dict(commands) or {}
546
        if commit_mark:
547
            params['commit-mark'] = commit_mark
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
548
        return _run(source, query_processor.QueryProcessor, params=params,
549
            verbose=verbose)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
550
551
552
class cmd_fast_export(Command):
553
    """Generate a fast-import stream from a Bazaar branch.
554
555
    This program generates a stream from a Bazaar branch in fast-import
556
    format used by tools such as bzr fast-import, git-fast-import and
557
    hg-fast-import.
558
559
    If no destination is given or the destination is '-', standard output
560
    is used. Otherwise, the destination is the name of a file. If the
561
    destination ends in '.gz', the output will be compressed into gzip
562
    format.
563
 
564
    :Round-tripping:
565
566
     Recent versions of the fast-import specification support features
567
     that allow effective round-tripping of many Bazaar branches. As
568
     such, fast-exporting a branch and fast-importing the data produced
569
     will create a new repository with equivalent history, i.e.
570
     "bzr log -v -p --include-merges --forward" on the old branch and
571
     new branch should produce similar, if not identical, results.
572
573
     .. note::
574
    
575
        Be aware that the new repository may appear to have similar history
576
        but internally it is quite different with new revision-ids and
577
        file-ids assigned. As a consequence, the ability to easily merge
578
        with branches based on the old repository is lost. Depending on your
579
        reasons for producing a new repository, this may or may not be an
580
        issue.
581
582
    :Interoperability:
583
584
     fast-export can use the following "extended features" to
585
     produce a richer data stream:
586
587
     * *multiple-authors* - if a commit has multiple authors (as commonly
588
       occurs in pair-programming), all authors will be included in the
589
       output, not just the first author
590
591
     * *commit-properties* - custom metadata per commit that Bazaar stores
592
       in revision properties (e.g. branch-nick and bugs fixed by this
593
       change) will be included in the output.
594
595
     * *empty-directories* - directories, even the empty ones, will be
596
       included in the output.
597
598
     To disable these features and produce output acceptable to git 1.6,
599
     use the --plain option. To enable these features, use --no-plain.
600
     Currently, --plain is the default but that will change in the near
601
     future once the feature names and definitions are formally agreed
602
     to by the broader fast-import developer community.
603
0.64.337 by Jelmer Vernooij
Merge support for --rewrite-tag-names.
604
     Git has stricter naming rules for tags and fast-export --plain
605
     will skip tags which can't be imported into git. To replace characters
606
     unsupported in git with an underscore instead, specify
607
     --rewrite-tag-names.
608
0.135.1 by Andy Grimm
Add --baseline option
609
    :History truncation:
610
0.135.3 by Andy Grimm
doc fix for --baseline
611
     When code has been significantly refactored over time (e.g., to separate 
612
     proprietary code from open source code), it is sometimes convenient to
613
     simply truncate the revision history at a certain point.  The --baseline 
614
     option, to be used in conjunction with -r, emits a baseline commit
615
     containing the state of the entire source tree at the first requested 
616
     revision.  This allows a user to produce a tree identical to the original 
617
     without munging multiple exports.
0.135.1 by Andy Grimm
Add --baseline option
618
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
619
    :Examples:
620
621
     To produce data destined for import into Bazaar::
622
623
       bzr fast-export --no-plain my-bzr-branch my.fi.gz
624
625
     To produce data destined for Git 1.6::
626
627
       bzr fast-export --plain my-bzr-branch my.fi
628
629
     To import several unmerged but related branches into the same repository,
630
     use the --{export,import}-marks options, and specify a name for the git
631
     branch like this::
632
    
633
       bzr fast-export --export-marks=marks.bzr project.dev |
634
              GIT_DIR=project/.git git-fast-import --export-marks=marks.git
635
636
       bzr fast-export --import-marks=marks.bzr -b other project.other |
637
              GIT_DIR=project/.git git-fast-import --import-marks=marks.git
638
639
     If you get a "Missing space after source" error from git-fast-import,
640
     see the top of the commands.py module for a work-around.
641
    """
642
    hidden = False
643
    _see_also = ['fast-import', 'fast-import-filter']
644
    takes_args = ['source', 'destination?']
645
    takes_options = ['verbose', 'revision',
646
                    Option('git-branch', short_name='b', type=str,
647
                        argname='FILE',
648
                        help='Name of the git branch to create (default=master).'
649
                        ),
650
                    Option('checkpoint', type=int, argname='N',
651
                        help="Checkpoint every N revisions (default=10000)."
652
                        ),
653
                    Option('marks', type=str, argname='FILE',
654
                        help="Import marks from and export marks to file."
655
                        ),
656
                    Option('import-marks', type=str, argname='FILE',
657
                        help="Import marks from file."
658
                        ),
659
                    Option('export-marks', type=str, argname='FILE',
660
                        help="Export marks to file."
661
                        ),
662
                    Option('plain',
663
                        help="Exclude metadata to maximise interoperability."
664
                        ),
0.133.2 by Oleksandr Usov
Rewrite tag names when exporting plain stream
665
                    Option('rewrite-tag-names',
0.64.337 by Jelmer Vernooij
Merge support for --rewrite-tag-names.
666
                        help="Replace characters invalid in git with '_'"
667
                             " (plain mode only).",
0.133.2 by Oleksandr Usov
Rewrite tag names when exporting plain stream
668
                        ),
0.135.1 by Andy Grimm
Add --baseline option
669
                    Option('baseline',
0.135.2 by Andy Grimm
fix --baseline bugs, and add a couple of tests
670
                        help="Export an 'absolute' baseline commit prior to"
0.135.1 by Andy Grimm
Add --baseline option
671
                             "the first relative commit",
672
                        ),
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
673
                     ]
674
    encoding_type = 'exact'
675
    def run(self, source, destination=None, verbose=False,
676
        git_branch="master", checkpoint=10000, marks=None,
677
        import_marks=None, export_marks=None, revision=None,
0.135.1 by Andy Grimm
Add --baseline option
678
        plain=True, rewrite_tag_names=False, baseline=False):
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
679
        load_fastimport()
0.64.339 by Jelmer Vernooij
Some refactoring of exporter.
680
        from bzrlib.branch import Branch
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
681
        from bzrlib.plugins.fastimport import exporter
682
683
        if marks:
684
            import_marks = export_marks = marks
0.64.339 by Jelmer Vernooij
Some refactoring of exporter.
685
686
        # Open the source
687
        branch = Branch.open_containing(source)[0]
688
        outf = exporter._get_output_stream(destination)
689
        exporter = exporter.BzrFastExporter(branch,
690
            outf=outf, git_branch=git_branch, checkpoint=checkpoint,
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
691
            import_marks_file=import_marks, export_marks_file=export_marks,
0.133.2 by Oleksandr Usov
Rewrite tag names when exporting plain stream
692
            revision=revision, verbose=verbose, plain_format=plain,
0.135.1 by Andy Grimm
Add --baseline option
693
            rewrite_tags=rewrite_tag_names, baseline=baseline)
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
694
        return exporter.run()
695
696
697
class cmd_fast_export_from_cvs(Command):
698
    """Generate a fast-import file from a CVS repository.
699
700
    Destination is a dump file, typically named xxx.fi where xxx is
701
    the name of the project. If '-' is given, standard output is used.
702
703
    cvs2svn 2.3 or later must be installed as its cvs2bzr script is used
704
    under the covers to do the export.
705
    
706
    The source must be the path on your filesystem to the part of the
707
    repository you wish to convert. i.e. either that path or a parent
708
    directory must contain a CVSROOT subdirectory. The path may point to
709
    either the top of a repository or to a path within it. In the latter
710
    case, only that project within the repository will be converted.
711
712
    .. note::
713
       Remote access to the repository is not sufficient - the path
714
       must point into a copy of the repository itself. See
715
       http://cvs2svn.tigris.org/faq.html#repoaccess for instructions
716
       on how to clone a remote CVS repository locally.
717
718
    By default, the trunk, branches and tags are all exported. If you
719
    only want the trunk, use the `--trunk-only` option.
720
721
    By default, filenames, log messages and author names are expected
722
    to be encoded in ascii. Use the `--encoding` option to specify an
723
    alternative. If multiple encodings are used, specify the option
724
    multiple times. For a list of valid encoding names, see
725
    http://docs.python.org/lib/standard-encodings.html.
726
727
    Windows users need to install GNU sort and use the `--sort`
728
    option to specify its location. GNU sort can be downloaded from
729
    http://unxutils.sourceforge.net/.
730
    """
731
    hidden = False
732
    _see_also = ['fast-import', 'fast-import-filter']
733
    takes_args = ['source', 'destination']
734
    takes_options = ['verbose',
735
                    Option('trunk-only',
736
                        help="Export just the trunk, ignoring tags and branches."
737
                        ),
738
                    ListOption('encoding', type=str, argname='CODEC',
739
                        help="Encoding used for filenames, commit messages "
740
                             "and author names if not ascii."
741
                        ),
742
                    Option('sort', type=str, argname='PATH',
743
                        help="GNU sort program location if not on the path."
744
                        ),
745
                    ]
746
    encoding_type = 'exact'
747
    def run(self, source, destination, verbose=False, trunk_only=False,
748
        encoding=None, sort=None):
749
        load_fastimport()
750
        from bzrlib.plugins.fastimport.exporters import fast_export_from
751
        custom = []
752
        if trunk_only:
753
            custom.append("--trunk-only")
754
        if encoding:
755
            for enc in encoding:
756
                custom.extend(['--encoding', enc])
757
        if sort:
758
            custom.extend(['--sort', sort])
759
        fast_export_from(source, destination, 'cvs', verbose, custom)
760
761
762
class cmd_fast_export_from_darcs(Command):
763
    """Generate a fast-import file from a Darcs repository.
764
765
    Destination is a dump file, typically named xxx.fi where xxx is
766
    the name of the project. If '-' is given, standard output is used.
767
768
    Darcs 2.2 or later must be installed as various subcommands are
769
    used to access the source repository. The source may be a network
770
    URL but using a local URL is recommended for performance reasons.
771
    """
772
    hidden = False
773
    _see_also = ['fast-import', 'fast-import-filter']
774
    takes_args = ['source', 'destination']
775
    takes_options = ['verbose',
776
                    Option('encoding', type=str, argname='CODEC',
777
                        help="Encoding used for commit messages if not utf-8."
778
                        ),
779
                    ]
780
    encoding_type = 'exact'
781
    def run(self, source, destination, verbose=False, encoding=None):
782
        from bzrlib.plugins.fastimport.exporters import fast_export_from
783
        custom = None
784
        if encoding is not None:
785
            custom = ['--encoding', encoding]
786
        fast_export_from(source, destination, 'darcs', verbose, custom)
787
788
789
class cmd_fast_export_from_hg(Command):
790
    """Generate a fast-import file from a Mercurial repository.
791
792
    Destination is a dump file, typically named xxx.fi where xxx is
793
    the name of the project. If '-' is given, standard output is used.
794
795
    Mercurial 1.2 or later must be installed as its libraries are used
796
    to access the source repository. Given the APIs currently used,
797
    the source repository must be a local file, not a network URL.
798
    """
799
    hidden = False
800
    _see_also = ['fast-import', 'fast-import-filter']
801
    takes_args = ['source', 'destination']
802
    takes_options = ['verbose']
803
    encoding_type = 'exact'
804
    def run(self, source, destination, verbose=False):
805
        load_fastimport()
806
        from bzrlib.plugins.fastimport.exporters import fast_export_from
807
        fast_export_from(source, destination, 'hg', verbose)
808
809
810
class cmd_fast_export_from_git(Command):
811
    """Generate a fast-import file from a Git repository.
812
813
    Destination is a dump file, typically named xxx.fi where xxx is
814
    the name of the project. If '-' is given, standard output is used.
815
816
    Git 1.6 or later must be installed as the git fast-export
817
    subcommand is used under the covers to generate the stream.
818
    The source must be a local directory.
819
820
    .. note::
821
    
822
       Earlier versions of Git may also work fine but are
823
       likely to receive less active support if problems arise.
824
    """
825
    hidden = False
826
    _see_also = ['fast-import', 'fast-import-filter']
827
    takes_args = ['source', 'destination']
828
    takes_options = ['verbose']
829
    encoding_type = 'exact'
830
    def run(self, source, destination, verbose=False):
831
        load_fastimport()
832
        from bzrlib.plugins.fastimport.exporters import fast_export_from
833
        fast_export_from(source, destination, 'git', verbose)
834
835
836
class cmd_fast_export_from_mtn(Command):
837
    """Generate a fast-import file from a Monotone repository.
838
839
    Destination is a dump file, typically named xxx.fi where xxx is
840
    the name of the project. If '-' is given, standard output is used.
841
842
    Monotone 0.43 or later must be installed as the mtn git_export
843
    subcommand is used under the covers to generate the stream.
844
    The source must be a local directory.
845
    """
846
    hidden = False
847
    _see_also = ['fast-import', 'fast-import-filter']
848
    takes_args = ['source', 'destination']
849
    takes_options = ['verbose']
850
    encoding_type = 'exact'
851
    def run(self, source, destination, verbose=False):
852
        load_fastimport()
853
        from bzrlib.plugins.fastimport.exporters import fast_export_from
854
        fast_export_from(source, destination, 'mtn', verbose)
855
856
857
class cmd_fast_export_from_p4(Command):
858
    """Generate a fast-import file from a Perforce repository.
859
860
    Source is a Perforce depot path, e.g., //depot/project
861
862
    Destination is a dump file, typically named xxx.fi where xxx is
863
    the name of the project. If '-' is given, standard output is used.
864
865
    bzrp4 must be installed as its p4_fast_export.py module is used under
866
    the covers to do the export.  bzrp4 can be downloaded from
867
    https://launchpad.net/bzrp4/.
868
869
    The P4PORT environment variable must be set, and you must be logged
870
    into the Perforce server.
871
872
    By default, only the HEAD changelist is exported.  To export all
873
    changelists, append '@all' to the source.  To export a revision range,
874
    append a comma-delimited pair of changelist numbers to the source,
875
    e.g., '100,200'.
876
    """
877
    hidden = False
878
    _see_also = ['fast-import', 'fast-import-filter']
879
    takes_args = ['source', 'destination']
880
    takes_options = []
881
    encoding_type = 'exact'
882
    def run(self, source, destination, verbose=False):
883
        load_fastimport()
884
        from bzrlib.plugins.fastimport.exporters import fast_export_from
885
        custom = []
886
        fast_export_from(source, destination, 'p4', verbose, custom)
887
888
889
class cmd_fast_export_from_svn(Command):
890
    """Generate a fast-import file from a Subversion repository.
891
892
    Destination is a dump file, typically named xxx.fi where xxx is
893
    the name of the project. If '-' is given, standard output is used.
894
895
    Python-Subversion (Python bindings to the Subversion APIs)
896
    1.4 or later must be installed as this library is used to
897
    access the source repository. The source may be a network URL
898
    but using a local URL is recommended for performance reasons.
899
    """
900
    hidden = False
901
    _see_also = ['fast-import', 'fast-import-filter']
902
    takes_args = ['source', 'destination']
903
    takes_options = ['verbose',
904
                    Option('trunk-path', type=str, argname="STR",
905
                        help="Path in repo to /trunk.\n"
906
                              "May be `regex:/cvs/(trunk)/proj1/(.*)` in "
907
                              "which case the first group is used as the "
908
                              "branch name and the second group is used "
909
                              "to match files.",
910
                        ),
911
                    ]
912
    encoding_type = 'exact'
0.64.327 by Jelmer Vernooij
Remove --branches-path and --tags-path options, which are not implemented by the underlying code yet.
913
    def run(self, source, destination, verbose=False, trunk_path=None):
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
914
        load_fastimport()
915
        from bzrlib.plugins.fastimport.exporters import fast_export_from
916
        custom = []
917
        if trunk_path is not None:
918
            custom.extend(['--trunk-path', trunk_path])
919
        fast_export_from(source, destination, 'svn', verbose, custom)