From 2240f1a381e3cfdcb6878dc94a4f8c263842c5fe Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Thu, 26 Jul 2012 12:10:58 +0100 Subject: logc script --- git-logc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 git-logc diff --git a/git-logc b/git-logc new file mode 100755 index 0000000..a38a827 --- /dev/null +++ b/git-logc @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.014; +use Term::ANSIColor ':constants'; + +my $tty=-t STDOUT; +$ENV{ANSI_COLORS_DISABLED}=1 unless $tty; + +sub parse_line { + my ($line) = @_; + + my ($graph,$hash,$decor,$date,$name,$subj) = split /\0/,$line; + return $graph unless defined $hash; + $decor =~ s{^\s+\(|\)$}{}g; + my @decors = split /, /,$decor; + return $graph,$hash,\@decors,$date,$name,$subj; +} + +sub class_decor { + my ($decor) = @_; + + my $colour=BRIGHT_BLUE; + if ($decor eq 'HEAD') { + $colour=BRIGHT_CYAN; + } + elsif ($decor =~ s{^refs/tags/}{tag: }) { + $colour=BRIGHT_YELLOW; + } + elsif ($decor =~ s{^refs/remotes/}{}) { + $colour=BRIGHT_RED; + } + elsif ($decor =~ s{^refs/heads/}{}) { + $colour=BRIGHT_GREEN; + } + return $colour,$decor; +} + +open my $fh,'-|','git','log',@ARGV,'--graph','--decorate=full','--pretty=format:%x00%h%x00%d%x00%ar%x00%aN%x00%s',($tty ? '--color=always' : ()); +my $out; +if ($tty) { + open $out,'|-','less'; + $SIG{PIPE}=sub{exit 0}; +} +else { + open $out,'>&',\*STDOUT; +} + +while (my $line = <$fh>) { + my ($graph,$hash,$decors,$date,$name,$subj) = parse_line($line); + if (not defined $hash) { + print $out $graph; + next; + } + + my $ret = $graph.YELLOW."$hash ".RESET; + + if (@$decors) { + $ret .= '('. join(', ',map { + my ($col,$str) = class_decor($_); + BOLD.$col.$str.RESET + } + @$decors).') ' + } + $ret .= RED."[$date]".RESET." ".GREEN."$name".RESET." $subj"; + print $out $ret; +} -- cgit v1.2.3