Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
18818:a0bff3d4f67b | 18819:05acdf8e1f23 |
---|---|
225 keyfn = lambda n: self.commitcache[n].sortkey | 225 keyfn = lambda n: self.commitcache[n].sortkey |
226 def picknext(nodes): | 226 def picknext(nodes): |
227 return sorted(nodes, key=keyfn)[0] | 227 return sorted(nodes, key=keyfn)[0] |
228 return picknext | 228 return picknext |
229 | 229 |
230 def makeclosesorter(): | |
231 """Close order sort.""" | |
232 keyfn = lambda n: ('close' not in self.commitcache[n].extra, | |
233 self.commitcache[n].sortkey) | |
234 def picknext(nodes): | |
235 return sorted(nodes, key=keyfn)[0] | |
236 return picknext | |
237 | |
230 def makedatesorter(): | 238 def makedatesorter(): |
231 """Sort revisions by date.""" | 239 """Sort revisions by date.""" |
232 dates = {} | 240 dates = {} |
233 def getdate(n): | 241 def getdate(n): |
234 if n not in dates: | 242 if n not in dates: |
244 picknext = makebranchsorter() | 252 picknext = makebranchsorter() |
245 elif sortmode == 'datesort': | 253 elif sortmode == 'datesort': |
246 picknext = makedatesorter() | 254 picknext = makedatesorter() |
247 elif sortmode == 'sourcesort': | 255 elif sortmode == 'sourcesort': |
248 picknext = makesourcesorter() | 256 picknext = makesourcesorter() |
257 elif sortmode == 'closesort': | |
258 picknext = makeclosesorter() | |
249 else: | 259 else: |
250 raise util.Abort(_('unknown sort mode: %s') % sortmode) | 260 raise util.Abort(_('unknown sort mode: %s') % sortmode) |
251 | 261 |
252 children, actives = mapchildren(parents) | 262 children, actives = mapchildren(parents) |
253 | 263 |
444 except Exception: | 454 except Exception: |
445 for path in destc.created: | 455 for path in destc.created: |
446 shutil.rmtree(path, True) | 456 shutil.rmtree(path, True) |
447 raise | 457 raise |
448 | 458 |
449 sortmodes = ('branchsort', 'datesort', 'sourcesort') | 459 sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort') |
450 sortmode = [m for m in sortmodes if opts.get(m)] | 460 sortmode = [m for m in sortmodes if opts.get(m)] |
451 if len(sortmode) > 1: | 461 if len(sortmode) > 1: |
452 raise util.Abort(_('more than one sort mode specified')) | 462 raise util.Abort(_('more than one sort mode specified')) |
453 sortmode = sortmode and sortmode[0] or defaultsort | 463 sortmode = sortmode and sortmode[0] or defaultsort |
454 if sortmode == 'sourcesort' and not srcc.hasnativeorder(): | 464 if sortmode == 'sourcesort' and not srcc.hasnativeorder(): |
455 raise util.Abort(_('--sourcesort is not supported by this data source')) | 465 raise util.Abort(_('--sourcesort is not supported by this data source')) |
466 if sortmode == 'closesort' and not srcc.hasnativeclose(): | |
467 raise util.Abort(_('--closesort is not supported by this data source')) | |
456 | 468 |
457 fmap = opts.get('filemap') | 469 fmap = opts.get('filemap') |
458 if fmap: | 470 if fmap: |
459 srcc = filemap.filemap_source(ui, srcc, fmap) | 471 srcc = filemap.filemap_source(ui, srcc, fmap) |
460 destc.setfilemapmode(True) | 472 destc.setfilemapmode(True) |