【问题标题】:Converting output of `hg history` into a dot file将`hg history`的输出转换为点文件
【发布时间】:2011-01-08 01:19:01
【问题描述】:

如何获取hg history 的输出并将其转换为dot 文件?

【问题讨论】:

    标签: mercurial scripting graphviz dot


    【解决方案1】:

    您正在寻找this extension

    【讨论】:

    • 我应该在 SD 尝试破解我自己的脚本之前问这个问题 :)
    • @Thr4wn,完全不相关,但我绝对喜欢你的头像 xP
    • 扩展是否仍然适用于当前的 hg? (如果你想要一些非常简单的东西,你可以使用 hg debugindexdot)
    【解决方案2】:

    我为此编写了一个脚本(并将其命名为 hghistory2dot.pl)。在代码下方查看其用法:

    #!/usr/bin/perl
    print "digraph {\n";
    $first = 1;
    $cset = ();
    
    sub printedge {
        my $one = csetstr(shift(@_));
        my $two = csetstr(shift(@_));
        print $one, " -> ", $two, ";\n";
    }
    
    sub csetstr {
        my $csetid = shift(@_);
        $csetid =~ s/\s//;
        $csetid =~ s/\\n//;
        return "cset_" . $csetid;
    }
    
    while($line = <> ) {
        if (!($line eq "\n") ) {
        $line =~ s/\n/\\n/;
        push(@cset, $line);
        }
        else {
        print csetstr($current), " [shape=record label=\"", @cset, "\"];\n";
        @cset = ();
        }
    
        if( $line =~ m/^changeset/ ) {
        @arr = split(/:/, $line);
        $arr[2] =~ s/\s//;
    
        if( ! $parent_found && ! $first) {
            #previous changeset had no defined parent; therefore this one is the implied parent.
            printedge($current, $arr[2]);
        }
    
        $current = $arr[2];
    
        $parent_found = 0;
        $first = 0;
        }
        elsif($line =~ m/^parent/) {
        $parent_found = 1;
        @arr = split(/:/, $line);
        $arr[2] =~ s/\s//;
        printedge($current, $arr[2]);
        }
    }
    
    print "}\n";
    

    hg history | hghistory2dot.pl | dot -Tpng &gt; tree.png

    【讨论】:

      猜你喜欢
      • 2013-07-03
      • 2021-05-25
      • 2021-10-30
      • 2018-12-23
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      相关资源
      最近更新 更多