代码之家  ›  专栏  ›  技术社区  ›  Alexander Bird

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

  •  2
  • Alexander Bird  · 技术社区  · 15 年前

    我怎样才能获得的输出 hg history dot 文件

    2 回复  |  直到 14 年前
        1
  •  5
  •   Kornel Kisielewicz    15 年前

    你在找什么 this extension .

        2
  •  3
  •   Alexander Bird    15 年前

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