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