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

3 messages from 2005-06-09 to 2005-06-11. Participants: Dan Holmsand, Petr Baudis.
Thread: https://gitlist.dev/t/881

## Dan Holmsand, 2005-06-09 11:19

Subject: [PATCH 3/6] Make showdate use "Linus format"
Message-ID: <42A825C2.1060302@gmail.com>
URL: https://gitlist.dev/e/42A825C2.1060302%40gmail.com

```
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
 			;;

```

## Petr Baudis, 2005-06-10 22:59

Subject: Re: [PATCH 3/6] Make showdate use "Linus format"
Message-ID: <20050610225938.GE22111@pasky.ji.cz>
URL: https://gitlist.dev/e/20050610225938.GE22111%40pasky.ji.cz
In-Reply-To: <42A825C2.1060302@gmail.com>

```
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, 2005-06-11 08:28

Subject: Re: [PATCH 3/6] Make showdate use "Linus format"
Message-ID: <42AAA0C8.9020102@gmail.com>
URL: https://gitlist.dev/e/42AAA0C8.9020102%40gmail.com
In-Reply-To: <20050610225938.GE22111@pasky.ji.cz>

```
Petr Baudis wrote:
> 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.

>>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

```
