# HG changeset patch # User Daniel Johnson # Date 1534074875 14400 # Node ID a99e5c6c8e1cc60e5150366ef870f4e12184cb05 # Parent 6b716ecb1cf3b6e6525c2fa4f47c22a090b52f5a 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 diff -r 6b716ecb1cf3 -r a99e5c6c8e1c hgfastimport/__init__.py --- a/hgfastimport/__init__.py Fri Dec 13 22:38:47 2013 -0500 +++ b/hgfastimport/__init__.py Sun Aug 12 07:54:35 2018 -0400 @@ -1,8 +1,36 @@ -from mercurial import encoding +''' import Git fast-import streams ''' +from __future__ import absolute_import + +from mercurial import ( + cmdutil, + encoding, + util, +) + from mercurial.i18n import _ -from hgext.convert import convcmd, hg + +from hgext.convert import ( + convcmd, + hg, +) + +from .hgimport import fastimport_source -from hgimport import fastimport_source +cmdtable = {} +try: + from mercurial import registrar + command = registrar.command(cmdtable) +except (ImportError, AttributeError): + command = cmdutil.command(cmdtable) + +testedwith = '4.7' + +@command("fastimport", + [('', 'branchsort', None, _('try to sort changesets by branches')), + ('', 'datesort', None, _('try to sort changesets by date')), + ('', 'sourcesort', None, _('preserve source changesets order'))], + _('hg fastimport SOURCE ...'), + norepo=False) def fastimport(ui, repo, *sources, **opts): """Convert a git fastimport dump into Mercurial changesets. @@ -29,8 +57,8 @@ encoding.encoding = 'UTF-8' # sink is the current repo, src is the list of fastimport streams - destc = hg.mercurial_sink(ui, repo.root) - srcc = fastimport_source(ui, repo, sources) + destc = hg.mercurial_sink(ui, 'hg', repo.root) + srcc = fastimport_source(ui, 'fastimport', repo, sources) # XXX figuring out sortmode copied straight from hgext/convert/convcmd.py defaultsort = 'branchsort' # for efficiency and consistency @@ -39,19 +67,8 @@ if len(sortmode) > 1: raise util.Abort(_('more than one sort mode specified')) sortmode = sortmode and sortmode[0] or defaultsort - + # not implemented: filemap, revmapfile revmapfile = destc.revmapfile() c = convcmd.converter(ui, srcc, destc, revmapfile, opts) c.convert(sortmode) - -# XXX sort options copied straight from hgext/convert/__init__.py -cmdtable = { - "fastimport": - (fastimport, - [('', 'branchsort', None, _('try to sort changesets by branches')), - ('', 'datesort', None, _('try to sort changesets by date')), - ('', 'sourcesort', None, _('preserve source changesets order')), - ], - 'hg fastimport SOURCE ...') -} diff -r 6b716ecb1cf3 -r a99e5c6c8e1c hgfastimport/hgimport.py --- a/hgfastimport/hgimport.py Fri Dec 13 22:38:47 2013 -0500 +++ b/hgfastimport/hgimport.py Sun Aug 12 07:54:35 2018 -0400 @@ -26,6 +26,8 @@ import sys from hgext.convert import common, hg as converthg +from mercurial import util +from mercurial.i18n import _ from fastimport import processor, parser @@ -34,11 +36,12 @@ """Interface between the fastimport processor below and Mercurial's normal conversion infrastructure. """ - def __init__(self, ui, repo, sources): + def __init__(self, ui, repotype, repo, sources): self.ui = ui self.sources = sources self.processor = HgImportProcessor(ui, repo) self.parsed = False + self.repotype = repotype # converter_source methods @@ -58,21 +61,26 @@ def getfile(self, name, fileid): if fileid is None: # deleted file - raise IOError + return None, None return (self.processor.getblob(fileid), self.processor.getmode(name, fileid)) - def getchanges(self, commitid): - """Returns a tuple of (files, copies). + def getchanges(self, commitid, full): + """Returns a tuple of (files, copies, cleanp2). files is a sorted list of (filename, id) tuples for all files changed between commitid and its first parent returned by - getcommit(). id is the source revision id of the file. + getcommit(). + commitid id is the source revision id of the file. + cleanp2 is currently unused and an empty set is returned. copies is a dictionary of dest: source """ + if full: + raise util.Abort(_("convert from fastimport does not support --full")) return (self.processor.modified[commitid], - self.processor.copies[commitid]) + self.processor.copies[commitid], + set()) def getcommit(self, commitid): """Return the commit object for commitid""" @@ -307,7 +315,8 @@ date = self.convert_date(userinfo) parents = filter(None, [first_parent, second_parent]) - commit = common.commit(user, date, text, parents, branch, rev=cmd.id) + commit = common.commit(user, date, text, parents, branch, + rev=cmd.id, sortkey=int(cmd.id[1:])) self.commitmap[cmd.id] = commit heads = self.branchmap.get(branch)