3 # tig-like git log output. Used when tig is not available or broken.
5 # Copyright (C) 2013 Simon Ruderich
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 use Term::ANSIColor qw(colored);
28 my $color_graph = 'yellow';
29 my $color_hash = 'cyan';
30 my $color_ref_sep = 'cyan';
31 my $color_ref_head = 'cyan bold';
32 my $color_ref_branch = 'green bold';
33 my $color_ref_reference = 'red bold';
34 my $color_author = 'magenta';
37 my $format = '%x00' # separator from --graph
38 . '%h' . '%x00' # abbreviated commit hash
39 . '%at' . '%x00' # author date
40 . '%an' . '%x00' # author name
41 . '%s' . '%x00' # subject
43 my $cmd = "git log --all --graph --format='$format'";
44 open my $fh, '-|', $cmd or die $!;
46 while (my $line = <$fh>) {
48 if ($line =~ m{^([|/\\_ ]+)$}) {
49 print colored($line, $color_graph);
54 $line =~ /^([ *|]+)\x00(.+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)$/
57 my $hash = colored($2, $color_hash);
58 my $date = POSIX::strftime('%Y-%m-%d', localtime($3));
59 my $author = colored($4, $color_author);
63 # Strip trailing whitespace.
66 $prefix =~ s/\|/colored($&, $color_graph)/ge;
68 # Strip leading whitespace and braces.
73 $refs = join colored(', ', $color_ref_sep), map {
76 $color = $color_ref_head;
78 $color = $color_ref_reference;
80 $color = $color_ref_branch;
87 . colored('(', $color_ref_sep)
89 . colored(')', $color_ref_sep);
92 printf "%s %s %s %s%s %s\n",
93 $prefix, $hash, $date, $author, $refs, $message;