4 print STDERR
"Usage: $ARGV0 <revision range>\n";
8 open INPUT
, 'git rev-list --parents ' . join(' ', @ARGV) . '|';
13 sub add_parents
($$) {
16 foreach my $parent (split / /,$parents) {
17 if ($commits->{$parent} == undef) {
18 $commits->{$parent} = {
23 if ($commits->{$parent}->{y
} < $y) {
24 $commits->{$parent}->{y
} = $y++;
26 $y = $commits->{$parent}->{y
} + 1;
32 # expects output of `rev-list --parents --topo-order`
35 if (/^([0-9a-f]{40}) ?(.*)$/) {
38 if ($commits->{$sha1} == undef) {
44 $commits->{$sha1}->{index} = $#list;
46 $commits->{$sha1}->{parents
} = $parents;
47 $list[$i] = $commits->{$sha1};
48 $commits->{$sha1}->{index} = $i++;
49 add_parents
($parents, $commits->{$sha1}->{y
});
55 print STDERR
"Cannot draw more than 26 revs.";
61 for ($i = 0; $i <= $#list; $i++) {
62 $list[$i]->{x
} = $#list - $i;
63 $list[$i]->{label
} = chr(0x41 + $list[$i]->{x
});
64 if ($height < $list[$i]->{y
}) {
65 $height = $list[$i]->{y
};
70 $width = $#list * 2 + 1;
71 $height = $height * 2 + 1;
73 for ($i = 0; $i < $height; $i++) {
74 $canvas[$i] = ' ' x
$width . "\n";
81 $canvas[$y] = substr($canvas[$y], 0, $x) . $c .
82 substr($canvas[$y], $x + 1);
88 return substr($canvas[$y], $x, 1);
93 return $info->{label
} . ": " . $info->{x
} . ", " . $info->{y
};
99 my $x1 = $commit1->{x
};
100 my $y1 = $commit1->{y
};
101 my $x2 = $commit2->{x
};
102 my $y2 = $commit2->{y
};
104 for (my $i = $x1 * 2 - 1; $i > $x2 * 2; $i--) {
105 set_cell
($i, $y1 * 2, "-");
109 my $factor = ($y2 - $y1) / ($x1 - $x2);
111 if ($x1 - $x2 == $y2 - $y1) {
113 for ($i = $x1 * 2 - 1; $i > $x2 * 2; $i -= 2) {
114 my $y = $y1 * 2 + ($x1 * 2 - $i) * $factor;
115 my $c = get_cell
($i, int($y));
116 if ($c ne ' ' && $c ne '-') {
122 for ($i = $x1 * 2 - 1; $i > $x2 * 2; $i--) {
123 my $y = $y1 * 2 + ($x1 * 2 - $i) * $factor;
124 my $c = (get_cell
($i, int($y)) ne ' ') ?
126 set_cell
($i, int($y), $c);
129 set_cell
($x1 * 2 - 1, $y1 * 2 + 1, '\'');
130 for ($i = $x1 * 2 - 2; $i > $x2 * 2 + 1; $i--) {
131 set_cell
($i, $y1 * 2 + 1, '-');
133 set_cell
($x2 * 2 + 1, $y1 * 2 + 1, ',');
134 for ($i = $y1 * 2 + 2; $i < $y2 * 2; $i++) {
135 my $c = (get_cell
($x2 * 2, $i) ne ' ') ?
137 set_cell
($x2 * 2, $i, $c);
144 for ($i = 0; $i <= $#list; $i++) {
148 set_cell
($x, $y, $info->{label
});
149 foreach my $parent (split / /,$info->{parents
}) {
150 if ($commits->{$parent}->{index} != undef) {
151 draw_line
($info, $commits->{$parent});