Skip to content

Commit

Permalink
Merge 8f09300 into 83e3d41
Browse files Browse the repository at this point in the history
  • Loading branch information
tueda committed Jun 4, 2024
2 parents 83e3d41 + 8f09300 commit 5179bd5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scripts/git-version-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ Options:
-s, --shell shell script output
-v, --only-version only-version output
-o <file>, --output <file> output to <file>
--date-format <format> date format (default: '%b %e %Y')
--date-format <format> date format (default: '%b %e %Y' as __DATE__)
--date-locale <locale> date locale (default: C)
--date-timezone <timezone> date timezone (default: GMT0)
END
}

# Format the date given in the form of '%Y-%m-%d %H:%M:%S %z'.
# fmt_isodate <isodate> <format>
fmt_isodate() {
# dash (0.5.5.1) needs the following exports.
export LANG
export LC_ALL
export TZ
# BSD date
date -j -f '%Y-%m-%d %H:%M:%S %z' "$1" +"$2" 2>/dev/null ||
Expand All @@ -56,6 +58,8 @@ refdir=$rootdir
mode=raw
output_file=
date_format='%b %e %Y'
date_locale=C
date_timezone=GMT0 # for better compatibility than UTC0

next=
for a in "$@"; do
Expand Down Expand Up @@ -93,6 +97,12 @@ for a in "$@"; do
--date-format)
next=date_format
;;
--date-locale)
next=date_locale
;;
--date-timezone)
next=date_timezone
;;
*)
echo "$prog: error: unknown option $a" >&2
exit 1
Expand Down Expand Up @@ -140,12 +150,12 @@ if [ "$mode" != "only-version" ]; then
if git_C diff-index --quiet HEAD .; then
# If the working tree is not dirty, use the latest commit date.
isodate=$(git_C log -1 --pretty=%ci .)
date=$(LANG=C TZ=UTC fmt_isodate "$isodate" "$date_format")
date=$(LC_ALL="$date_locale" TZ="$date_timezone" fmt_isodate "$isodate" "$date_format")
else
# If the working tree is dirty, suffix "-dirty" to the revision identifier
# and use the current date time.
revision="$revision-dirty"
date=$(LANG=C TZ=UTC date +"$date_format")
date=$(LC_ALL="$date_locale" TZ="$date_timezone" date +"$date_format")
fi
# Version description.
# Examples: "4.3.0", "v4.3.0-1-g7c9706c"
Expand Down

0 comments on commit 5179bd5

Please sign in to comment.