/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
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
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
16
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
17
r"""FastImport Plugin
18
=================
19
20
The fastimport plugin provides stream-based importing of data into Bazaar.
21
A bzr-fast-export.py script is also included providing exporting of data
22
out of Bazaar to the same format. As well as enabling interchange between
23
multiple VCS tools, fastimport/export can be useful for complex branch
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
24
operations, e.g. partitioning off part of a code base in order to Open
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
25
Source it.
26
27
The normal import recipe is::
28
29
  bzr init-repo .
30
  front-end | bzr fast-import -
31
32
Numerous front-ends are provided in the exporters directory where
33
the plugin is installed. The list of known front-ends and their
34
status is documented on http://bazaar-vcs.org/BzrFastImport/FrontEnds.
35
For further details, see http://bazaar-vcs.org/BzrFastImport and the
36
online help for the commands::
37
38
  bzr help fast-import
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
39
  bzr help fast-export
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
40
  bzr help fast-import-filter
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
41
  bzr help fast-import-info
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
42
  bzr help fast-import-query
0.64.81 by Ian Clatworthy
'bzr help fastimport' now provides useful help
43
44
To report bugs or publish enhancements, visit the bzr-fastimport project
45
page on Launchpad, https://launchpad.net/bzr-fastimport.
46
"""
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
47
0.64.126 by Ian Clatworthy
ensure version appears in bzr plugins output (Alexander Belchenko)
48
version_info = (0, 8, 0, 'dev', 0)
49
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
50
from bzrlib.commands import Command, register_command
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
51
from bzrlib.option import Option, ListOption
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
52
53
54
def test_suite():
55
    import tests
56
    return tests.test_suite()
57
58
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
59
def _run(source, processor_factory, control, params, verbose):
60
    """Create and run a processor.
61
    
62
    :param source: a filename or '-' for standard input
63
    :param processor_factory: a callable for creating a processor
64
    :param control: the BzrDir of the destination or None if no
65
      destination is expected
66
    """
67
    import parser
68
    if source == '-':
69
        import sys
70
        stream = sys.stdin
0.65.6 by James Westby
Open the input in binary mode, as suggested by Paul Moore.
71
        try:
0.64.98 by Ian Clatworthy
fix os import as needed on Windows
72
            import os
0.77.17 by Alexander Belchenko
fast-import-filter should produce binary output.
73
            if os.name == 'nt':
74
                fileno = getattr(sys.stdin, 'fileno', None)
75
                if fileno:
76
                    no = fileno()
77
                    if no >= 0:     # -1 means we're working as subprocess
78
                        import msvcrt
79
                        msvcrt.setmode(no, os.O_BINARY)
0.65.6 by James Westby
Open the input in binary mode, as suggested by Paul Moore.
80
        except ImportError:
81
            pass
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
82
    else:
0.65.6 by James Westby
Open the input in binary mode, as suggested by Paul Moore.
83
        stream = open(source, "rb")
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
84
    proc = processor_factory(control, params=params, verbose=verbose)
85
    p = parser.ImportParser(stream, verbose=verbose)
86
    return proc.process(p.iter_commands)
