Skip to contentSkip to conversation

Improve autodate.sh

PATCH In review Akira Yokosawa 2 participants 8 messages Dec 29, 2019 – Jan 2, 2020

lore
Share & tools
lore
#0 lore raw

cover Improve autodate.sh

This patch set was inspired by your change log of commit 686915e83f79 ("utilities/autodate: Convert current tag to release/edition text") saying:

This should really use a canned library to convert numerals to English-text ordinals, but none of the ones I found worked as advertised.

My guess is the ones you found are assuming bash and don't work with dash. You know, dash doesn't handle arrays.

Patch #1 is my answer and delegates the handling of ordinals to a LaTeX package "fmtcount".
Patch #2 is a minor update so that a repository with untracked files is treated as clean.
Patch #3 expands the use of tag info and displays it on every page at the bottom-right corner.

Thanks, Akira
--
Akira Yokosawa (3):
utilities/autodate: Use 'fmtcount' package for ordinals utilities/autodate: Ignore untracked files in 'git status' utilities/autodate: Put commit-id in footer by 'draftwatermark'

 FAQ-BUILD.txt         |  6 ++++--
 perfbook.tex          |  9 +++++++++
 utilities/autodate.sh | 35 ++++++++++++-----------------------
 3 files changed, 25 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 utilities/autodate: Use 'fmtcount' package for ordinals

From f688ea9f959e70e39315f0a48c843667e9e70561 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sun, 29 Dec 2019 17:49:26 +0900
Subject: [PATCH 1/3] utilities/autodate: Use 'fmtcount' package for ordinals

LaTeX package "fmtcount" provides a macro "\Ordinalstringnum{}", which does the conversion we need.

Also do some cosmetic tweaks:
- Use typewriter font for commit description and non-release tag.
- Move "(m)" indicating dirty git status to the end of release info.

---
 perfbook.tex          |  1 +
 utilities/autodate.sh | 27 +++++----------------------
 2 files changed, 6 insertions(+), 22 deletions(-)
perfbook.tex +1 -0
index 7dc8d95f..73b79205 100644
@@ -59,6 +59,7 @@
 \usepackage[hyphens]{url}
 \usepackage{threeparttable}
 \usepackage{titlesec}[2016/03/21] % Suppress number in paragraph heading
+\usepackage{fmtcount}
 \usepackage[bookmarks=true,bookmarksnumbered=true,pdfborder={0 0 0},linktoc=all]{hyperref}
 \usepackage{footnotebackref} % to enable cross-ref of footnote
 \usepackage[all]{hypcap} % for going to the top of figure and table
utilities/autodate.sh +5 -22
index 13d8bb5f..924fa6ee 100644
@@ -43,7 +43,7 @@ else
 	description="`git describe --tags HEAD`"
 	case "$description" in
 	*-g*)
-		release="Commit $description"
+		release=`env printf 'Commit: \\\texttt{%s}' "$description"`
 		;;
 	v*)
 		release="Release $description"
@@ -57,25 +57,8 @@ else
 		esac
 		case "$description" in
 		Edition[.-][0-9]*)
-			ednum="`echo $description | sed -e 's/^Edition[.-]\([1-9]*\).*$/\1/'`"
-			case "$ednum" in
-			1)
-				edord=First
-				;;
-			2)
-				edord=Second
-				;;
-			3)
-				edord=Third
-				;;
-			4)
-				edord=Fourth
-				;;
-			*)
-				edord=FixMe
-				;;
-			esac
-			release="$edord $release"
+			ednum="`echo $description | sed -e 's/^Edition[.-]\([0-9]*\).*$/\1/'`"
+			release=`env printf '\\Ordinalstringnum{%s} %s' $ednum "$release"`
 			;;
 		esac
 		case "$description" in
@@ -86,7 +69,7 @@ else
 		esac
 		;;
 	*)
-		release="Commit $description"
+		release=`env printf 'Tag: \\\texttt{%s}' "$description"`
 		;;
 	esac
 fi
@@ -98,5 +81,5 @@ then
 	release=`env printf '%s %s' '\\\\' "$release"`
 fi
 
-env printf '\\date{%s %s, %s %s %s}\n' $month $day $year $modified "$release"
+env printf '\\date{%s %s, %s %s %s}\n' $month $day $year "$release" $modified
 env printf '\\newcommand{\\commityear}{%s}\n' $year
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/3 utilities/autodate: Ignore untracked files in 'git status'

In reply to Akira Yokosawa

