blob: c4f7fee9786abc4ae4514ae6497633648506c680 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/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 <lekensteyn@gmail.com>
# 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;
}
# match only git's "commit" label, not something from the commit message.
$0 ~ /^commit/ &&
$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");
printf("\n");
}
|