From e4c16ff97afe69adec52cbbf4b4d66455d4a3371 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 11 Feb 2013 16:15:25 +0100 Subject: [PATCH] tig.pl: Add, tig-like log view. Used when tig is not available or broken. Also add tig alias to gitconfig. --- gitconfig.m4 | 10 +++++--- setup.sh | 5 ++-- tig.pl | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100755 tig.pl diff --git a/gitconfig.m4 b/gitconfig.m4 index 008b7fd..263723c 100644 --- a/gitconfig.m4 +++ b/gitconfig.m4 @@ -1,6 +1,6 @@ # Global Git configuration file. -# Copyright (C) 2011-2012 Simon Ruderich +# Copyright (C) 2011-2013 Simon Ruderich # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -112,8 +112,12 @@ include(../lib.m4) ## Custom commands. # - # tig-like log view. - tig = log --pretty=oneline --graph --all --decorate --abbrev-commit + # tig-like log view. Similar to the following but with author/date + # information. --pretty=format is not used because it doesn't allow + # precise enough control over formats and colors. + # + # tig = log --pretty=oneline --graph --all --decorate --abbrev-commit + tig = ! TIG | less [diff] # Detect copies and renames. diff --git a/setup.sh b/setup.sh index 0ef9e6a..2747b92 100755 --- a/setup.sh +++ b/setup.sh @@ -2,7 +2,7 @@ # Setup script for VCS configuration files. -# Copyright (C) 2011-2012 Simon Ruderich +# Copyright (C) 2011-2013 Simon Ruderich # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,7 +30,8 @@ if installed git; then generate m4 gitconfig \ -DGITIGNORE=`pwd`/gitignore \ -DPATIENCE="$PATIENCE" \ - -DOS=`os` + -DOS=`os` \ + -DTIG="`pwd`/tig.pl" link gitconfig ~/.gitconfig fi diff --git a/tig.pl b/tig.pl new file mode 100755 index 0000000..615107a --- /dev/null +++ b/tig.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +# tig-like git log output. Used when tig is not available or broken. + +# Copyright (C) 2013 Simon Ruderich +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +use strict; +use warnings; + +use POSIX (); +use Term::ANSIColor qw(colored); + + +my $color_graph = 'yellow'; +my $color_hash = 'cyan'; +my $color_ref_sep = 'cyan'; +my $color_ref_head = 'cyan bold'; +my $color_ref_branch = 'green bold'; +my $color_ref_reference = 'red bold'; +my $color_author = 'magenta'; + + +my $format = '%h' . '%x00' # abbreviated commit hash + . '%at' . '%x00' # author date + . '%an' . '%x00' # author name + . '%s' . '%x00' # subject + . '%d'; # ref names +my $cmd = "git log --all --graph --format='$format'"; +open my $fh, '-|', $cmd or die $!; + +while (my $line = <$fh>) { + # History graph line. + if ($line =~ m{^([|/\\ ]+)$}) { + print colored($line, $color_graph); + next; + } + + # Commit line. + $line =~ /^([ *|]+) (.+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)$/ or die; + my $prefix = $1; + my $hash = colored($2, $color_hash); + my $date = POSIX::strftime('%Y-%m-%d', localtime($3)); + my $author = colored($4, $color_author); + my $message = $5; + my $refs = $6; + + # Color "graph". + $prefix =~ s/\|/colored($&, $color_graph)/ge; + + # Strip leading whitespace. + $refs =~ s/^\s+//; + + printf "%s %s %s %s %s %s\n", + $prefix, $hash, $date, $author, $message, $refs; +} + +close $fh or die $!; -- 2.45.2