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