git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Pretty-print date in 'git log'
@ 2005-04-18  5:46 David Woodhouse
  2005-04-18 19:02 ` Ray Lee
  0 siblings, 1 reply; 5+ messages in thread
From: David Woodhouse @ 2005-04-18  5:46 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Pretty-print date in 'git log'
       [not found] ` <1113808105.5286.1.camel@localhost.localdomain>
@ 2005-04-18 10:27   ` Petr Baudis
  2005-04-18 12:24     ` David Woodhouse
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Baudis @ 2005-04-18 10:27 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Sanjoy Mahajan, git

Dear diary, on Mon, Apr 18, 2005 at 09:08:24AM CEST, I got a letter
where David Woodhouse <dwmw2@infradead.org> told me that...
> On Mon, 2005-04-18 at 07:43 +0100, Sanjoy Mahajan wrote:
> > Is this short script good enough:
> 
> It's not far off; thanks. We might as well just do it like that inside
> gitlog.sh. Could do with falling back to just printing the input if it
> can't parse it -- the git repo has old-style dates in it still.

Yes. As far as I'm concerned, I'd put such stuff to git log, and extend
it usage so that it is possible to print individual log entries with it
- just make it accept a _range_ of commits, and then do

	git log $commit $commit

And maybe options for changelog-suitable output (RMK-like) etc.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Pretty-print date in 'git log'
  2005-04-18 10:27   ` [PATCH] Pretty-print date in 'git log' Petr Baudis
@ 2005-04-18 12:24     ` David Woodhouse
  0 siblings, 0 replies; 5+ messages in thread
From: David Woodhouse @ 2005-04-18 12:24 UTC (permalink / raw)
  To: Petr Baudis; +Cc: Sanjoy Mahajan, git

On Mon, 2005-04-18 at 12:27 +0200, Petr Baudis wrote:
> Yes. As far as I'm concerned, I'd put such stuff to git log, and extend
> it usage so that it is possible to print individual log entries with it
> - just make it accept a _range_ of commits, and then do
> 
>         git log $commit $commit

That's fairly trivial. In the current (and misguided) version with
chronological output, rev-tree will do it all for you, in fact:

	rev-tree $1 ^$2

In the older and more useful version, it was only slightly more complex:

 base=$(gitXnormid.sh -c $1) || exit 1
 
+if [ -n "$2" ]; then
+    endpoint=$(gitXnormid.sh -c $2) || exit 1
+    if rev-tree $base $endpoint | grep -q $base:3; then
+        base=
+    else
+        rev-tree --edges $base $endpoint | sed 's/[a-z0-9]*:1//g' > $TMPCL
+    fi
+fi
 changelog $base
 rm $TMPCL $TMPCM


-- 
dwmw2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Pretty-print date in 'git log'
  2005-04-18  5:46 David Woodhouse
@ 2005-04-18 19:02 ` Ray Lee
  2005-04-18 19:57   ` Sanjoy Mahajan
  0 siblings, 1 reply; 5+ messages in thread
From: Ray Lee @ 2005-04-18 19:02 UTC (permalink / raw)
  To: David Woodhouse; +Cc: git, Petr Baudis

On Mon, 2005-04-18 at 15:46 +1000, David Woodhouse wrote:
> 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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Pretty-print date in 'git log'
  2005-04-18 19:02 ` Ray Lee
@ 2005-04-18 19:57   ` Sanjoy Mahajan
  0 siblings, 0 replies; 5+ messages in thread
From: Sanjoy Mahajan @ 2005-04-18 19:57 UTC (permalink / raw)
  To: Ray Lee; +Cc: David Woodhouse, git, Petr Baudis

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-18 19:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <E1DNPz9-0003lm-00@skye.ra.phy.cam.ac.uk>
     [not found] ` <1113808105.5286.1.camel@localhost.localdomain>
2005-04-18 10:27   ` [PATCH] Pretty-print date in 'git log' Petr Baudis
2005-04-18 12:24     ` David Woodhouse
2005-04-18  5:46 David Woodhouse
2005-04-18 19:02 ` Ray Lee
2005-04-18 19:57   ` Sanjoy Mahajan

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