my %opt;
GetOptions(\%opt, qw{
cancel|c
+ height|h=i
overlay|o
stack|s
-}) or exit 1;
+ width|w=i
+}) or do {
+ print STDERR <<END;
+usage: git-graph [options]
+ -c | --cancel +/- counts cancel out
+ -o | --overlay +/- counts are overlaid as # (default)
+ -s | --cancel +/- counts are stacked
+ --height [n] Set height of graph
+ -h [n] (height of terminal is default)
+ --width [n] Set horizontal scale
+ -w [n] (fit to width of terminal by default)
+END
+ exit 1;
+};
$opt{overlay} = 1 unless $opt{cancel} or $opt{stack};
my @terminal = GetTerminalSize;
my $width = $terminal[0] - 11;
-my $height = $terminal[1] - 2;
+my $height = $opt{height} // $terminal[1] - 2;
my %add;
my %del;
my $date;
-for (qx{git log --pretty=format:%ct --shortstat --since='$height days ago'}) {
+for (qx{git log --find-renames --shortstat --pretty=format:%ct --since='$height days ago'}) {
next if m{^\s*$};
if (m{^(\d{10})\n$}) {
$date = int ($1 / 86400);
$canmax = $can if $canmax < $can;
}
-my $max = $opt{cancel} ? $canmax :
+my $max = $opt{width} ? $opt{width} :
+ $opt{cancel} ? $canmax :
$opt{stack} ? $addmax + $delmax :
$addmax > $delmax ? $addmax : $delmax;
my $scale = $width / $max;
}
my $greg = strftime "%b %d %w", localtime $date * 86400;
$greg =~ s{(\d)$}{substr "sMTWTFs", $1, 1}e;
- printf "$greg \e[33m%s\e[32m%s\e[31m%s\e[0m\n",
+ my $line = sprintf "$greg \e[33m%s\e[32m%s\e[31m%s\e[0m\n",
"#" x ($mod && 1 + $mod * $scale),
"+" x ($add && 1 + $add * $scale),
"-" x ($del && 1 + $del * $scale);
+ if (length $line > $width + 30) {
+ $line = sprintf "## %d ##\e[32m++ %d ++\e[31m-- %d --\e[0m\n",
+ $mod, $add, $del;
+ $line = "$greg \e[33m" . "#"x($width + 16 - length $line) . $line;
+ }
+ print $line;
}
printf " \e[33m#\e[0m <- %-8.1f %s %8d ->\n",
1/$scale, " " x ($width - 25), $max;