diff options
author | Akira Yokosawa <akiyks@gmail.com> | 2023-02-04 00:23:25 +0900 |
---|---|---|
committer | Paul E. McKenney <paulmck@kernel.org> | 2023-02-03 09:52:17 -0800 |
commit | 35a7791778053a0bdb1c3b0bccae61eaadf43603 (patch) | |
tree | 8fe26dc2328302fc60a8ed934c663b207bff0326 /utilities | |
parent | 1c1affe8377e9f59a47fc1f39ab16b4a92d85963 (diff) | |
download | perfbook-35a7791778053a0bdb1c3b0bccae61eaadf43603.tar.gz |
autodate.sh: Add graceful fallback of commitid-only mode for shallow clone
Under shallow clone of perfbook repo, "git describe" can't work.
Catch the error and use "git log" to obtain the commit id instead.
Following is the comparison of autodate.tex.
Before:
\date{February 3, 2023 \\ Tag: \texttt{} }
\newcommand{\commityear}{2023}
\newcommand{\commitid}{}
\IfQqzBg{}{\setboolean{qqzbg}{false}}
% tcolorbox version: 5.1
\tcbsetforeverylayer{autoparskip}
After:
\date{February 3, 2023 \\ Commit: \texttt{g25bd138c30bf} (shallow clone) }
\newcommand{\commityear}{2023}
\newcommand{\commitid}{g25bd138c30bf}
\IfQqzBg{}{\setboolean{qqzbg}{false}}
% tcolorbox version: 5.1
\tcbsetforeverylayer{autoparskip}
Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
Tested-by: Leonardo Bras <leobras.c@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'utilities')
-rw-r--r-- | utilities/autodate.sh | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/utilities/autodate.sh b/utilities/autodate.sh index e33c254d..6d10b5d7 100644 --- a/utilities/autodate.sh +++ b/utilities/autodate.sh @@ -52,27 +52,28 @@ else else modified="" fi - description="`git describe --tags HEAD`" - case "$description" in - *-g*) - release=`env printf 'Commit: \\\texttt{%s}' "$description"` - commitid="$description" - ;; - v*) - release="Release $description" - commitid=$description - qqzbg="true" - ;; - Edition*) - release="Edition" - commitid=$description - qqzbg="true" + if description="`git describe --tags HEAD 2> /dev/null`" + then case "$description" in - *P*) - release="Print $release" + *-g*) + release=`env printf 'Commit: \\\texttt{%s}' "$description"` + commitid="$description" ;; - esac - case "$description" in + v*) + release="Release $description" + commitid=$description + qqzbg="true" + ;; + Edition*) + release="Edition" + commitid=$description + qqzbg="true" + case "$description" in + *P*) + release="Print $release" + ;; + esac + case "$description" in Edition[.-][0-9]*) ednum="`echo $description | sed -e 's/^Edition[.-]\([0-9]*\).*$/\1/'`" release=`env printf '\\Ordinalstringnum{%s} %s' $ednum "$release"` @@ -85,11 +86,16 @@ else ;; esac ;; - *) - release=`env printf 'Tag: \\\texttt{%s}' "$description"` - commitid=`echo $description | sed -e 's/.*-\(g.*\)/\1/'` - ;; - esac + *) + release=`env printf 'Tag: \\\texttt{%s}' "$description"` + commitid=`echo $description | sed -e 's/.*-\(g.*\)/\1/'` + ;; + esac + else + description=`git log --max-count=1 | head -n 1 | sed -e 's/^commit \([0-9a-f]\{12\}\).*$/g\1/'` + release=`env printf 'Commit: \\\texttt{%s} (shallow clone)' "$description"` + commitid="$description" + fi fi month=`date --date="$date_str" +%B` year=`date --date="$date_str" +%Y` |