28 return s.encode(orig_encoding, 'replace') |
28 return s.encode(orig_encoding, 'replace') |
29 else: |
29 else: |
30 return s.decode('utf-8').encode(orig_encoding, 'replace') |
30 return s.decode('utf-8').encode(orig_encoding, 'replace') |
31 |
31 |
32 source_converters = [ |
32 source_converters = [ |
33 ('cvs', convert_cvs), |
33 ('cvs', convert_cvs, 'branchsort'), |
34 ('git', convert_git), |
34 ('git', convert_git, 'branchsort'), |
35 ('svn', svn_source), |
35 ('svn', svn_source, 'branchsort'), |
36 ('hg', mercurial_source), |
36 ('hg', mercurial_source, 'sourcesort'), |
37 ('darcs', darcs_source), |
37 ('darcs', darcs_source, 'branchsort'), |
38 ('mtn', monotone_source), |
38 ('mtn', monotone_source, 'branchsort'), |
39 ('gnuarch', gnuarch_source), |
39 ('gnuarch', gnuarch_source, 'branchsort'), |
40 ('bzr', bzr_source), |
40 ('bzr', bzr_source, 'branchsort'), |
41 ('p4', p4_source), |
41 ('p4', p4_source, 'branchsort'), |
42 ] |
42 ] |
43 |
43 |
44 sink_converters = [ |
44 sink_converters = [ |
45 ('hg', mercurial_sink), |
45 ('hg', mercurial_sink), |
46 ('svn', svn_sink), |
46 ('svn', svn_sink), |
47 ] |
47 ] |
48 |
48 |
49 def convertsource(ui, path, type, rev): |
49 def convertsource(ui, path, type, rev): |
50 exceptions = [] |
50 exceptions = [] |
51 for name, source in source_converters: |
51 for name, source, sortmode in source_converters: |
52 try: |
52 try: |
53 if not type or name == type: |
53 if not type or name == type: |
54 return source(ui, path, rev) |
54 return source(ui, path, rev), sortmode |
55 except (NoRepo, MissingTool), inst: |
55 except (NoRepo, MissingTool), inst: |
56 exceptions.append(inst) |
56 exceptions.append(inst) |
57 if not ui.quiet: |
57 if not ui.quiet: |
58 for inst in exceptions: |
58 for inst in exceptions: |
59 ui.write("%s\n" % inst) |
59 ui.write("%s\n" % inst) |
362 ui.status(_("assuming destination %s\n") % dest) |
362 ui.status(_("assuming destination %s\n") % dest) |
363 |
363 |
364 destc = convertsink(ui, dest, opts.get('dest_type')) |
364 destc = convertsink(ui, dest, opts.get('dest_type')) |
365 |
365 |
366 try: |
366 try: |
367 srcc = convertsource(ui, src, opts.get('source_type'), |
367 srcc, defaultsort = convertsource(ui, src, opts.get('source_type'), |
368 opts.get('rev')) |
368 opts.get('rev')) |
369 except Exception: |
369 except Exception: |
370 for path in destc.created: |
370 for path in destc.created: |
371 shutil.rmtree(path, True) |
371 shutil.rmtree(path, True) |
372 raise |
372 raise |
373 |
373 |
374 sortmodes = ('datesort', 'sourcesort') |
374 sortmodes = ('branchsort', 'datesort', 'sourcesort') |
375 sortmode = [m for m in sortmodes if opts.get(m)] |
375 sortmode = [m for m in sortmodes if opts.get(m)] |
376 if len(sortmode) > 1: |
376 if len(sortmode) > 1: |
377 raise util.Abort(_('more than one sort mode specified')) |
377 raise util.Abort(_('more than one sort mode specified')) |
378 sortmode = sortmode and sortmode[0] or 'branchsort' |
378 sortmode = sortmode and sortmode[0] or defaultsort |
379 if sortmode == 'sourcesort' and not srcc.hasnativeorder(): |
379 if sortmode == 'sourcesort' and not srcc.hasnativeorder(): |
380 raise util.Abort(_('--sourcesort is not supported by this data source')) |
380 raise util.Abort(_('--sourcesort is not supported by this data source')) |
381 |
381 |
382 fmap = opts.get('filemap') |
382 fmap = opts.get('filemap') |
383 if fmap: |
383 if fmap: |