From c9778ef5caf2375ce7e0d02390c97efda9e6e603 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sun, 29 Dec 2019 17:51:13 +0900
Subject: [PATCH 2/3] utilities/autodate: Ignore untracked files in 'git status'

This is safe because untracked files won't have any effect in the resulting .pdf unless at least one of the tracked files is modified.

---
 utilities/autodate.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utilities/autodate.sh +1 -1
index 924fa6ee..2ebc0754 100644
@@ -33,7 +33,7 @@ then
 else
 	date_str=`git show --format="%cD" | head -1`
 	# check if git status is clean
-	gitstatus=`git status --porcelain | wc -l`
+	gitstatus=`git status -uno --porcelain | wc -l`
 	if [ $gitstatus != "0" ]
 	then
 		modified="(m)"
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/3 utilities/autodate: Put commit-id in footer by 'draftwatermark'

In reply to Akira Yokosawa

From 8575d3513dc813b9ede20a8aa4629826b8028343 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sun, 29 Dec 2019 17:51:53 +0900
Subject: [PATCH 3/3] utilities/autodate: Put commit-id in footer by 'draftwatermark'

A similar footer should be able to be typeset on every page by a LaTeX package "fancyhdr", but I have not figured out a way to do so reliably on Chapter pages.

A Release/Edition will have the release/edition tag name instead.

Also update FAQ-BUILD.txt to mention the possible version mismatch of draftwatermark.

---
 FAQ-BUILD.txt         | 6 ++++--
 perfbook.tex          | 8 ++++++++
 utilities/autodate.sh | 6 ++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
FAQ-BUILD.txt +4 -2
index 4fb85e7a..f5066798 100644
@@ -178,10 +178,11 @@
 			tlmgr install newtx
 
 10.	Building perfbook fails with a warning of buggy cleveref/listings
-	or version mismatch of titlesec. What can I do?
+	or version mismatch of titlesec/draftwatermark. What can I do?
 
 	A.	They are known issues on Ubuntu Xenial (titlesec),
-		Ubuntu Bionic (cleveref), and TeX Live 2014/2015 (listings).
+		Ubuntu Bionic (cleveref), TeX Live 2014/2015 (listings),
+		and TeX Live releases prior to 2015 (draftwatermark).
 		This answer assumes Ubuntu, but it should work on other
 		distros.
 
@@ -189,6 +190,7 @@
 		http://mirrors.ctan.org/macros/latex/contrib/titlesec.zip
 		http://mirrors.ctan.org/macros/latex/contrib/cleveref.zip
 		http://mirrors.ctan.org/macros/latex/contrib/listings.zip
+		http://mirrors.ctan.org/macros/latex/contrib/draftwatermark.zip
 
 	    2.	Install it by following instructions at:
 		https://help.ubuntu.com/community/LaTeX#Installing_packages_manually
perfbook.tex +8 -0
index 73b79205..0fae78fb 100644
@@ -60,6 +60,14 @@
 \usepackage{threeparttable}
 \usepackage{titlesec}[2016/03/21] % Suppress number in paragraph heading
 \usepackage{fmtcount}
+\usepackage{draftwatermark}[2015/02/19]
+\SetWatermarkAngle{0.0}
+\SetWatermarkFontSize{8pt}
+\SetWatermarkScale{1.0}
+\SetWatermarkLightness{.6}
+\SetWatermarkHorCenter{.85\paperwidth}
+\SetWatermarkVerCenter{.95\paperheight}
+\SetWatermarkText{\texttt{\commitid}}
 \usepackage[bookmarks=true,bookmarksnumbered=true,pdfborder={0 0 0},linktoc=all]{hyperref}
 \usepackage{footnotebackref} % to enable cross-ref of footnote
 \usepackage[all]{hypcap} % for going to the top of figure and table
utilities/autodate.sh +6 -0
index 2ebc0754..a954bbe7 100644
@@ -30,6 +30,7 @@ then
 	date_str=`date -R`
 	modified=""
 	release=""
+	commitid=""
 else
 	date_str=`git show --format="%cD" | head -1`
 	# check if git status is clean
@@ -44,12 +45,15 @@ else
 	case "$description" in
 	*-g*)
 		release=`env printf 'Commit: \\\texttt{%s}' "$description"`
+		commitid=`echo $description | sed -e 's/.*-\(g.*\)/\1/'`
 		;;
 	v*)
 		release="Release $description"
+		commitid=$description
 		;;
 	Edition*)
 		release="Edition"
+		commitid=$description
 		case "$description" in
 		*P*)
 			release="Print $release"
