From e39c1451a8d4428763d1d88ae6e4aae8555cc5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D1=80=D0=B0=D1=85=D0=B8=D1=9A=D0=B0=20=D0=A0?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=9B?= Date: Tue, 21 May 2024 20:22:19 +0000 Subject: [PATCH] lib/make{date,version}: Optimize date and version output --- lib/makedate | 16 ++++------------ lib/makeversion | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/makedate b/lib/makedate index 4231baa..6cc0fe2 100755 --- a/lib/makedate +++ b/lib/makedate @@ -1,26 +1,18 @@ #!/bin/sh -x # vim: set ft=bash: FALLBACKDATE=${FALLBACKDATE:-unknown} -case "$(uname -s)" in - *OpenBSD*) - DATEARGS='-j +%B,\ %d\ %Y' - ;; - *) - DATEARGS='+%B,\ %d\ %Y' - ;; -esac +LC_ALL=C +export LC_ALL if [ -d .got ] && command -v got >/dev/null 2>&1; then - got tag -l | + got log | awk ' /^date: / { sub(/^date: /,"",$0) - print strftime("%B %d, %Y") + print $2 " " $3 ", " $5 exit }' >date.new elif [ -d .git ] && command -v git >/dev/null 2>&1; then - LC_ALL=C - export LC_ALL user=$(unalias ls >/dev/null 2>&1 || true; \ command ls -ld . | awk '{print $3}') e_user=$(id -un) diff --git a/lib/makeversion b/lib/makeversion index abcfca5..ee14eda 100755 --- a/lib/makeversion +++ b/lib/makeversion @@ -3,13 +3,32 @@ FALLBACKVER=${FALLBACKVER:-unknown} if [ -d .got ] && command -v got >/dev/null 2>&1; then + lastcommit=$(got log | + awk '/^commit/ {print substr($2,1,9); exit}') got tag -l | - awk ' - /^tag/ { - sub(/^v/,"",$2) - print $2 - exit - }' >version.new + awk -v lastcommit="$lastcommit" ' + /^object: commit/ { + if (!lasttagcom) + { + lasttagcom = substr($3,1,9) + } + next + } + /^tag/ { + if (!ver) + { + sub(/^v/,"",$2) + ver = $2 + } + next + } + END { + printf "%s", ver + if (lastcommit != lasttagcom) + { + printf "-g%s", lastcommit + } + }' >version.new elif [ -d .git ] && command -v git >/dev/null 2>&1; then LC_ALL=C export LC_ALL -- 2.45.2