threads / patch / 881

patch, 6 partsMake showdate use "Linus format"

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

## tl;dr

3 messages between Jun 9, 2005 and Jun 11, 2005. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Dan Holmsand· Jun 9, 2005, 11:19 UTC · lore

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(-)
Show changes to 2 files +9 −11

cg-Xlib, cg-mkpatch

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
 			;;
Petr Baudis· Jun 10, 2005, 22:59 UTC · re: Dan Holmsand · lore

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

Thanks, applied.

Dear diary, on Thu, Jun 09, 2005 at 01:19:30PM CEST, I got a letter where Dan Holmsand <holmsand@gmail.com> told me that...

> This makes showdate use the same date format as
> git-rev-list --pretty, and gives some speedup. It might also
> be more portable.

I dropped the format change bit, because I really think the Linus' date format is bad. The current standardized, international and most widely used (even your mailer agent used it in your Date: header) date format is RFC 822, so please let's stick with it. It's perfect for our use, and better human-readable too. The date part isn't split all around but concentrated in the first half while the second half is dedicated to time.

> 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.
You forgot to modify cg-log accordingly. (I fixed that.)
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
<Espy> be careful, some twit might quote you out of context..
Dan Holmsand· Jun 11, 2005, 08:28 UTC · re: Petr Baudis · lore

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

Petr Baudis wrote:
Show 17 quoted lines
> Thanks, applied.
> 
> Dear diary, on Thu, Jun 09, 2005 at 01:19:30PM CEST, I got a letter
> where Dan Holmsand <holmsand@gmail.com> told me that...
> 
>>This makes showdate use the same date format as
>>git-rev-list --pretty, and gives some speedup. It might also
>>be more portable.
> 
> 
> I dropped the format change bit, because I really think the Linus' date
> format is bad. The current standardized, international and most widely
> used (even your mailer agent used it in your Date: header) date format
> is RFC 822, so please let's stick with it. It's perfect for our use, and
> better human-readable too. The date part isn't split all around but
> concentrated in the first half while the second half is dedicated to
> time.

Ok, I really have nothing against RFC822. But if Linus' format is bad, then git-rev-list --pretty should be fixed (or, rather, date.c). It doesn't make any sense to me to have different formats between cogito and core git.

And I'd really, really like to use as much of git-rev-list --pretty output as possible in cg-log. That makes the whole thing some orders of magnitude faster, and thus more usable.

Show 6 quoted lines
>>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.
> 
> 
> You forgot to modify cg-log accordingly. (I fixed that.)

Thanks. I did the "hope he takes my other patch too" thing... Sorry 'bout that.

/dan

← back to recent threads