[flashrom] [PATCH] squash! BSD refinements.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Tue Sep 10 11:44:25 CEST 2013


Also, fix date handling in getrevision.sh to work with the various formats for
invoking 'date'. This also uses svn's info --xml output instead of the regular one.

Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---

Together with my previous patch I would also like to fix the getrevision
script as follows. The commit log and inline comments explain how precisely.


 util/getrevision.sh | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/util/getrevision.sh b/util/getrevision.sh
index c05f59e..5fd83f5 100755
--- a/util/getrevision.sh
+++ b/util/getrevision.sh
@@ -110,15 +110,31 @@ scm_url() {
 timestamp() {
 	local t
 
+	# date syntaxes are manifold:
+	# gnu		date [-d input]... [+FORMAT]
+	# netbsd	date [-ajnu] [-d date] [-r seconds] [+format] [[[[[[CC]yy]mm]dd]HH]MM[.SS]]
+	# freebsd	date [-jnu]  [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...]
+	# dragonflybsd	date [-jnu]  [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...]
+	# openbsd	date [-aju]  [-d dst] [-r seconds] [+format] [[[[[[cc]yy]mm]dd]HH]MM[.SS]] [...]
 	if svn_is_file_tracked "$2" ; then
 		if svn_has_local_changes "$2"; then
 			t=$(date -u "$1")
 		else
 			# No local changes, get date of the last log record.
-			local last_commit_date="$(svn info "$2" | \
-						  grep '^Last Changed Date:' | \
-						  awk '{print $4" "$5" "$6}')"
-			t=$(date -d "${last_commit_date}" -u "$1")
+			local last_commit_date="$(svn info --xml "$2"| \
+						  sed -n -e 's/<date>\(.*\)<\/date>/\1/p' -e 's/\..*Z/Z/p')"
+
+			case $(uname) in
+			# Most BSD dates do not support parsing date values from user input with -d but all of
+			# them support parsing the syntax with [[[[[[cc]yy]mm]dd]HH]MM[.ss]]. We have to
+			# transform the ISO8601 date first though.
+			NetBSD|OpenBSD|DragonFly|FreeBSD)
+				last_commit_date="$(echo ${last_commit_date} | \
+				   sed -n -e 's/\(....\)-\(..\)-\(..\)T\(..\):\(..\):\(..\)Z/\1\2\3\4\5\.\6/p')"
+				t=$(date -u -j "${last_commit_date}" "$1" 2>/dev/null);;
+			*)
+				t=$(date -u -d "${last_commit_date}" "$1" 2>/dev/null);;
+			esac
 		fi
 	elif git_is_file_tracked "$2" ; then
 		# are there local changes?
@@ -126,12 +142,22 @@ timestamp() {
 			t=$(date -u "${1}")
 		else
 			# No local changes, get date of the last commit
-			t=$(date -d "$(git log --pretty=format:"%cD" -1 -- "$2")" -u "$1")
+			case $(uname) in
+			# Most BSD dates do not support parsing date values from user input with -d but all of
+			# them support parsing epoch seconds with -r. Thanks to git we can easily use that:
+			NetBSD|OpenBSD|DragonFly|FreeBSD)
+				t=$(date -u -r "$(git log --pretty=format:%ct -1 -- $2)"  "$1" 2>/dev/null);;
+			*)
+				t=$(date -d "$(git log --pretty=format:%cD -1 -- $2)" -u "$1" 2>/dev/null);;
+			esac
 		fi
 	else
 		t=$(date -u "$1")
 	fi
 
+	if [ -z "$t" ]; then
+		echo "Warning: Could not determine timestamp." 2>/dev/null
+	fi
 	echo "${t}"
 }
 
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list