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