Mercurial > public > mercurial-scm > hg
comparison mercurial/debugcommands.py @ 30528:22683f2f8100
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 17 Aug 2016 21:00:11 -0700 |
parents | 243ecbd4f5c9 |
children | bd5c4320b5a8 |
comparison
equal
deleted
inserted
replaced
30527:243ecbd4f5c9 | 30528:22683f2f8100 |
---|---|
13 | 13 |
14 from .i18n import _ | 14 from .i18n import _ |
15 from .node import ( | 15 from .node import ( |
16 bin, | 16 bin, |
17 hex, | 17 hex, |
18 nullid, | |
18 short, | 19 short, |
19 ) | 20 ) |
20 from . import ( | 21 from . import ( |
21 bundle2, | 22 bundle2, |
22 changegroup, | 23 changegroup, |
675 ignorefile, lineno, line = ignoredata | 676 ignorefile, lineno, line = ignoredata |
676 ui.write(_("(ignore rule in %s, line %d: '%s')\n") | 677 ui.write(_("(ignore rule in %s, line %d: '%s')\n") |
677 % (ignorefile, lineno, line)) | 678 % (ignorefile, lineno, line)) |
678 else: | 679 else: |
679 ui.write(_("%s is not ignored\n") % f) | 680 ui.write(_("%s is not ignored\n") % f) |
681 | |
682 @command('debugindex', commands.debugrevlogopts + | |
683 [('f', 'format', 0, _('revlog format'), _('FORMAT'))], | |
684 _('[-f FORMAT] -c|-m|FILE'), | |
685 optionalrepo=True) | |
686 def debugindex(ui, repo, file_=None, **opts): | |
687 """dump the contents of an index file""" | |
688 r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) | |
689 format = opts.get('format', 0) | |
690 if format not in (0, 1): | |
691 raise error.Abort(_("unknown format %d") % format) | |
692 | |
693 generaldelta = r.version & revlog.REVLOGGENERALDELTA | |
694 if generaldelta: | |
695 basehdr = ' delta' | |
696 else: | |
697 basehdr = ' base' | |
698 | |
699 if ui.debugflag: | |
700 shortfn = hex | |
701 else: | |
702 shortfn = short | |
703 | |
704 # There might not be anything in r, so have a sane default | |
705 idlen = 12 | |
706 for i in r: | |
707 idlen = len(shortfn(r.node(i))) | |
708 break | |
709 | |
710 if format == 0: | |
711 ui.write((" rev offset length " + basehdr + " linkrev" | |
712 " %s %s p2\n") % ("nodeid".ljust(idlen), "p1".ljust(idlen))) | |
713 elif format == 1: | |
714 ui.write((" rev flag offset length" | |
715 " size " + basehdr + " link p1 p2" | |
716 " %s\n") % "nodeid".rjust(idlen)) | |
717 | |
718 for i in r: | |
719 node = r.node(i) | |
720 if generaldelta: | |
721 base = r.deltaparent(i) | |
722 else: | |
723 base = r.chainbase(i) | |
724 if format == 0: | |
725 try: | |
726 pp = r.parents(node) | |
727 except Exception: | |
728 pp = [nullid, nullid] | |
729 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
730 i, r.start(i), r.length(i), base, r.linkrev(i), | |
731 shortfn(node), shortfn(pp[0]), shortfn(pp[1]))) | |
732 elif format == 1: | |
733 pr = r.parentrevs(i) | |
734 ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( | |
735 i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), | |
736 base, r.linkrev(i), pr[0], pr[1], shortfn(node))) | |
737 | |
738 @command('debugindexdot', commands.debugrevlogopts, | |
739 _('-c|-m|FILE'), optionalrepo=True) | |
740 def debugindexdot(ui, repo, file_=None, **opts): | |
741 """dump an index DAG as a graphviz dot file""" | |
742 r = cmdutil.openrevlog(repo, 'debugindexdot', file_, opts) | |
743 ui.write(("digraph G {\n")) | |
744 for i in r: | |
745 node = r.node(i) | |
746 pp = r.parents(node) | |
747 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | |
748 if pp[1] != nullid: | |
749 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | |
750 ui.write("}\n") |