{"thread":{"id":"96","subject":"[PATCH] Pretty-print date in 'git log'","startedAt":"2005-04-18T05:46:59Z","lastAt":"2005-04-18T19:57:11Z","messageCount":3,"participants":["David Woodhouse","Ray Lee","Sanjoy Mahajan"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"629","messageId":"1113803220.11910.81.camel@localhost.localdomain","threadId":"96","inReplyTo":null,"subject":"[PATCH] Pretty-print date in 'git log'","fromName":"David Woodhouse","fromEmail":"dwmw2@infradead.org","sentAt":"2005-04-18T05:46:59Z","receivedAt":"2005-04-18T05:46:59Z","isPatch":true,"sender":{"key":"dwmw2@infradead.org","avatar":"https://gravatar.com/avatar/7afd4f07e0cf7d7e046ae2d23678296b37777c96488e6f3451e78a5514154ebd?d=mp&s=160"},"body":"Add tool to render git's \"<utcseconds> <zone>\" into an RFC2822-compliant\nstring, because I don't think date(1) can do it. Use same for 'git log'\noutput.\n\nSigned-off-by: David Woodhouse <dwmw2@infradead.org>\n\n--- Makefile\n+++ Makefile\t2005-04-18 15:40:43.000000000 +1000\n@@ -14,7 +14,7 @@\n \n PROG=   update-cache show-diff init-db write-tree read-tree commit-tree \\\n \tcat-file fsck-cache checkout-cache diff-tree rev-tree show-files \\\n-\tcheck-files ls-tree merge-base\n+\tcheck-files ls-tree merge-base show-date\n \n SCRIPT=\tparent-id tree-id git gitXnormid.sh gitadd.sh gitaddremote.sh \\\n \tgitcommit.sh gitdiff-do gitdiff.sh gitlog.sh gitls.sh gitlsobj.sh \\\n--- gitlog.sh\n+++ gitlog.sh\t2005-04-18 15:39:38.000000000 +1000\n@@ -13,6 +13,23 @@\n \n rev-tree $base | sort -rn | while read time commit parents; do\n \techo commit ${commit%:*};\n-\tcat-file commit $commit\n+\tcat-file commit $commit | while read type rest ; do\n+\t\tcase \"$type\" in\n+\t\t    \"author\"|\"committer\")\n+\t\t        DATESTAMP=\"`echo $rest | cut -f2 -d\\>`\"\n+\t\t\tRFC2822DATE=\"`show-date $DATESTAMP 2>/dev/null || echo $DATESTAMP`\"\n+\t\t\techo $type $rest | sed \"s/$DATESTAMP\\$/ $RFC2822DATE/\"\n+\t\t\t;;\n+\n+\t\t    \"\")\n+\t\t\techo \"\"\n+\t\t\tcat\n+\t\t\t;;\n+\t\t    *)\n+\t\t\techo $type $rest\n+\t\t\t;;\n+\t\tesac\n+\t    done\n+\t\t    \n \techo -e \"\\n--------------------------\"\n done\n--- show-date.c.orig\t2005-04-18 15:43:06.000000000 +1000\n+++ show-date.c\t2005-04-18 15:42:15.000000000 +1000\n@@ -0,0 +1,48 @@\n+#include <time.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include \"cache.h\"\n+\n+static const char *month_names[] = {\n+        \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\",\n+        \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"\n+};\n+\n+static const char *weekday_names[] = {\n+        \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"\n+};\n+\n+int main(int argc, char **argv)\n+{\n+\ttime_t t;\n+\tint offset;\n+\tchar *p;\n+\tstruct tm tm;\n+\n+\tif (argc != 3)\n+\t\tusage(\"usage: show-date <seconds> <zone>\");\n+\n+\tt = strtol(argv[1], &p, 0);\n+\tif (*p || !t)\n+\t\tusage(\"usage: show-date <seconds> <zone>\");\n+\n+\tif (argv[2][0] != '-' && argv[2][0] != '+')\n+\t\tusage(\"usage: show-date <seconds> <zone>\");\n+\n+\toffset = strtol(argv[2]+1, &p, 10);\n+\tif (*p || p!= argv[2]+5)\n+\t\tusage(\"usage: show-date <seconds> <zone>\");\n+\n+\tif (argv[2][0] == '-')\n+\t\toffset = -offset;\n+\n+\toffset = 60 * (offset % 100 + (offset / 100 * 60));\n+\n+\tt += offset;\n+\tgmtime_r(&t, &tm);\n+\n+\tprintf(\"%s, %d %s %04d %02d:%02d:%02d %s\\n\",\n+\t       weekday_names[tm.tm_wday], tm.tm_mday, month_names[tm.tm_mon],\n+\t       tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, argv[2]);\n+\treturn 0;\n+}\n\n-- \ndwmw2\n\n"},{"id":"680","messageId":"1113850922.23938.54.camel@orca.madrabbit.org","threadId":"96","inReplyTo":"1113803220.11910.81.camel@localhost.localdomain","subject":"Re: [PATCH] Pretty-print date in 'git log'","fromName":"Ray Lee","fromEmail":"ray-lk@madrabbit.org","sentAt":"2005-04-18T19:02:02Z","receivedAt":"2005-04-18T19:02:02Z","isPatch":true,"sender":{"key":"ray-lk@madrabbit.org","avatar":null},"body":"On Mon, 2005-04-18 at 15:46 +1000, David Woodhouse wrote:\n> Add tool to render git's \"<utcseconds> <zone>\" into an RFC2822-compliant\n> string, because I don't think date(1) can do it.\n\nI admit it's not obvious, but date(1) includes gnu's full date parser,\nso you can pull stunts like:\n\nray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds'\nFri Mar 18 01:58:31 UTC 2005\nray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds + 0800'\nFri Mar 18 09:58:31 UTC 2005\n\nRay\n\n\n"},{"id":"683","messageId":"E1DNcMp-0006sk-00@skye.ra.phy.cam.ac.uk","threadId":"96","inReplyTo":"1113850922.23938.54.camel@orca.madrabbit.org","subject":"Re: [PATCH] Pretty-print date in 'git log'","fromName":"Sanjoy Mahajan","fromEmail":"sanjoy@mrao.cam.ac.uk","sentAt":"2005-04-18T19:57:11Z","receivedAt":"2005-04-18T19:57:11Z","isPatch":true,"sender":{"key":"sanjoy@mrao.cam.ac.uk","avatar":null},"body":"> ray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds'\n> Fri Mar 18 01:58:31 UTC 2005\n> ray:~/work/home$ date -ud 'jan 1, 1970 + 1111111111 seconds + 0800'\n> Fri Mar 18 09:58:31 UTC 2005\n\nI sent David a short script to do almost that, except that mine needed\nto negate the timezone whereas yours elegantly changes +0800 to + 0800\n\nIn your 2nd example, you'll need 'sed' to replace UTC (or +0000 if\nusing -R) in the output by +0800, because the 1111111111 is the UTC\nseconds, so the actual time is Fri Mar 18 01:58:31 UTC 2005 (as given\nby your first example).\n\n-Sanjoy\n"}]}