16
16
"""Fastimport/fastexport commands."""
18
from __future__ import absolute_import
20
18
from ... import controldir
21
19
from ...commands import Command
22
20
from ...option import Option, RegistryOption
23
from ...sixish import (
41
36
:param user_map: if not None, the file containing the user map.
43
38
from fastimport.errors import ParsingError
44
from ...errors import BzrCommandError
39
from ...errors import CommandError
45
40
from fastimport import parser
46
41
stream = _get_source_stream(source)
47
42
user_mapper = _get_user_mapper(user_map)
51
46
return proc.process(p.iter_commands)
52
47
except ParsingError as e:
53
raise BzrCommandError("%d: Parse error: %s" % (e.lineno, e))
48
raise CommandError("%d: Parse error: %s" % (e.lineno, e))
56
51
def _get_source_stream(source):
242
237
_see_also = ['fast-export', 'fast-import-filter', 'fast-import-info']
243
238
takes_args = ['source', 'destination?']
244
239
takes_options = ['verbose',
245
Option('user-map', type=text_type,
240
Option('user-map', type=str,
246
241
help="Path to file containing a map of user-ids.",
248
Option('info', type=text_type,
243
Option('info', type=str,
249
244
help="Path to file containing caching hints.",
271
266
experimental="Enable experimental features.",
272
267
value_switches=True, enum_switch=False,
274
Option('import-marks', type=text_type,
269
Option('import-marks', type=str,
275
270
help="Import marks from file."
277
Option('export-marks', type=text_type,
272
Option('export-marks', type=str,
278
273
help="Export marks to file."
280
275
RegistryOption('format',
322
317
user_map=user_map)
324
319
def _generate_info(self, source):
325
from ...sixish import StringIO
320
from io import StringIO
326
321
from fastimport import parser
327
322
from fastimport.errors import ParsingError
328
from ...errors import BzrCommandError
323
from ...errors import CommandError
329
324
from fastimport.processors import info_processor
330
325
stream = _get_source_stream(source)
331
326
output = StringIO()
336
331
return_code = proc.process(p.iter_commands)
337
332
except ParsingError as e:
338
raise BzrCommandError("%d: Parse error: %s" % (e.lineno, e))
333
raise CommandError("%d: Parse error: %s" % (e.lineno, e))
339
334
lines = output.getvalue().splitlines()
448
443
_see_also = ['fast-import', 'fast-import-filter']
449
444
takes_args = ['source?', 'destination?']
450
445
takes_options = ['verbose', 'revision',
451
Option('git-branch', short_name='b', type=text_type,
446
Option('git-branch', short_name='b', type=str,
453
448
help='Name of the git branch to create (default=master).'
455
450
Option('checkpoint', type=int, argname='N',
456
451
help="Checkpoint every N revisions (default=10000)."
458
Option('marks', type=text_type, argname='FILE',
453
Option('marks', type=str, argname='FILE',
459
454
help="Import marks from and export marks to file."
461
Option('import-marks', type=text_type, argname='FILE',
456
Option('import-marks', type=str, argname='FILE',
462
457
help="Import marks from file."
464
Option('export-marks', type=text_type, argname='FILE',
459
Option('export-marks', type=str, argname='FILE',
465
460
help="Export marks to file."