From b696923617e79a6af0360805b993a20fec2f86dc Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 22 Nov 2013 19:44:08 +0100 Subject: git-log-describe: add git-describe output to git-log As of today (2013-11-22) there is still no support for adding an indication of tag to the output of git log. This script post-processes the output of `git log` and adds the output of `git describe --first-parent` to line following the commit ID. For a version suitable for `git log --oneline`, see [1]. [1]: http://stackoverflow.com/q/17379010/427545 --- git-log-describe.awk | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 git-log-describe.awk (limited to 'git-log-describe.awk') diff --git a/git-log-describe.awk b/git-log-describe.awk new file mode 100755 index 0000000..0ac233e --- /dev/null +++ b/git-log-describe.awk @@ -0,0 +1,34 @@ +#!/usr/bin/awk -f +# Adds a "git describe" (nearest tag) output for `git log` (with support for +# color escapes and --graph markers). --oneline is not supported. +# +# Copyright (c) 2013 Peter Wu +# Licensed under GPLv3 or any latter version + +function has_color(str) { + if (str ~ /\033/) return 1; + + return 0; +} + +{ print; } + +{ + is_color = has_color($0); + # strip color escapes for easier text matching + gsub(/\033\[[0-9]*m/, ""); + + text_len = length($0); + # remove --graph markers + sub(/^[*|][*|_/\\ ]*/, ""); + indent_len = length($0) - text_len; +} + +$1 == "commit" && $2 ~ /^[0-9a-f]{5,40}$/ { + hash = $2; + + printf("%" indent_len "sDescribe: ", ""); + if (is_color) printf("\033[96m"); # light cyan + system("git describe --first-parent " hash);# " |tr -d '\''\n'\''"); + if (is_color) printf("\033[m"); +} -- cgit v1.2.1