Mercurial > hg
comparison contrib/convert-repo @ 3957:2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 22 Dec 2006 17:59:40 -0600 |
parents | 558f52943cd2 |
children | 67982d3ee76c |
comparison
equal
deleted
inserted
replaced
3956:558f52943cd2 | 3957:2b87d3c5ab8e |
---|---|
432 except NoRepo: | 432 except NoRepo: |
433 pass | 433 pass |
434 abort("%s: unknown repository type\n" % path) | 434 abort("%s: unknown repository type\n" % path) |
435 | 435 |
436 class convert: | 436 class convert: |
437 def __init__(self, source, dest, mapfile): | 437 def __init__(self, source, dest, mapfile, opts): |
438 | 438 |
439 self.source = source | 439 self.source = source |
440 self.dest = dest | 440 self.dest = dest |
441 self.mapfile = mapfile | 441 self.mapfile = mapfile |
442 self.opts = opts | |
442 self.commitcache = {} | 443 self.commitcache = {} |
443 | 444 |
444 self.map = {} | 445 self.map = {} |
445 try: | 446 try: |
446 for l in file(self.mapfile): | 447 for l in file(self.mapfile): |
499 break | 500 break |
500 | 501 |
501 if not dep: | 502 if not dep: |
502 # all n's parents are in the list | 503 # all n's parents are in the list |
503 removed[n] = 1 | 504 removed[n] = 1 |
504 s.append(n) | 505 if n not in self.map: |
506 s.append(n) | |
505 if n in children: | 507 if n in children: |
506 for c in children[n]: | 508 for c in children[n]: |
507 visit.insert(0, c) | 509 visit.insert(0, c) |
510 | |
511 if opts.get('datesort'): | |
512 depth = {} | |
513 for n in s: | |
514 depth[n] = 0 | |
515 pl = [p for p in self.commitcache[n].parents if p not in self.map] | |
516 if pl: | |
517 depth[n] = max([depth[p] for p in pl]) + 1 | |
518 | |
519 s = [(depth[n], self.commitcache[n].date, n) for n in s] | |
520 s.sort() | |
521 s = [e[2] for e in s] | |
508 | 522 |
509 return s | 523 return s |
510 | 524 |
511 def copy(self, rev): | 525 def copy(self, rev): |
512 c = self.commitcache[rev] | 526 c = self.commitcache[rev] |
530 status("scanning source...\n") | 544 status("scanning source...\n") |
531 heads = self.source.getheads() | 545 heads = self.source.getheads() |
532 parents = self.walktree(heads) | 546 parents = self.walktree(heads) |
533 status("sorting...\n") | 547 status("sorting...\n") |
534 t = self.toposort(parents) | 548 t = self.toposort(parents) |
535 t = [n for n in t if n not in self.map] | |
536 num = len(t) | 549 num = len(t) |
537 c = None | 550 c = None |
538 | 551 |
539 status("converting...\n") | 552 status("converting...\n") |
540 for c in t: | 553 for c in t: |
578 try: | 591 try: |
579 mapfile = destc.mapfile() | 592 mapfile = destc.mapfile() |
580 except: | 593 except: |
581 mapfile = os.path.join(destc, "map") | 594 mapfile = os.path.join(destc, "map") |
582 | 595 |
583 c = convert(srcc, destc, mapfile) | 596 c = convert(srcc, destc, mapfile, opts) |
584 c.convert() | 597 c.convert() |
585 | 598 |
586 options = [('q', 'quiet', None, 'suppress output')] | 599 options = [('q', 'quiet', None, 'suppress output'), |
600 ('', 'datesort', None, 'try to sort changesets by date')] | |
587 opts = {} | 601 opts = {} |
588 args = fancyopts.fancyopts(sys.argv[1:], options, opts) | 602 args = fancyopts.fancyopts(sys.argv[1:], options, opts) |
589 | 603 |
590 if opts['quiet']: | 604 if opts['quiet']: |
591 quiet = 1 | 605 quiet = 1 |