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