2

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

4

2 回答 2

5

您正在寻找此扩展程序

于 2010-01-22T03:28:43.237 回答
3

我为此编写了一个脚本(并将其命名为 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 > tree.png

于 2010-01-22T03:28:41.437 回答