Mercurial > hg > hg-fastimport
comparison hgfastimport/__init__.py @ 74:a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
This change the minimum Mercurial supported version 4.1
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 18 Jan 2021 18:04:38 +0000 |
| parents | a99e5c6c8e1c |
| children |
comparison
equal
deleted
inserted
replaced
| 73:a99e5c6c8e1c | 74:a4f13dc5e3f7 |
|---|---|
| 1 ''' import Git fast-import streams ''' | 1 ''' import Git fast-import streams ''' |
| 2 from __future__ import absolute_import | 2 from __future__ import absolute_import |
| 3 | 3 |
| 4 from mercurial import ( | 4 from mercurial import ( |
| 5 cmdutil, | 5 commands, |
| 6 encoding, | 6 encoding, |
| 7 util, | 7 error, |
| 8 pycompat, | |
| 8 ) | 9 ) |
| 9 | 10 |
| 10 from mercurial.i18n import _ | 11 from mercurial.i18n import _ |
| 11 | 12 |
| 12 from hgext.convert import ( | 13 from hgext.convert import ( |
| 14 hg, | 15 hg, |
| 15 ) | 16 ) |
| 16 | 17 |
| 17 from .hgimport import fastimport_source | 18 from .hgimport import fastimport_source |
| 18 | 19 |
| 20 testedwith = b'5.6.1' | |
| 21 minimumhgversion = b'4.1' | |
| 22 | |
| 19 cmdtable = {} | 23 cmdtable = {} |
| 20 try: | 24 try: |
| 21 from mercurial import registrar | 25 from mercurial import registrar |
| 22 command = registrar.command(cmdtable) | 26 command = registrar.command(cmdtable) |
| 23 except (ImportError, AttributeError): | 27 except (ImportError, AttributeError): |
| 28 from mercurial import cmdutil | |
| 24 command = cmdutil.command(cmdtable) | 29 command = cmdutil.command(cmdtable) |
| 25 | 30 |
| 26 testedwith = '4.7' | 31 @command(b'fastimport', |
| 27 | 32 [(b'', b'branchsort', None, _(b'try to sort changesets by branches')), |
| 28 @command("fastimport", | 33 (b'', b'datesort', None, _(b'try to sort changesets by date')), |
| 29 [('', 'branchsort', None, _('try to sort changesets by branches')), | 34 (b'', b'sourcesort', None, _(b'preserve source changesets order'))], |
| 30 ('', 'datesort', None, _('try to sort changesets by date')), | 35 _(b'hg fastimport SOURCE ...'), |
| 31 ('', 'sourcesort', None, _('preserve source changesets order'))], | 36 norepo=False) |
| 32 _('hg fastimport SOURCE ...'), | |
| 33 norepo=False) | |
| 34 | 37 |
| 35 def fastimport(ui, repo, *sources, **opts): | 38 def fastimport(ui, repo, *sources, **opts): |
| 36 """Convert a git fastimport dump into Mercurial changesets. | 39 '''Convert a git fastimport dump into Mercurial changesets. |
| 37 | 40 |
| 38 Reads a series of SOURCE fastimport dumps and adds the resulting | 41 Reads a series of SOURCE fastimport dumps and adds the resulting |
| 39 changes to the current Mercurial repository. | 42 changes to the current Mercurial repository. |
| 40 """ | 43 ''' |
| 41 # Would be nice to just call hgext.convert.convcmd.convert() and let | 44 # Would be nice to just call hgext.convert.convcmd.convert() and let |
| 42 # it take care of things. But syntax and semantics are just a | 45 # it take care of things. But syntax and semantics are just a |
| 43 # little mismatched: | 46 # little mismatched: |
| 44 # - fastimport takes multiple source paths (mainly because cvs2git | 47 # - fastimport takes multiple source paths (mainly because cvs2git |
| 45 # produces 2 dump files) | 48 # produces 2 dump files) |
| 47 # | 50 # |
| 48 # So for the time being, I have copied bits of convert() over here. | 51 # So for the time being, I have copied bits of convert() over here. |
| 49 # Boo, hiss. | 52 # Boo, hiss. |
| 50 | 53 |
| 51 if not sources: | 54 if not sources: |
| 52 sources = ("-") | 55 sources = (b'-') |
| 53 | 56 |
| 54 # assume fastimport metadata (usernames, commit messages) are | 57 # assume fastimport metadata (usernames, commit messages) are |
| 55 # encoded UTF-8 | 58 # encoded UTF-8 |
| 56 convcmd.orig_encoding = encoding.encoding | 59 convcmd.orig_encoding = encoding.encoding |
| 57 encoding.encoding = 'UTF-8' | 60 encoding.encoding = b'UTF-8' |
| 58 | 61 |
| 59 # sink is the current repo, src is the list of fastimport streams | 62 # sink is the current repo, src is the list of fastimport streams |
| 60 destc = hg.mercurial_sink(ui, 'hg', repo.root) | 63 destc = hg.mercurial_sink(ui, b'hg', repo.root) |
| 61 srcc = fastimport_source(ui, 'fastimport', repo, sources) | 64 srcc = fastimport_source(ui, b'fastimport', repo, sources) |
| 62 | 65 |
| 63 # XXX figuring out sortmode copied straight from hgext/convert/convcmd.py | 66 opts = pycompat.byteskwargs(opts) |
| 64 defaultsort = 'branchsort' # for efficiency and consistency | 67 defaultsort = b'branchsort' # for efficiency and consistency |
| 65 sortmodes = ('branchsort', 'datesort', 'sourcesort') | 68 sortmodes = (b'branchsort', b'datesort', b'sourcesort') |
| 66 sortmode = [m for m in sortmodes if opts.get(m)] | 69 sortmode = [m for m in sortmodes if opts.get(m)] |
| 67 if len(sortmode) > 1: | 70 if len(sortmode) > 1: |
| 68 raise util.Abort(_('more than one sort mode specified')) | 71 raise error.Abort(_(b'more than one sort mode specified')) |
| 69 sortmode = sortmode and sortmode[0] or defaultsort | 72 if sortmode: |
| 73 sortmode = sortmode[0] | |
| 74 else: | |
| 75 sortmode = defaultsort | |
| 70 | 76 |
| 71 # not implemented: filemap, revmapfile | 77 # not implemented: filemap, revmapfile |
| 72 revmapfile = destc.revmapfile() | 78 revmapfile = destc.revmapfile() |
| 73 c = convcmd.converter(ui, srcc, destc, revmapfile, opts) | 79 c = convcmd.converter(ui, srcc, destc, revmapfile, opts) |
| 74 c.convert(sortmode) | 80 c.convert(sortmode) |