@@ -70,6 +74,7 @@ else
 		;;
 	*)
 		release=`env printf 'Tag: \\\texttt{%s}' "$description"`
+		commitid=`echo $description | sed -e 's/.*-\(g.*\)/\1/'`
 		;;
 	esac
 fi
@@ -83,3 +88,4 @@ fi
 
 env printf '\\date{%s %s, %s %s %s}\n' $month $day $year "$release" $modified
 env printf '\\newcommand{\\commityear}{%s}\n' $year
+env printf '\\newcommand{\\commitid}{%s}\n' $commitid$modified
Signature · 1 line
2.17.1
#4 lore raw
In reply to Akira Yokosawa
Quoted 9 lines · Akira Yokosawa

This patch set was inspired by your change log of commit 686915e83f79 ("utilities/autodate: Convert current tag to release/edition text") saying:

This should really use a canned library to convert numerals to English-text ordinals, but none of the ones I found worked as advertised.

My guess is the ones you found are assuming bash and don't work with dash. You know, dash doesn't handle arrays.

It was instead that my versions of python didn't know about the advertised library, possibly because I didn't know to tell them.

Quoted 2 lines

Patch #1 is my answer and delegates the handling of ordinals to a LaTeX package "fmtcount".

But I like your approach better in any case, thank you!!! ;-)

Quoted 2 lines

Patch #2 is a minor update so that a repository with untracked files is treated as clean.

My use case for wanting the current behavior is when I add a file, add references to it, but forget to do "git add". The "(m)" is a hint that I forgot something.

But what is the countervailing use case? Maybe there is a way to solve both problems.

Quoted 2 lines

Patch #3 expands the use of tag info and displays it on every page at the bottom-right corner.

Nice!

I took #1 and #3, and pushed another patch that includes the most recent tag for non-release builds. Let's talk about #2 -- perhaps I should take it as is, but that would require some other warning.

Thoughts?

Thanx, Paul

Quoted 15 lines

Thanks, Akira
--
Akira Yokosawa (3):
utilities/autodate: Use 'fmtcount' package for ordinals utilities/autodate: Ignore untracked files in 'git status' utilities/autodate: Put commit-id in footer by 'draftwatermark'

 FAQ-BUILD.txt         |  6 ++++--
 perfbook.tex          |  9 +++++++++
 utilities/autodate.sh | 35 ++++++++++++-----------------------
 3 files changed, 25 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.1
#5 lore raw
Quoted 5 lines · Paul E. McKenney
Quoted 4 lines · Akira Yokosawa

This patch set was inspired by your change log of commit 686915e83f79 ("utilities/autodate: Convert current tag to release/edition text") saying:

Quoted 8 lines
Quoted 5 lines

This should really use a canned library to convert numerals to English-text ordinals, but none of the ones I found worked as advertised.

My guess is the ones you found are assuming bash and don't work with dash. You know, dash doesn't handle arrays.

It was instead that my versions of python didn't know about the advertised library, possibly because I didn't know to tell them.

Hm, installing python (or python3 nowadays?) packages can be tricky. (system/user install, installing by pip/pip3 or apt ...)

Quoted 4 lines
Quoted 3 lines

Patch #1 is my answer and delegates the handling of ordinals to a LaTeX package "fmtcount".

Quoted 8 lines

But I like your approach better in any case, thank you!!! ;-)

Quoted 2 lines

Patch #2 is a minor update so that a repository with untracked files is treated as clean.

My use case for wanting the current behavior is when I add a file, add references to it, but forget to do "git add". The "(m)" is a hint that I forgot something.

Ah, current behavior does help such a situation!

Quoted 2 lines

But what is the countervailing use case?

Not much of a use case, but for example, random experimental outputs under CodeSamples/ not covered by .gitignore will generate the "(m)", which looks irrelevant.

But my view point was of receiving side of your updates. Now I know you've relied on the current behavior and changing it should be regarded as a regression.

Quoted 2 lines

Maybe there is a way to
solve both problems.

Let's keep the current behavior.

Quoted 8 lines
Quoted 3 lines

Patch #3 expands the use of tag info and displays it on every page at the bottom-right corner.

Nice!

I took #1 and #3, and pushed another patch that includes the most recent tag for non-release builds.

I thought full $description in non-release builds could be too long for the footer area, but the position of the watermark in the preamble specifies the center, and it looks reasonable. Thank you!

Quoted 4 lines

Let's talk about #2 -- perhaps
I should take it as is, but that would require some other warning.

Thoughts?

As mentioned above, I'm OK with keeping the current behavior. Adding some namespaces to .gitignore might be a better approach, but it is not urgent at all.

