Mercurial > hg
diff hgext/convert/convcmd.py @ 18819:05acdf8e1f23
convert: add closesort algorithm to mercurial sources
If you actively work with branches, sometimes you need to close old branches
which last commited hundreds revisions ago. After close you will see long
lines in graph visually spoiling history. This sort only moves closed
revisions as close as possible to parents and does not increase storage size
as datesort do.
author | Constantine Linnick <theaspect@gmail.com> |
---|---|
date | Sun, 24 Mar 2013 00:06:52 +0700 |
parents | 13d73bf6be29 |
children | 61f1223ab358 |
line wrap: on
line diff
--- a/hgext/convert/convcmd.py Sun Mar 24 16:43:25 2013 -0700 +++ b/hgext/convert/convcmd.py Sun Mar 24 00:06:52 2013 +0700 @@ -227,6 +227,14 @@ return sorted(nodes, key=keyfn)[0] return picknext + def makeclosesorter(): + """Close order sort.""" + keyfn = lambda n: ('close' not in self.commitcache[n].extra, + self.commitcache[n].sortkey) + def picknext(nodes): + return sorted(nodes, key=keyfn)[0] + return picknext + def makedatesorter(): """Sort revisions by date.""" dates = {} @@ -246,6 +254,8 @@ picknext = makedatesorter() elif sortmode == 'sourcesort': picknext = makesourcesorter() + elif sortmode == 'closesort': + picknext = makeclosesorter() else: raise util.Abort(_('unknown sort mode: %s') % sortmode) @@ -446,13 +456,15 @@ shutil.rmtree(path, True) raise - sortmodes = ('branchsort', 'datesort', 'sourcesort') + sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort') 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 defaultsort if sortmode == 'sourcesort' and not srcc.hasnativeorder(): raise util.Abort(_('--sourcesort is not supported by this data source')) + if sortmode == 'closesort' and not srcc.hasnativeclose(): + raise util.Abort(_('--closesort is not supported by this data source')) fmap = opts.get('filemap') if fmap: