/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-17 23:37:24 UTC
  • mto: (0.64.114 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090217233724-y6q12cyoyln6vkh6
code & tests for file copying

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
operatons, 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-info
 
40
  bzr help fast-import-query
 
41
 
 
42
To report bugs or publish enhancements, visit the bzr-fastimport project
 
43
page on Launchpad, https://launchpad.net/bzr-fastimport.
 
44
"""
 
45
 
 
46
from bzrlib.commands import Command, register_command
 
47
from bzrlib.option import Option, ListOption
 
48
 
 
49
 
 
50
def test_suite():
 
51
    import tests
 
52
    return tests.test_suite()
 
53
 
 
54
 
 
55
def _run(source, processor_factory, control, params, verbose):
 
56
    """Create and run a processor.
 
57
    
 
58
    :param source: a filename or '-' for standard input
 
59
    :param processor_factory: a callable for creating a processor
 
60
    :param control: the BzrDir of the destination or None if no
 
61
      destination is expected
 
62
    """
 
63
    import parser
 
64
    if source == '-':
 
65
        import sys
 
66
        stream = sys.stdin
 
67
        try:
 
68
            import msvcrt
 
69
            import os
 
70
            msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
 
71
        except ImportError:
 
72
            pass
 
73
    else:
 
74
        stream = open(source, "rb")
 
75
    proc = processor_factory(control, params=params, verbose=verbose)
 
76
    p = parser.ImportParser(stream, verbose=verbose)
 
77
    return proc.process(p.iter_commands)
 
78
 
 
79
 
 
80
class cmd_fast_import(Command):
 
81
    """Backend for fast Bazaar data importers.
 
82
 
 
83
    This command reads a mixed command/data stream and
 
84
    creates branches in the current repository accordingly.
 
85
    To specify standard input as the input stream, use a
 
86
    source name of '-'.
 
87
    
 
88
    The usual recipe is::
 
89
 
 
90
      bzr init-repo .
 
91
      front-end | bzr fast-import -
 
92
 
 
93
    If run inside a branch using a shared repository, then
 
94
    the current branch is made the trunk and other branches,
 
95
    if any, are created in sister directories. If run inside
 
96
    a standalone tree, the current branch is also made the
 
97
    trunk, but warnings are output about other branches found.
 
98
    
 
99
    The stream format is upwardly compatible with git-fast-import
 
100
    so existing front-ends for that tool can typically be reused
 
101
    without changes. See http://bazaar-vcs.org/BzrFastImport for
 
102
    links to matching exporters from Subversion, CVS, Git,
 
103
    Mercurial, Darcs, Perforce and SCCS.
 
104
 
 
105
    While reusing an existing format with existing frontends is
 
106
    great, it does mean a slightly more complex recipe when
 
107
    importing large projects via exporters that reuse blob data
 
108
    across commits, namely::
 
109
 
 
110
      bzr init-repo .
 
111
      front-end > xxx.fi
 
112
      bzr fast-import-info -v xxx.fi > xxx.cfg
 
113
      bzr fast-import xxx.fi --info xxx.cfg
 
114
 
 
115
    In this scenario, the xxx.cfg file generated by the first pass
 
116
    holds caching hints that the second pass uses to lower memory
 
117
    usage.
 
118
    
 
119
    At checkpoints and on completion, the commit-id -> revision-id
 
120
    map is saved to a file called 'fastimport-id-map' in the control
 
121
    directory for the repository (e.g. .bzr/repository). If the import
 
122
    is interrupted or unexpectedly crashes, it can be started again
 
123
    and this file will be used to skip over already loaded revisions.
 
124
    As long as subsequent exports from the original source begin
 
125
    with exactly the same revisions, you can use this feature to
 
126
    maintain a mirror of a repository managed by a foreign tool.
 
127
    If and when Bazaar is used to manage the repository, this file
 
128
    can be safely deleted.
 
129
 
 
130
    If you wish to write a custom exporter for your project, see
 
131
    http://bazaar-vcs.org/BzrFastImport for the detailed protocol
 
132
    specification. In many cases, exporters can be written quite
 
133
    quickly using whatever scripting/programming language you like.
 
134
 
 
135
    Examples::
 
136
 
 
137
     cd /git/repo/path
 
138
     git-fast-export --signed-tags=warn | bzr fast-import -
 
139
 
 
140
        Import a Git repository into Bazaar.
 
141
 
 
142
     svn-fast-export.py /svn/repo/path | bzr fast-import -
 
143
 
 
144
        Import a Subversion repository into Bazaar.
 
145
 
 
146
     hg-fast-export.py -r /hg/repo/path | bzr fast-import -
 
147
 
 
148
        Import a Mercurial repository into Bazaar.
 
149
    """
 
150
    hidden = True
 
151
    _see_also = ['fast-import-info', 'fast-import-query']
 
152
    takes_args = ['source']
 
153
    takes_options = ['verbose',
 
154
                    Option('info', type=str,
 
155
                        help="Path to file containing caching hints.",
 
156
                        ),
 
157
                    Option('trees',
 
158
                        help="Update working trees.",
 
159
                        ),
 
160
                    Option('checkpoint', type=int,
 
161
                        help="Checkpoint automatically every N revisions.",
 
162
                        ),
 
163
                    Option('count', type=int,
 
164
                        help="Import this many revisions then exit.",
 
165
                        ),
 
166
                    Option('inv-cache', type=int,
 
167
                        help="Number of inventories to cache.",
 
168
                        ),
 
169
                    Option('experimental',
 
170
                        help="Enable experimental features.",
 
171
                        ),
 
172
                    Option('import-marks', type=str,
 
173
                        help="Import marks from file."),
 
174
                    Option('export-marks', type=str,
 
175
                        help="Export marks to file."),
 
176
                     ]
 
177
    aliases = []
 
178
    def run(self, source, verbose=False, info=None, trees=False,
 
179
        checkpoint=10000, count=-1, inv_cache=10,
 
180
        experimental=True, import_marks=None, export_marks=None):
 
181
        from bzrlib import bzrdir
 
182
        from bzrlib.plugins.fastimport.processors import generic_processor
 
183
        control, relpath = bzrdir.BzrDir.open_containing('.')
 
184
        params = {
 
185
            'info': info,
 
186
            'trees': trees,
 
187
            'checkpoint': checkpoint,
 
188
            'count': count,
 
189
            'inv-cache': inv_cache,
 
190
            'experimental': experimental,
 
191
            'import-marks': import_marks,
 
192
            'export-marks': export_marks,
 
193
            }
 
194
        return _run(source, generic_processor.GenericProcessor, control,
 
195
            params, verbose)
 
196
 
 
197
 
 
198
class cmd_fast_import_info(Command):
 
199
    """Output information about a fast-import stream.
 
200
 
 
201
    This command reads a fast-import stream and outputs
 
202
    statistics and interesting properties about what it finds.
 
203
    When run in verbose mode, the information is output as a
 
204
    configuration file that can be passed to fast-import to
 
205
    assist it in intelligently caching objects.
 
206
 
 
207
    To specify standard input as the input stream, use a source
 
208
    name of '-'.
 
209
 
 
210
    Examples::
 
211
 
 
212
     front-end | bzr fast-import-info -
 
213
 
 
214
        Display statistics about the import stream produced by front-end.
 
215
 
 
216
     front-end | bzr fast-import-info -v - > front-end.cfg
 
217
 
 
218
       Create a hints file for running fast-import on a large repository.
 
219
    """
 
220
    hidden = True
 
221
    _see_also = ['fast-import']
 
222
    takes_args = ['source']
 
223
    takes_options = ['verbose']
 
224
    aliases = []
 
225
    def run(self, source, verbose=False):
 
226
        from bzrlib.plugins.fastimport.processors import info_processor
 
227
        return _run(source, info_processor.InfoProcessor, None, {}, verbose)
 
228
 
 
229
 
 
230
class cmd_fast_import_query(Command):
 
231
    """Query a fast-import stream displaying selected commands.
 
232
 
 
233
    To specify standard input as the input stream, use a source
 
234
    name of '-'. To specify the commands to display, use the -C
 
235
    option one or more times. To specify just some fields for
 
236
    a command, use the syntax::
 
237
 
 
238
      command=field1,...
 
239
 
 
240
    By default, the nominated fields for the nominated commands
 
241
    are displayed tab separated. To see the information in
 
242
    a name:value format, use verbose mode.
 
243
 
 
244
    Note: Binary fields (e.g. data for blobs) are masked out
 
245
    so it is generally safe to view the output in a terminal.
 
246
 
 
247
    Examples::
 
248
 
 
249
      front-end > xxx.fi
 
250
      bzr fast-import-query xxx.fi -Creset -Ctag
 
251
 
 
252
        Show all the fields of the reset and tag commands.
 
253
 
 
254
      bzr fast-import-query xxx.fi -Ccommit=mark,merge
 
255
 
 
256
        Show the mark and merge fields of the commit commands.
 
257
    """
 
258
    hidden = True
 
259
    _see_also = ['fast-import']
 
260
    takes_args = ['source']
 
261
    takes_options = ['verbose',
 
262
                    ListOption('commands', short_name='C', type=str,
 
263
                        help="Display fields for these commands."
 
264
                        ),
 
265
                     ]
 
266
    aliases = []
 
267
    def run(self, source, verbose=False, commands=None):
 
268
        from bzrlib.plugins.fastimport.processors import query_processor
 
269
        from bzrlib.plugins.fastimport import helpers
 
270
        params = helpers.defines_to_dict(commands)
 
271
        return _run(source, query_processor.QueryProcessor, None, params,
 
272
            verbose)
 
273
 
 
274
 
 
275
register_command(cmd_fast_import)
 
276
register_command(cmd_fast_import_info)
 
277
register_command(cmd_fast_import_query)