0.64.8 by Ian Clatworthy
custom parameters for processors
87
88
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
89
class cmd_fast_import(Command):
90
    """Backend for fast Bazaar data importers.
91
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
92
    This command reads a mixed command/data stream and
93
    creates branches in the current repository accordingly.
94
    To specify standard input as the input stream, use a
95
    source name of '-'.
96
    
97
    The usual recipe is::
98
99
      bzr init-repo .
100
      front-end | bzr fast-import -
101
102
    If run inside a branch using a shared repository, then
103
    the current branch is made the trunk and other branches,
104
    if any, are created in sister directories. If run inside
105
    a standalone tree, the current branch is also made the
106
    trunk, but warnings are output about other branches found.
0.82.1 by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names
107
108
    Git reference names are mapped to bzr branch names as follows:
109
      
110
    * refs/heads/foo is mapped to foo
111
    * refs/remotes/origin/foo is mapped to foo.remote
112
    * refs/tags/foo is mapped to foo.tag
113
    * */master is mapped to trunk, trunk.remote, etc.
114
    * */trunk is mapped to git-trunk, git-trunk.remote, etc.
115
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
116
    The stream format is upwardly compatible with git-fast-import
117
    so existing front-ends for that tool can typically be reused
118
    without changes. See http://bazaar-vcs.org/BzrFastImport for
119
    links to matching exporters from Subversion, CVS, Git,
120
    Mercurial, Darcs, Perforce and SCCS.
0.82.1 by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names
121
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
122
    While reusing an existing format with existing frontends is
123
    great, it does mean a slightly more complex recipe when
0.64.50 by Ian Clatworthy
cleanly restart after an interruption - basic mirroring
124
    importing large projects via exporters that reuse blob data
125
    across commits, namely::
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
126
127
      bzr init-repo .
128
      front-end > xxx.fi
0.66.1 by Elliot Murphy
Fix typo in online help.
129
      bzr fast-import-info -v xxx.fi > xxx.cfg
130
      bzr fast-import xxx.fi --info xxx.cfg
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
131
132
    In this scenario, the xxx.cfg file generated by the first pass
133
    holds caching hints that the second pass uses to lower memory
134
    usage.
0.82.1 by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names
135
0.64.50 by Ian Clatworthy
cleanly restart after an interruption - basic mirroring
136
    At checkpoints and on completion, the commit-id -> revision-id
137
    map is saved to a file called 'fastimport-id-map' in the control
138
    directory for the repository (e.g. .bzr/repository). If the import
139
    is interrupted or unexpectedly crashes, it can be started again
140
    and this file will be used to skip over already loaded revisions.
141
    As long as subsequent exports from the original source begin
142
    with exactly the same revisions, you can use this feature to
143
    maintain a mirror of a repository managed by a foreign tool.
144
    If and when Bazaar is used to manage the repository, this file
145
    can be safely deleted.
146
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
147
    If you wish to write a custom exporter for your project, see
148
    http://bazaar-vcs.org/BzrFastImport for the detailed protocol
149
    specification. In many cases, exporters can be written quite
150
    quickly using whatever scripting/programming language you like.
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
151
152
    Examples::
153
154
     cd /git/repo/path
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
155
     git-fast-export --signed-tags=warn | bzr fast-import -
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
156
157
        Import a Git repository into Bazaar.
158
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
159
     svn-fast-export.py /svn/repo/path | bzr fast-import -
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
160
161
        Import a Subversion repository into Bazaar.
162
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
163
     hg-fast-export.py -r /hg/repo/path | bzr fast-import -
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
164
165
        Import a Mercurial repository into Bazaar.
166
    """
0.64.120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
167
    hidden = False
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
168
    _see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
169
    takes_args = ['source']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
170
    takes_options = ['verbose',
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
171
                    Option('info', type=str,
172
                        help="Path to file containing caching hints.",
173
                        ),
174
                    Option('trees',
175
                        help="Update working trees.",
176
                        ),
177
                    Option('checkpoint', type=int,
178
                        help="Checkpoint automatically every N revisions.",
179
                        ),
180
                    Option('count', type=int,
181
                        help="Import this many revisions then exit.",
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
182
                        ),
0.64.44 by Ian Clatworthy
smart caching of serialised inventories
183
                    Option('inv-cache', type=int,
184
                        help="Number of inventories to cache.",
185
                        ),
0.64.47 by Ian Clatworthy
add option for enabling experimental stuff
186
                    Option('experimental',
187
                        help="Enable experimental features.",
188
                        ),
0.68.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
189
                    Option('import-marks', type=str,
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
190
                        help="Import marks from file."
191
                        ),
0.68.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
192
                    Option('export-marks', type=str,
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
193
                        help="Export marks to file."
194
                        ),
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
195
                     ]
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
196
    aliases = []
197
    def run(self, source, verbose=False, info=None, trees=False,
0.64.99 by Ian Clatworthy
remove --inv-fulltext option
198
        checkpoint=10000, count=-1, inv_cache=10,
0.81.5 by Ian Clatworthy
basic DeltaCommitHandler generating deltas
199
        experimental=False, import_marks=None, export_marks=None):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
200
        from bzrlib import bzrdir
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
201
        from bzrlib.plugins.fastimport.processors import generic_processor
202
        control, relpath = bzrdir.BzrDir.open_containing('.')
203
        params = {
204
            'info': info,
205
            'trees': trees,
206
            'checkpoint': checkpoint,
0.64.44 by Ian Clatworthy
smart caching of serialised inventories
207
            'count': count,
208
            'inv-cache': inv_cache,
0.64.47 by Ian Clatworthy
add option for enabling experimental stuff
209
            'experimental': experimental,
0.68.7 by Pieter de Bie
Add importing and exporting of marks to bzr-fastimport
210
            'import-marks': import_marks,
211
            'export-marks': export_marks,
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
212
            }
