/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-18 01:09:34 UTC
  • mto: (0.64.117 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090218010934-dn6xdnq78u1egdf7
move escape_commit_message into helpers

Show diffs side-by-side

added added

removed removed

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