From 28b092d1e0b29e07f71f28bdb7bf7ffba465210c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 23 Nov 2013 00:32:17 +0100 Subject: git-log-describe: describe first tag following a commit Instead of showing where a commit was derived from, use `--contains` to show a description relative to a tag containing the commit. --- git-log-describe.awk | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/git-log-describe.awk b/git-log-describe.awk index 27063c4..c0ab37e 100755 --- a/git-log-describe.awk +++ b/git-log-describe.awk @@ -1,6 +1,8 @@ #!/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. +# Adds the first tag containing a commit for each git-log entry. +# `git log --color` and `git log --graph` are supported. --oneline is not +# supported (yet). +# If there is no tag after the commit, no description is shown. # # Optional variables: # -vcache={0|1} Enable a cache for git describe outputs. If set to 1, @@ -9,6 +11,10 @@ # be created if non-existent. Implies -vcache=1. # -vcache_ro={0|1} Set to 1 to prevent creating new files in cache. # +# NOTE: when cache is enabled, one must clear it when the `git describe` options +# are changed (see variable "opts" below) or when a new tag is added before an +# existing tag. +# # Copyright (c) 2013 Peter Wu # Licensed under GPLv3 or any latter version @@ -26,6 +32,9 @@ BEGIN { if (cache_ro && !is_dir(cache_dir) || !mkdir_p(cache_dir)) cache_dir = ""; } + + # Use `git-describe --contains` to show which tag contains this commit. + opts = "--contains"; } { print; } @@ -97,7 +106,7 @@ function git_describe(hash) { # cache entry was unavailable, get a description now. if (!desc) { - "git describe --first-parent " hash | getline desc; + "git describe " opts " " hash " 2>/dev/null" | getline desc; # write description to cache if allowed. if (cache_dir && desc && !cache_ro) { -- cgit v1.2.1