git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Petr Baudis <pasky@ucw.cz>
Cc: git@vger.kernel.org
Subject: [PATCH] Pretty-print date in 'git log'
Date: Mon, 18 Apr 2005 15:46:59 +1000	[thread overview]
Message-ID: <1113803220.11910.81.camel@localhost.localdomain> (raw)

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.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>

--- Makefile
+++ Makefile	2005-04-18 15:40:43.000000000 +1000
@@ -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
+++ gitlog.sh	2005-04-18 15:39:38.000000000 +1000
@@ -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.orig	2005-04-18 15:43:06.000000000 +1000
+++ show-date.c	2005-04-18 15:42:15.000000000 +1000
@@ -0,0 +1,48 @@
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "cache.h"
+
+static const char *month_names[] = {
+        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static const char *weekday_names[] = {
+        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+int main(int argc, char **argv)
+{
+	time_t t;
+	int offset;
+	char *p;
+	struct tm tm;
+
+	if (argc != 3)
+		usage("usage: show-date <seconds> <zone>");
+
+	t = strtol(argv[1], &p, 0);
+	if (*p || !t)
+		usage("usage: show-date <seconds> <zone>");
+
+	if (argv[2][0] != '-' && argv[2][0] != '+')
+		usage("usage: show-date <seconds> <zone>");
+
+	offset = strtol(argv[2]+1, &p, 10);
+	if (*p || p!= argv[2]+5)
+		usage("usage: show-date <seconds> <zone>");
+
+	if (argv[2][0] == '-')
+		offset = -offset;
+
+	offset = 60 * (offset % 100 + (offset / 100 * 60));
+
+	t += offset;
+	gmtime_r(&t, &tm);
+
+	printf("%s, %d %s %04d %02d:%02d:%02d %s\n",
+	       weekday_names[tm.tm_wday], tm.tm_mday, month_names[tm.tm_mon],
+	       tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, argv[2]);
+	return 0;
+}

-- 
dwmw2


             reply	other threads:[~2005-04-18  5:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18  5:46 David Woodhouse [this message]
2005-04-18 19:02 ` [PATCH] Pretty-print date in 'git log' Ray Lee
2005-04-18 19:57   ` Sanjoy Mahajan
     [not found] <E1DNPz9-0003lm-00@skye.ra.phy.cam.ac.uk>
     [not found] ` <1113808105.5286.1.camel@localhost.localdomain>
2005-04-18 10:27   ` Petr Baudis
2005-04-18 12:24     ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1113803220.11910.81.camel@localhost.localdomain \
    --to=dwmw2@infradead.org \
    --cc=git@vger.kernel.org \
    --cc=pasky@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).