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
|
|
75 |
importing large projects, namely::
|
|
76 |
||
77 |
bzr init-repo .
|
|
78 |
front-end > xxx.fi
|
|
79 |
bzr fast-export-info -v xxx.fi > xxx.cfg
|
|
80 |
bzr fast-export xxx.fi --info xxx.cfg
|
|
81 |
||
82 |
In this scenario, the xxx.cfg file generated by the first pass
|
|
83 |
holds caching hints that the second pass uses to lower memory
|
|
84 |
usage.
|
|
85 |
|
|
86 |
If you wish to write a custom exporter for your project, see
|
|
87 |
http://bazaar-vcs.org/BzrFastImport for the detailed protocol
|
|
88 |
specification. In many cases, exporters can be written quite
|
|
89 |
quickly using whatever scripting/programming language you like.
|
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
90 |
|
91 |
Examples::
|
|
92 |
||
93 |
cd /git/repo/path
|
|
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
94 |
git-fast-export --signed-tags=warn | bzr fast-import -
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
95 |
|
96 |
Import a Git repository into Bazaar.
|
|
97 |
||
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
98 |
svn-fast-export.py /svn/repo/path | bzr fast-import -
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
99 |
|
100 |
Import a Subversion repository into Bazaar.
|
|
101 |
||
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
102 |
hg-fast-export.py -r /hg/repo/path | bzr fast-import -
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
103 |
|
104 |
Import a Mercurial repository into Bazaar.
|
|
105 |
"""
|
|
106 |
hidden = True |
|
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
107 |
_see_also = ['fast-import-info', 'fast-import-filter'] |
108 |
takes_args = ['source'] |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
109 |
takes_options = ['verbose', |
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
110 |
Option('info', type=str, |
111 |
help="Path to file containing caching hints.", |
|
112 |
),
|
|
113 |
Option('trees', |
|
114 |
help="Update working trees.", |
|
115 |
),
|
|
116 |
Option('checkpoint', type=int, |
|
117 |
help="Checkpoint automatically every N revisions.", |
|
118 |
),
|
|
119 |
Option('count', type=int, |
|
120 |
help="Import this many revisions then exit.", |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
121 |
),
|
|
0.64.44
by Ian Clatworthy
smart caching of serialised inventories |
122 |
Option('inv-cache', type=int, |
123 |
help="Number of inventories to cache.", |
|
124 |
),
|
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
125 |
]
|
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
126 |
aliases = [] |
127 |
def run(self, source, verbose=False, info=None, trees=False, |
|
|
0.64.44
by Ian Clatworthy
smart caching of serialised inventories |
128 |
checkpoint=10000, count=-1, inv_cache=10): |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
129 |
from bzrlib import bzrdir |
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
130 |
from bzrlib.plugins.fastimport.processors import generic_processor |
131 |
control, relpath = bzrdir.BzrDir.open_containing('.') |
|
132 |
params = { |
|
133 |
'info': info, |
|
134 |
'trees': trees, |
|
135 |
'checkpoint': checkpoint, |
|
|
0.64.44
by Ian Clatworthy
smart caching of serialised inventories |
136 |
'count': count, |
137 |
'inv-cache': inv_cache, |
|
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
138 |
}
|
139 |
return _run(source, generic_processor.GenericProcessor, control, |
|
140 |
params, verbose) |
|
141 |
||
142 |
||
143 |
class cmd_fast_import_info(Command): |
|
144 |
"""Output information about a fast-import stream. |
|
145 |
||
146 |
This command reads a fast-import stream and outputs
|
|
147 |
statistics and interesting properties about what it finds.
|
|
148 |
When run in verbose mode, the information is output as a
|
|
149 |
configuration file that can be passed to fast-import to
|
|
150 |
assist it in intelligently caching objects.
|
|
151 |
||
152 |
To specify standard input as the input stream, use a source
|
|
153 |
name of '-'.
|
|
154 |
||
155 |
Examples::
|
|
156 |
||
157 |
front-end | bzr fast-import-info -
|
|
158 |
||
159 |
Display statistics about the import stream produced by front-end.
|
|
160 |
||
161 |
front-end | bzr fast-import-info -v - > front-end.cfg
|
|
162 |
||
163 |
Create a hints file for running fast-import on a large repository.
|
|
164 |
"""
|
|
165 |
hidden = True |
|
166 |
_see_also = ['fast-import'] |
|
167 |
takes_args = ['source'] |
|
168 |
takes_options = ['verbose'] |
|
169 |
aliases = [] |
|
170 |
def run(self, source, verbose=False): |
|
171 |
from bzrlib.plugins.fastimport.processors import info_processor |
|
172 |
return _run(source, info_processor.InfoProcessor, None, {}, verbose) |
|
173 |
||
174 |
||
175 |
class cmd_fast_import_filter(Command): |
|
176 |
"""Filter a fast-import stream displaying selected commands. |
|
177 |
||
178 |
To specify standard input as the input stream, use a source
|
|
179 |
name of '-'. To specify the commands to display, use the -C
|
|
180 |
option one or more times. To specify just some fields for
|
|
181 |
a command, use the syntax::
|
|
182 |
||
183 |
command=field1,...
|
|
184 |
||
185 |
By default, the nominated fields for the nominated commands
|
|
186 |
are displayed tab separated. To see the information in
|
|
187 |
a name:value format, use verbose mode.
|
|
188 |
||
189 |
Note: Binary fields (e.g. data for blobs) are masked out
|
|
190 |
so it is generally safe to view the output in a terminal.
|
|
191 |
||
192 |
Examples::
|
|
193 |
||
194 |
front-end > xxx.fi
|
|
195 |
bzr fast-import-filter xxx.fi -Creset -Ctag
|
|
196 |
||
197 |
Show all the fields of the reset and tag commands.
|
|
198 |
||
199 |
bzr fast-import-filter xxx.fi -Ccommit=mark,merge
|
|
200 |
||
201 |
Show the mark and merge fields of the commit commands.
|
|
202 |
"""
|
|
203 |
hidden = True |
|
204 |
_see_also = ['fast-import'] |
|
205 |
takes_args = ['source'] |
|
206 |
takes_options = ['verbose', |
|
207 |
ListOption('commands', short_name='C', type=str, |
|
208 |
help="Display fields for these commands." |
|
209 |
),
|
|
210 |
]
|
|
211 |
aliases = [] |
|
212 |
def run(self, source, verbose=False, commands=None): |
|
213 |
from bzrlib.plugins.fastimport.processors import filter_processor |
|
214 |
from bzrlib.plugins.fastimport import helpers |
|
215 |
params = helpers.defines_to_dict(commands) |
|
216 |
return _run(source, filter_processor.FilterProcessor, None, params, |
|
217 |
verbose) |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
218 |
|
219 |
||
220 |
register_command(cmd_fast_import) |
|
|
0.64.38
by Ian Clatworthy
clean-up doc ready for initial release |
221 |
register_command(cmd_fast_import_info) |
222 |
register_command(cmd_fast_import_filter) |