comparison hgfastimport/__init__.py @ 73:a99e5c6c8e1c

Fix compatibility with 4.6+ Update to work with hg 4.5+ Switch to modern @command decorator API Adds compatiblility with hg 4.2 Clean up formatting and add description Update to work with hg 3.4+ Update to work with hg 3.2+ This breaks compatibility with <3.2. Merged from patches from github:danielj7/hg-fastimport
author Daniel Johnson <daniel@daniel-johnson.org>
date Sun, 12 Aug 2018 07:54:35 -0400
parents 6b716ecb1cf3
children a4f13dc5e3f7
comparison
equal deleted inserted replaced
72:6b716ecb1cf3 73:a99e5c6c8e1c
1 from mercurial import encoding 1 ''' import Git fast-import streams '''
2 from __future__ import absolute_import
3
4 from mercurial import (
5 cmdutil,
6 encoding,
7 util,
8 )
9
2 from mercurial.i18n import _ 10 from mercurial.i18n import _
3 from hgext.convert import convcmd, hg
4 11
5 from hgimport import fastimport_source 12 from hgext.convert import (
13 convcmd,
14 hg,
15 )
16
17 from .hgimport import fastimport_source
18
19 cmdtable = {}
20 try:
21 from mercurial import registrar
22 command = registrar.command(cmdtable)
23 except (ImportError, AttributeError):
24 command = cmdutil.command(cmdtable)
25
26 testedwith = '4.7'
27
28 @command("fastimport",
29 [('', 'branchsort', None, _('try to sort changesets by branches')),
30 ('', 'datesort', None, _('try to sort changesets by date')),
31 ('', 'sourcesort', None, _('preserve source changesets order'))],
32 _('hg fastimport SOURCE ...'),
33 norepo=False)
6 34
7 def fastimport(ui, repo, *sources, **opts): 35 def fastimport(ui, repo, *sources, **opts):
8 """Convert a git fastimport dump into Mercurial changesets. 36 """Convert a git fastimport dump into Mercurial changesets.
9 37
10 Reads a series of SOURCE fastimport dumps and adds the resulting 38 Reads a series of SOURCE fastimport dumps and adds the resulting
27 # encoded UTF-8 55 # encoded UTF-8
28 convcmd.orig_encoding = encoding.encoding 56 convcmd.orig_encoding = encoding.encoding
29 encoding.encoding = 'UTF-8' 57 encoding.encoding = 'UTF-8'
30 58
31 # sink is the current repo, src is the list of fastimport streams 59 # sink is the current repo, src is the list of fastimport streams
32 destc = hg.mercurial_sink(ui, repo.root) 60 destc = hg.mercurial_sink(ui, 'hg', repo.root)
33 srcc = fastimport_source(ui, repo, sources) 61 srcc = fastimport_source(ui, 'fastimport', repo, sources)
34 62
35 # XXX figuring out sortmode copied straight from hgext/convert/convcmd.py 63 # XXX figuring out sortmode copied straight from hgext/convert/convcmd.py
36 defaultsort = 'branchsort' # for efficiency and consistency 64 defaultsort = 'branchsort' # for efficiency and consistency
37 sortmodes = ('branchsort', 'datesort', 'sourcesort') 65 sortmodes = ('branchsort', 'datesort', 'sourcesort')
38 sortmode = [m for m in sortmodes if opts.get(m)] 66 sortmode = [m for m in sortmodes if opts.get(m)]
39 if len(sortmode) > 1: 67 if len(sortmode) > 1:
40 raise util.Abort(_('more than one sort mode specified')) 68 raise util.Abort(_('more than one sort mode specified'))
41 sortmode = sortmode and sortmode[0] or defaultsort 69 sortmode = sortmode and sortmode[0] or defaultsort
42 70
43 # not implemented: filemap, revmapfile 71 # not implemented: filemap, revmapfile
44 revmapfile = destc.revmapfile() 72 revmapfile = destc.revmapfile()
45 c = convcmd.converter(ui, srcc, destc, revmapfile, opts) 73 c = convcmd.converter(ui, srcc, destc, revmapfile, opts)
46 c.convert(sortmode) 74 c.convert(sortmode)
47
48 # XXX sort options copied straight from hgext/convert/__init__.py
49 cmdtable = {
50 "fastimport":
51 (fastimport,
52 [('', 'branchsort', None, _('try to sort changesets by branches')),
53 ('', 'datesort', None, _('try to sort changesets by date')),
54 ('', 'sourcesort', None, _('preserve source changesets order')),
55 ],
56 'hg fastimport SOURCE ...')
57 }