[PATCH 3/6] Make showdate use "Linus format"

From: Dan Holmsand <holmsand@gmail.com>
Date: 2005-06-09 21:19:30
This makes showdate use the same date format as
git-rev-list --pretty, and gives some speedup. It might also
be more portable.

Note that this changes the calling convention: the previous
version used seconds from $1, but timezone from the global
variable $date. cg-mkpatch is modified to the new way.

Also fixes bash's belief that number literals starting with
zero are octal.

Signed-off-by: Dan Holmsand <holmsand@gmail.com>
---

 cg-Xlib    |   18 ++++++++----------
 cg-mkpatch |    2 +-
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -60,19 +60,17 @@ stat () {
 }
 
 showdate () {
-	date="$1"
-	format="$2"
-	[ "$format" ] || format=-R
-	sec=${date[0]}; tz=${date[1]}
+	local secs=$1 tzhours=${2:0:3} tzmins=${2:0:1}${2:3} format=$3
+	# bash doesn't like leading zeros
+	[ "${tzhours:1:1}" = 0 ] && tzhours=${2:0:1}${2:2:1}
+	secs=$((secs + tzhours * 3600 + tzmins * 60))
 	if [ "$has_gnudate" ]; then
-	        dtz=${tz/+/}
-		lsec=$(($dtz / 100 * 3600 + $dtz % 100 * 60 + $sec))
-	        pdate="$(date -ud "1970-01-01 UTC + $lsec sec" "$format" 2>/dev/null)"
+		[ "$format" ] || format="+%a %b %-d %H:%M:%S %Y $2"
+		LANG=C date -ud "1970-01-01 UTC + $secs sec" "$format"
 	else
-		# FIXME: $format
-	        pdate="$(date -u -r ${date[0]} 2>/dev/null)"
+		[ "$format" ] || format="+%a %b %d %H:%M:%S %Y $2"
+		date -u -r $secs "$format"
 	fi
-	echo "${pdate/+0000/$tz}"
 }
 
 # Usage: tree_timewarp [--no-head-update] DIRECTION_STR ROLLBACK_BOOL BASE BRANCH
diff --git a/cg-mkpatch b/cg-mkpatch
--- a/cg-mkpatch
+++ b/cg-mkpatch
@@ -52,7 +52,7 @@ showpatch () {
 		case "$key" in
 		"author"|"committer")
 			date=(${rest#*> })
-			pdate="$(showdate $date)"
+			pdate="$(showdate ${date[*]})"
 			[ "$pdate" ] && rest="${rest%> *}> $pdate"
 			echo $key $rest >>$header
 			;;


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Thu Jun 09 22:36:22 2005

This archive was generated by hypermail 2.1.8 : 2005-06-09 22:36:23 EST