将 `hg History` 的输出转换为点文件

发布于 2024-08-18 13:38:45 字数 358 浏览 2 评论 0原文

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

How can I take the output of hg history and convert it into a dot file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十级心震 2024-08-25 13:38:45

您正在寻找此扩展程序

You are looking for this extension.

苦笑流年记忆 2024-08-25 13:38:45

我编写了一个脚本来执行此操作(并将其命名为 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 |点-Tpng>树.png

I wrote a script to do this (and called it hghistory2dot.pl). See its usage below the code:

#!/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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文