comparison hgext/convert/cvsps.py @ 7502:16905fc2690f

Add debugcvsps command, replacing cvsps script
author Frank Kingswood <frank@kingswood-consulting.co.uk>
date Wed, 10 Dec 2008 14:02:54 +0000
parents 810ca383da9c
children 8bea01a65391
comparison
equal deleted inserted replaced
7501:732c54abd592 7502:16905fc2690f
582 c.id = i + 1 582 c.id = i + 1
583 583
584 ui.status(_('%d changeset entries\n') % len(changesets)) 584 ui.status(_('%d changeset entries\n') % len(changesets))
585 585
586 return changesets 586 return changesets
587
588
589 def debugcvsps(ui, *args, **opts):
590 '''Read CVS rlog for current directory or named path in repository, and
591 convert the log to changesets based on matching commit log entries and dates.'''
592
593 if opts["new_cache"]:
594 cache = "write"
595 elif opts["update_cache"]:
596 cache = "update"
597 else:
598 cache = None
599
600 revisions = opts["revisions"]
601
602 try:
603 if args:
604 log = []
605 for d in args:
606 log += createlog(ui, d, root=opts["root"], cache=cache)
607 else:
608 log = createlog(ui, root=opts["root"], cache=cache)
609 except logerror, e:
610 ui.write("%r\n"%e)
611 return
612
613 changesets = createchangeset(ui, log, opts["fuzz"])
614 del log
615
616 # Print changesets (optionally filtered)
617
618 off = len(revisions)
619 branches = {} # latest version number in each branch
620 ancestors = {} # parent branch
621 for cs in changesets:
622
623 if opts["ancestors"]:
624 if cs.branch not in branches and cs.parents and cs.parents[0].id:
625 ancestors[cs.branch] = changesets[cs.parents[0].id-1].branch, cs.parents[0].id
626 branches[cs.branch] = cs.id
627
628 # limit by branches
629 if opts["branches"] and (cs.branch or 'HEAD') not in opts["branches"]:
630 continue
631
632 if not off:
633 # Note: trailing spaces on several lines here are needed to have
634 # bug-for-bug compatibility with cvsps.
635 ui.write('---------------------\n')
636 ui.write('PatchSet %d \n' % cs.id)
637 ui.write('Date: %s\n' % util.datestr(cs.date, '%Y/%m/%d %H:%M:%S %1%2'))
638 ui.write('Author: %s\n' % cs.author)
639 ui.write('Branch: %s\n' % (cs.branch or 'HEAD'))
640 ui.write('Tag%s: %s \n' % (['', 's'][len(cs.tags)>1],
641 ','.join(cs.tags) or '(none)'))
642 if opts["parents"] and cs.parents:
643 if len(cs.parents)>1:
644 ui.write('Parents: %s\n' % (','.join([str(p.id) for p in cs.parents])))
645 else:
646 ui.write('Parent: %d\n' % cs.parents[0].id)
647
648 if opts["ancestors"]:
649 b = cs.branch
650 r = []
651 while b:
652 b, c = ancestors[b]
653 r.append('%s:%d:%d' % (b or "HEAD", c, branches[b]))
654 if r:
655 ui.write('Ancestors: %s\n' % (','.join(r)))
656
657 ui.write('Log:\n')
658 ui.write('%s\n\n' % cs.comment)
659 ui.write('Members: \n')
660 for f in cs.entries:
661 fn = f.file
662 if fn.startswith(opts["prefix"]):
663 fn = fn[len(opts["prefix"]):]
664 ui.write('\t%s:%s->%s%s \n' % (fn, '.'.join([str(x) for x in f.parent]) or 'INITIAL',
665 '.'.join([str(x) for x in f.revision]), ['', '(DEAD)'][f.dead]))
666 ui.write('\n')
667
668 # have we seen the start tag?
669 if revisions and off:
670 if revisions[0] == str(cs.id) or \
671 revisions[0] in cs.tags:
672 off = False
673
674 # see if we reached the end tag
675 if len(revisions)>1 and not off:
676 if revisions[1] == str(cs.id) or \
677 revisions[1] in cs.tags:
678 break