213
        return _run(source, generic_processor.GenericProcessor, control,
214
            params, verbose)
215
216
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
217
class cmd_fast_import_filter(Command):
218
    """Filter a fast-import stream to include/exclude files & directories.
219
220
    This command is useful for splitting a subdirectory or bunch of
221
    files out from a project to create a new project complete with history
222
    for just those files. It can also be used to create a new project
223
    repository that removes all references to files that should not have
224
    been committed, e.g. security-related information (like passwords),
225
    commercially sensitive material, files with an incompatible license or
226
    large binary files like CD images.
227
228
    When filtering out a subdirectory (or file), the new stream uses the
229
    subdirectory (or subdirectory containing the file) as the root. As
230
    fast-import doesn't know in advance whether a path is a file or
231
    directory in the stream, you need to specify a trailing '/' on
232
    directories passed to the --includes option. If multiple files or
233
    directories are given, the new root is the deepest common directory.
234
235
    To specify standard input as the input stream, use a source
236
    name of '-'.
237
238
    Note: If a path has been renamed, take care to specify the *original*
239
    path name, not the final name that it ends up with.
240
241
    Examples::
242
243
      Create a new project from a library. (Note the trailing / on the
244
      directory name of the library.)
245
246
        front-end | bzr fast-import-filter -i lib/xxx/ > xxx.fi
247
        bzr init-repo mylibrary
248
        cd mylibrary
249
        bzr fast-import ../xxx.fi
250
        (lib/xxx/foo is now foo)
251
252
      Create a new repository without a sensitive file.
253
254
        front-end | bzr fast-import-filter -x missile-codes.txt > clean.fi
255
        bzr init-repo project.clean
256
        cd project.clean
257
        bzr fast-import ../clean.fi
258
    """
259
    hidden = False
260
    _see_also = ['fast-import']
261
    takes_args = ['source']
262
    takes_options = ['verbose',
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
263
                    ListOption('include_paths', short_name='i', type=str,
264
                        help="Only include commits affecting these paths."
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
265
                             " Directories should have a trailing /."
266
                        ),
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
267
                    ListOption('exclude_paths', short_name='x', type=str,
268
                        help="Exclude these paths from commits."
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
269
                        ),
270
                     ]
271
    aliases = []
0.77.17 by Alexander Belchenko
fast-import-filter should produce binary output.
272
    encoding_type = 'exact'
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
273
    def run(self, source, verbose=False, include_paths=None,
274
        exclude_paths=None):
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
275
        from bzrlib.plugins.fastimport.processors import filter_processor
276
        params = {
0.77.5 by Ian Clatworthy
add _paths to option & params names as other types of filtering may be added later
277
            'include_paths': include_paths,
278
            'exclude_paths': exclude_paths,
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
279
            }
280
        return _run(source, filter_processor.FilterProcessor, None, params,
281
            verbose)
282
283
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
284
class cmd_fast_import_info(Command):
285
    """Output information about a fast-import stream.
286
287
    This command reads a fast-import stream and outputs
288
    statistics and interesting properties about what it finds.
289
    When run in verbose mode, the information is output as a
290
    configuration file that can be passed to fast-import to
291
    assist it in intelligently caching objects.
292
293
    To specify standard input as the input stream, use a source
294
    name of '-'.
295
296
    Examples::
297
298
     front-end | bzr fast-import-info -
299
300
        Display statistics about the import stream produced by front-end.
301
302
     front-end | bzr fast-import-info -v - > front-end.cfg
303
304
       Create a hints file for running fast-import on a large repository.
305
    """
0.64.120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
306
    hidden = False
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
307
    _see_also = ['fast-import']
308
    takes_args = ['source']
309
    takes_options = ['verbose']
310
    aliases = []
311
    def run(self, source, verbose=False):
312
        from bzrlib.plugins.fastimport.processors import info_processor
313
        return _run(source, info_processor.InfoProcessor, None, {}, verbose)