Thanks, Akira

Quoted 18 lines

Thanx, Paul

Quoted 15 lines

Thanks, Akira
--
Akira Yokosawa (3):
utilities/autodate: Use 'fmtcount' package for ordinals utilities/autodate: Ignore untracked files in 'git status' utilities/autodate: Put commit-id in footer by 'draftwatermark'

 FAQ-BUILD.txt         |  6 ++++--
 perfbook.tex          |  9 +++++++++
 utilities/autodate.sh | 35 ++++++++++++-----------------------
 3 files changed, 25 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.1
#6 lore raw
Quoted 9 lines · Akira Yokosawa
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · Akira Yokosawa

This patch set was inspired by your change log of commit 686915e83f79 ("utilities/autodate: Convert current tag to release/edition text") saying:

This should really use a canned library to convert numerals to English-text ordinals, but none of the ones I found worked as advertised.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

My guess is the ones you found are assuming bash and don't work with dash. You know, dash doesn't handle arrays.

It was instead that my versions of python didn't know about the advertised library, possibly because I didn't know to tell them.

Hm, installing python (or python3 nowadays?) packages can be tricky. (system/user install, installing by pip/pip3 or apt ...)

Ah, as the old saying goes, I have much to learn!

Quoted 12 lines
Quoted 11 lines
Quoted 2 lines

Patch #1 is my answer and delegates the handling of ordinals to a LaTeX package "fmtcount".

But I like your approach better in any case, thank you!!! ;-)

Quoted 2 lines

Patch #2 is a minor update so that a repository with untracked files is treated as clean.

My use case for wanting the current behavior is when I add a file, add references to it, but forget to do "git add". The "(m)" is a hint that I forgot something.

Quoted 7 lines

Ah, current behavior does help such a situation!

Quoted 1 line

But what is the countervailing use case?

Not much of a use case, but for example, random experimental outputs under CodeSamples/ not covered by .gitignore will generate the "(m)", which looks irrelevant.

I like your suggestion below of creating directories for experiemental not-to-be-committed results using .gitignore, and would of course welcome a patch.

Quoted 3 lines

But my view point was of receiving side of your updates. Now I know you've relied on the current behavior and changing it should be regarded as a regression.

OK, we should be good as-is, then.

Quoted 4 lines
Quoted 2 lines

Maybe there is a way to
solve both problems.

Let's keep the current behavior.

Sounds good!

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

Patch #3 expands the use of tag info and displays it on every page at the bottom-right corner.

Nice!

I took #1 and #3, and pushed another patch that includes the most recent tag for non-release builds.

I thought full $description in non-release builds could be too long for the footer area, but the position of the watermark in the preamble specifies the center, and it looks reasonable. Thank you!

Very good! And thank you for coming up with the footer trick, could save some confusion.

Quoted 8 lines
Quoted 4 lines

Let's talk about #2 -- perhaps
I should take it as is, but that would require some other warning.

Thoughts?

As mentioned above, I'm OK with keeping the current behavior. Adding some namespaces to .gitignore might be a better approach, but it is not urgent at all.

As noted earlier, this sounds good to me! One approach would be to add the experimental directory and a README within it, with the README describing the purpose. Then a .gitignore in that same directory could ignore all but the README. But maybe you have a better idea.

Thanx, Paul

Quoted 21 lines

Thanks, Akira

Quoted 18 lines

Thanx, Paul

Quoted 15 lines

Thanks, Akira
--
Akira Yokosawa (3):
utilities/autodate: Use 'fmtcount' package for ordinals utilities/autodate: Ignore untracked files in 'git status' utilities/autodate: Put commit-id in footer by 'draftwatermark'

 FAQ-BUILD.txt         |  6 ++++--
 perfbook.tex          |  9 +++++++++
 utilities/autodate.sh | 35 ++++++++++++-----------------------
 3 files changed, 25 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.1
#7 lore raw
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Akira Yokosawa

On Mon, 30 Dec 2019 16:06:27 -0800, Paul E. McKenney wrote:

[ . . . ]

Quoted 8 lines
Quoted 3 lines

As mentioned above, I'm OK with keeping the current behavior. Adding some namespaces to .gitignore might be a better approach, but it is not urgent at all.

As noted earlier, this sounds good to me! One approach would be to add the experimental directory and a README within it, with the README describing the purpose. Then a .gitignore in that same directory could ignore all but the README. But maybe you have a better idea.

Another possibility would be for your tests to direct output somewhere outside of the perfbook source tree, if that would work reasonably.

Thanx, Paul