From 341a558a78755437bc3cc8c512224419b4af9494 Mon Sep 17 00:00:00 2001
From: Mathieu Arnold <mat@FreeBSD.org>
Date: Tue, 14 Jun 2016 14:02:59 +0000
Subject: [PATCH] Fix using LATESTREVISION when not using svn (or svn is
 broken)

Kinda ok'ed by:	wblock
Sponsored by:	Absolight
---
 share/mk/doc.docbook.mk | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/share/mk/doc.docbook.mk b/share/mk/doc.docbook.mk
index 72d520dbc4..bbda71a8f1 100644
--- a/share/mk/doc.docbook.mk
+++ b/share/mk/doc.docbook.mk
@@ -87,12 +87,35 @@ NO_SUBDIR=      YES
 #
 # Determine latest revision
 #
+# This needs to contain all of:
+# --param latestrevision.timestamp "'timestamp'"
+# --param latestrevision.committer "'committer'"
+# --param latestrevision.number "'revision id'"
+
+# If using git, use git log.  The revision won't work with the generated links,
+# because it is a hash, and git log doesn't know about git svn find-rev.
+.if exists(${DOC_PREFIX}/.git)
+LATESTREVISION!=cd ${.CURDIR} && git log -1 \
+	--pretty=format:'--param latestrevision.timestamp "'\''%ci'\''" --param latestrevision.committer "'\''%cn'\''" --param latestrevision.number "'\''%h'\''"' \
+	${SRCS}
+.else
+# svn doesn't allow multiple files passed to it, so try to get the latest with grep
 LATESTREVISION!=${GREP} -Ehos '\$$[F]reeBSD: ([^\$$ ]+ ){5}\$$' ${SRCS} | \
 		${AWK} '{ print \
 		  " --param latestrevision.timestamp \"'\''"$$4" "$$5"'\''\"" \
 		  " --param latestrevision.committer \"'\''"$$6"'\''\"" \
 		  " --param latestrevision.number \"'\''"$$3"'\''\"" \
 		}' | ${SORT} | ${TAIL} -n1
+.endif
+
+# And sometime, strange things happen, so let's try to be a bit clever so that
+# we always have something to output, so use file on the file modified last,
+# and use its changed timestamp, user.  Leave the revision as blank.
+.if empty(LATESTREVISION)
+LATESTREVISION!=stat -t '%F %T %Z' \
+	-f '--param latestrevision.timestamp "'\''%Sc'\''" --param latestrevision.committer "'\''%Su'\''" --param latestrevision.number "'\'''\''"' \
+	$(ls -t1 ${SRCS}|head -1)
+.endif
 
 XSLTPROCOPTS+=	${LATESTREVISION}