Mercurial 将“hg history”的输出转换为点文件

Mercurial 将“hg history”的输出转换为点文件,mercurial,scripting,graphviz,dot,Mercurial,Scripting,Graphviz,Dot,如何将hg history的输出转换为文件?您正在寻找的文件。我编写了一个脚本来实现这一点(并将其命名为hghistory2dot.pl)。请参见代码下面的用法: #!/usr/bin/perl print "digraph {\n"; $first = 1; $cset = (); sub printedge { my $one = csetstr(shift(@_)); my $two = csetstr(shift(@_)); print $one, " ->

如何将
hg history
的输出转换为文件?

您正在寻找的文件。

我编写了一个脚本来实现这一点(并将其命名为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";
#/usr/bin/perl
打印“有向图{\n”;
$first=1;
$cset=();
子打印边缘{
我的$1=csetstr(shift(@));
我的$2=csetstr(shift(@));
打印$1、“->”和$2、;\n”;
}
亚csetstr{
my$csetid=班次(@41;;
$csetid=~s/\s/;
$csetid=~s/\\n/;
返回“cset”..$csetid;
}
而($line=){
如果(!($line eq“\n”)){
$line=~s/\n/\\n/;
推送(@cset,$line);
}
否则{
打印csetstr($current),“[shape=记录标签=\”,@cset,“\”];\n”;
@cset=();
}
如果($line=~m/^changeset/){
@arr=拆分(/:/,美元行);
$arr[2]=~s/\s/;
如果(!$parent_找到&&!$first){
#以前的变更集没有定义的父项;因此此变更集是隐含的父项。
printedge($current$arr[2]);
}
$current=$arr[2];
$parent\u found=0;
$first=0;
}
elsif($line=~m/^parent/){
$parent_found=1;
@arr=拆分(/:/,美元行);
$arr[2]=~s/\s/;
printedge($current$arr[2]);
}
}
打印“}\n”;

hg history | hghistory2dot.pl | dot-Tpng>tree.png

在尝试破解我自己的脚本之前,我应该在SD上问这个问题:)@Thr4wn,完全不相关,但我绝对喜欢你的化身xp。该扩展是否仍然适用于当前的hg?(如果您想要非常简单的东西,可以使用hg debugindexdot)