314
315
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
316
class cmd_fast_import_query(Command):
317
    """Query a fast-import stream displaying selected commands.
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
318
319
    To specify standard input as the input stream, use a source
320
    name of '-'. To specify the commands to display, use the -C
321
    option one or more times. To specify just some fields for
322
    a command, use the syntax::
323
324
      command=field1,...
325
326
    By default, the nominated fields for the nominated commands
327
    are displayed tab separated. To see the information in
328
    a name:value format, use verbose mode.
329
330
    Note: Binary fields (e.g. data for blobs) are masked out
331
    so it is generally safe to view the output in a terminal.
332
333
    Examples::
334
335
      front-end > xxx.fi
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
336
      bzr fast-import-query xxx.fi -Creset -Ctag
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
337
338
        Show all the fields of the reset and tag commands.
339
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
340
      bzr fast-import-query xxx.fi -Ccommit=mark,merge
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
341
342
        Show the mark and merge fields of the commit commands.
343
    """
344
    hidden = True
0.64.120 by Ian Clatworthy
unhide fast-import and fast-import-info commands
345
    _see_also = ['fast-import', 'fast-import-filter']
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
346
    takes_args = ['source']
347
    takes_options = ['verbose',
348
                    ListOption('commands', short_name='C', type=str,
349
                        help="Display fields for these commands."
350
                        ),
351
                     ]
352
    aliases = []
353
    def run(self, source, verbose=False, commands=None):
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
354
        from bzrlib.plugins.fastimport.processors import query_processor
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
355
        from bzrlib.plugins.fastimport import helpers
356
        params = helpers.defines_to_dict(commands)
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
357
        return _run(source, query_processor.QueryProcessor, None, params,
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
358
            verbose)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
359
360
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
361
class cmd_fast_export(Command):
362
    """Generate a fast-import stream from a Bazaar branch.
363
364
    This program generates a stream from a bzr branch in the format required by
365
    git-fast-import(1). It preserves merges correctly, even merged branches with
366
    no common history (`bzr merge -r 0..-1`).
367
368
    To import several unmerged but related branches into the same repository,
369
    use the --{export,import}-marks options, and specify a name for the git
370
    branch like this::
371
    
372
        % bzr-fast-export --export-marks=marks.bzr project.dev |
373
              GIT_DIR=project/.git git-fast-import --export-marks=marks.git
374
375
        % bzr-fast-export --import-marks=marks.bzr -b other project.other |
376
              GIT_DIR=project/.git git-fast-import --import-marks=marks.git
0.79.10 by Ian Clatworthy
documentation clean-ups
377
378
    If you get a "Missing space after source" error from git-fast-import,
379
    see the top of the commands.py module for a work-around.
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
380
    """
0.79.10 by Ian Clatworthy
documentation clean-ups
381
    hidden = False
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
382
    _see_also = ['fast-import', 'fast-import-filter']
383
    takes_args = ['source']
384
    takes_options = ['verbose',
385
                    Option('git-branch', short_name='b', type=str,
386
                        argname='FILE',
387
                        help='Name of the git branch to create (default=master).'
388
                        ),
389
                    Option('checkpoint', type=int, argname='N',
390
                        help="Checkpoint every N revisions (default=1000)."
391
                        ),
392
                    Option('marks', type=str, argname='FILE',
393
                        help="Import marks from and export marks to file."
394
                        ),
395
                    Option('import-marks', type=str, argname='FILE',
396
                        help="Import marks from file."
397
                        ),
398
                    Option('export-marks', type=str, argname='FILE',
399
                        help="Export marks to file."
400
                        ),
401
                     ]
402
    aliases = []
403
    def run(self, source, verbose=False, git_branch="master", checkpoint=1000,
404
        marks=None, import_marks=None, export_marks=None):
405
        from bzrlib.plugins.fastimport import bzr_exporter
406
407
        if marks:                                              
408
            import_marks = export_marks = marks
409
        exporter = bzr_exporter.BzrFastExporter(source,
410
            git_branch=git_branch, checkpoint=checkpoint,
411
            import_marks_file=import_marks, export_marks_file=export_marks)
412
        return exporter.run()
413
414
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
415
register_command(cmd_fast_import)
0.77.1 by Ian Clatworthy
initial cut at fast-import-filter
416
register_command(cmd_fast_import_filter)
0.64.38 by Ian Clatworthy
clean-up doc ready for initial release
417
register_command(cmd_fast_import_info)
0.64.111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
418
register_command(cmd_fast_import_query)
0.79.1 by Ian Clatworthy
turn bzr-fast-export into a fast-export command
419
register_command(cmd_fast_export)