Skip to contentSkip to conversation

Pretty-print date in 'git log'

PATCH In review David Woodhouse 3 participants 3 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Pretty-print date in 'git log'

Add tool to render git's "<utcseconds> <zone>" into an RFC2822-compliant string, because I don't think date(1) can do it. Use same for 'git log' output.

Makefile +1 -1
@@ -14,7 +14,7 @@
 
 PROG=   update-cache show-diff init-db write-tree read-tree commit-tree \
 	cat-file fsck-cache checkout-cache diff-tree rev-tree show-files \
-	check-files ls-tree merge-base
+	check-files ls-tree merge-base show-date
 
 SCRIPT=	parent-id tree-id git gitXnormid.sh gitadd.sh gitaddremote.sh \
 	gitcommit.sh gitdiff-do gitdiff.sh gitlog.sh gitls.sh gitlsobj.sh \
gitlog.sh +18 -1
@@ -13,6 +13,23 @@
 
 rev-tree $base | sort -rn | while read time commit parents; do
 	echo commit ${commit%:*};
-	cat-file commit $commit
+	cat-file commit $commit | while read type rest ; do
+		case "$type" in
+		    "author"|"committer")
+		        DATESTAMP="`echo $rest | cut -f2 -d\>`"
+			RFC2822DATE="`show-date $DATESTAMP 2>/dev/null || echo $DATESTAMP`"
+			echo $type $rest | sed "s/$DATESTAMP\$/ $RFC2822DATE/"
+			;;
+
+		    "")
+			echo ""
+			cat
+			;;
+		    *)
+			echo $type $rest
+			;;
+		esac
+	    done
+		    
 	echo -e "\n--------------------------"
 done
show-date.c renamed from show-date.c.orig +48 -0

48 lines not on this page · raw message

Signature · 1 line
dwmw2
#1 lore raw
Quoted 2 lines · David Woodhouse

Add tool to render git's "<utcseconds> <zone>" into an RFC2822-compliant string, because I don't think date(1) can do it.

I admit it's not obvious, but date(1) includes gnu's full date parser, so you can pull stunts like:

ray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds'
Fri Mar 18 01:58:31 UTC 2005
ray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds + 0800'
Fri Mar 18 09:58:31 UTC 2005

Ray

#2 lore raw
Quoted 4 lines
ray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds'
Fri Mar 18 01:58:31 UTC 2005
ray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds + 0800'
Fri Mar 18 09:58:31 UTC 2005

I sent David a short script to do almost that, except that mine needed to negate the timezone whereas yours elegantly changes +0800 to + 0800

In your 2nd example, you'll need 'sed' to replace UTC (or +0000 if using -R) in the output by +0800, because the 1111111111 is the UTC seconds, so the actual time is Fri Mar 18 01:58:31 UTC 2005 (as given by your first example).

-Sanjoy