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