How can I take the output of hg history
and convert it into a dot file?
views:
61answers:
2I should have asked this question on SD _before_ trying to hack my own script :)
Thr4wn
2010-01-22 03:30:14
@Thr4wn, completely unrelated, but I absolutely dig your avatar xP
Kornel Kisielewicz
2010-01-22 03:32:19
does the extension still work with current hg? (and if you want something very simple, you could use hg debugindexdot)
tonfa
2010-04-04 15:56:33
+1
A:
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
Thr4wn
2010-01-22 03:28:41