diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py --- a/hgext/convert/__init__.py +++ b/hgext/convert/__init__.py @@ -247,7 +247,8 @@ cmdtable = { ('s', 'source-type', '', _('source repository type')), ('', 'splicemap', '', _('splice synthesized history into place')), ('', 'branchmap', '', _('change branch names while converting')), - ('', 'datesort', None, _('try to sort changesets by date'))], + ('', 'datesort', None, _('try to sort changesets by date')), + ('', 'sourcesort', None, _('preserve source changesets order'))], _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')), "debugsvnlog": (debugsvnlog, diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -38,7 +38,7 @@ SKIPREV = 'SKIP' class commit(object): def __init__(self, author, date, desc, parents, branch=None, rev=None, - extra={}): + extra={}, sortkey=None): self.author = author or 'unknown' self.date = date or '0 0' self.desc = desc @@ -46,6 +46,7 @@ class commit(object): self.branch = branch self.rev = rev self.extra = extra + self.sortkey = sortkey class converter_source(object): """Conversion source interface""" diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py --- a/hgext/convert/convcmd.py +++ b/hgext/convert/convcmd.py @@ -169,6 +169,13 @@ class converter(object): return next return picknext + def makesourcesorter(): + """Source specific sort.""" + keyfn = lambda n: self.commitcache[n].sortkey + def picknext(nodes): + return sorted(nodes, key=keyfn)[0] + return picknext + def makedatesorter(): """Sort revisions by date.""" dates = {} @@ -186,6 +193,8 @@ class converter(object): picknext = makebranchsorter() elif sortmode == 'datesort': picknext = makedatesorter() + elif sortmode == 'sourcesort': + picknext = makesourcesorter() else: raise util.Abort(_('unknown sort mode: %s') % sortmode) @@ -362,9 +371,11 @@ def convert(ui, src, dest=None, revmapfi shutil.rmtree(path, True) raise - sortmode = 'branchsort' - if opts.get('datesort'): - sortmode = 'datesort' + sortmodes = ('datesort', 'sourcesort') + sortmode = [m for m in sortmodes if opts.get(m)] + if len(sortmode) > 1: + raise util.Abort(_('more than one sort mode specified')) + sortmode = sortmode and sortmode[0] or 'branchsort' fmap = opts.get('filemap') if fmap: diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py --- a/hgext/convert/hg.py +++ b/hgext/convert/hg.py @@ -302,7 +302,8 @@ class mercurial_source(converter_source) crev = None return commit(author=ctx.user(), date=util.datestr(ctx.date()), desc=ctx.description(), rev=crev, parents=parents, - branch=ctx.branch(), extra=ctx.extra()) + branch=ctx.branch(), extra=ctx.extra(), + sortkey=ctx.rev()) def gettags(self): tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] diff --git a/tests/test-convert-datesort b/tests/test-convert-datesort --- a/tests/test-convert-datesort +++ b/tests/test-convert-datesort @@ -20,10 +20,10 @@ hg ci -m a3 -d '4 0' hg up -C 0 hg branch branchb echo b >> b -hg ci -Am b0 -d '5 0' +hg ci -Am b0 -d '6 0' hg up -C brancha echo a >> a -hg ci -m a4 -d '6 0' +hg ci -m a4 -d '5 0' echo a >> a hg ci -m a5 -d '7 0' echo a >> a @@ -34,7 +34,12 @@ hg ci -m b1 -d '9 0' cd .. echo % convert with datesort -hg convert --datesort t t2 +hg convert --datesort t t-datesort echo % graph converted repo -hg -R t2 glog --template '{rev} "{desc}"\n' +hg -R t-datesort glog --template '{rev} "{desc}"\n' +echo % convert with datesort +hg convert --sourcesort t t-sourcesort +echo % graph converted repo +hg -R t-sourcesort glog --template '{rev} "{desc}"\n' + diff --git a/tests/test-convert-datesort.out b/tests/test-convert-datesort.out --- a/tests/test-convert-datesort.out +++ b/tests/test-convert-datesort.out @@ -7,7 +7,40 @@ created new head 1 files updated, 0 files merged, 1 files removed, 0 files unresolved 2 files updated, 0 files merged, 0 files removed, 0 files unresolved % convert with datesort -initializing destination t2 repository +initializing destination t-datesort repository +scanning source... +sorting... +converting... +8 a0 +7 a1 +6 a2 +5 a3 +4 a4 +3 b0 +2 a5 +1 a6 +0 b1 +% graph converted repo +o 8 "b1" +| +| o 7 "a6" +| | +| o 6 "a5" +| | +o | 5 "b0" +| | +| o 4 "a4" +| | +| o 3 "a3" +| | +| o 2 "a2" +| | +| o 1 "a1" +|/ +o 0 "a0" + +% convert with datesort +initializing destination t-sourcesort repository scanning source... sorting... converting... diff --git a/tests/test-convert.out b/tests/test-convert.out --- a/tests/test-convert.out +++ b/tests/test-convert.out @@ -210,6 +210,7 @@ options: --splicemap splice synthesized history into place --branchmap change branch names while converting --datesort try to sort changesets by date + --sourcesort preserve source changesets order use "hg -v help convert" to show global options adding a