aboutsummaryrefslogtreecommitdiff
path: root/rev-tree.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2005-04-15 08:39:57 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-15 08:39:57 -0700
commit27de946d0ee70fad497253bbaab76d2fa7b1c77c (patch)
tree53cbeeb5b30e9a9e0759fad94a9e2d24aaeff53d /rev-tree.c
parentaa1c48df8172f844455cc12f25aa49be8ffdd828 (diff)
downloadgit-27de946d0ee70fad497253bbaab76d2fa7b1c77c.tar.gz
git-27de946d0ee70fad497253bbaab76d2fa7b1c77c.tar.xz
[PATCH] Simplify date handling and make it more reliable
This make all dates be stores as seconds since UTC epoch, with the author's or committer's timezone as auxiliary data so that dates can be pretty-printed in the original timezone later if anyone cares. I left the date parsing in rev-tree.c for backward compatibility but it can be dropped when we change to base64 :) commit-tree now eats RFC2822 dates as AUTHOR_DATE because that's what you're going to want to feed it. Yes, glibc sucks and strptime is a pile of crap. We have to parse it ourselves.
Diffstat (limited to 'rev-tree.c')
-rw-r--r--rev-tree.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/rev-tree.c b/rev-tree.c
index d3fc93c61..33caac3d0 100644
--- a/rev-tree.c
+++ b/rev-tree.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE /* glibc2 needs this */
+#define _BSD_SOURCE /* for tm.tm_gmtoff */
#include <time.h>
#include <ctype.h>
@@ -21,6 +22,7 @@ static unsigned long parse_time(const char *buf)
char buffer[100];
struct tm tm;
const char *formats[] = {
+ "%s",
"%c",
"%a %b %d %T %y",
NULL
@@ -30,7 +32,7 @@ static unsigned long parse_time(const char *buf)
p = buffer;
while (isspace(c = *buf))
buf++;
- while ((c = *buf++) != '\n')
+ while ((c = *buf++) != '\n' && c)
*p++ = c;
*p++ = 0;
buf = buffer;
@@ -50,6 +52,8 @@ static unsigned long parse_time(const char *buf)
static unsigned long parse_commit_date(const char *buf)
{
+ unsigned long time;
+
if (memcmp(buf, "author", 6))
return 0;
while (*buf++ != '\n')
@@ -58,7 +62,11 @@ static unsigned long parse_commit_date(const char *buf)
return 0;
while (*buf++ != '>')
/* nada */;
- return parse_time(buf);
+
+ time = strtoul(buf, NULL, 10);
+ if (!time)
+ time = parse_time(buf);
+ return time;
}
static int parse_commit(unsigned char *sha1)