summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d167f14)
raw | patch | inline | side by side (parent: d167f14)
author | Edgar Toernig <froese@gmx.de> | |
Sat, 30 Apr 2005 16:46:49 +0000 (09:46 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 30 Apr 2005 16:46:49 +0000 (09:46 -0700) |
...since everything out there is either strange (libc mktime has issues
with timezones) or introduces unnecessary dependencies for people (libcurl).
This goes back to the old date parsing, but moves it out into a file of
its own, and does the "struct tm" to "seconds since epoch" handling by
hand.
I grepped through the tz-database and it seems there's one "country"
left that has non-60-minute DST: Lord Howe Island. All others dropped
that before 1970.
with timezones) or introduces unnecessary dependencies for people (libcurl).
This goes back to the old date parsing, but moves it out into a file of
its own, and does the "struct tm" to "seconds since epoch" handling by
hand.
I grepped through the tz-database and it seems there's one "country"
left that has non-60-minute DST: Lord Howe Island. All others dropped
that before 1970.
Makefile | patch | blob | history | |
cache.h | patch | blob | history | |
commit-tree.c | patch | blob | history | |
date.c | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile b/Makefile
index ef9a9fae88a1ac438c22beb50790f0f0e37ffc3c..7b51773ab0fd94252e86a986eca52929d40b495b 100644 (file)
--- a/Makefile
+++ b/Makefile
install: $(PROG) $(SCRIPTS)
install $(PROG) $(SCRIPTS) $(HOME)/bin/
-LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o tag.o
+LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o \
+ tag.o date.o
LIB_FILE=libgit.a
LIB_H=cache.h object.h blob.h tree.h commit.h tag.h
git-tar-tree: tar-tree.c
git-http-pull: LIBS += -lcurl
-git-commit-tree: LIBS += -lcurl
# Library objects..
blob.o: $(LIB_H)
index aca98f3ec655e0b3530b0f84b5226a51879da95a..e27429eae979f207d3ccdf0c53fea424306ddeb6 100644 (file)
--- a/cache.h
+++ b/cache.h
unsigned long *size,
unsigned char *sha1_ret);
+void parse_date(char *date, char *buf, int bufsize);
+void datestamp(char *buf, int bufsize);
+
static inline void *xmalloc(int size)
{
void *ret = malloc(size);
diff --git a/commit-tree.c b/commit-tree.c
index 7c23b9b506bc50521a053d20e8960f857f1ae31a..0c568d0179e93bc202ac62c31fca7fe107b3ab1c 100644 (file)
--- a/commit-tree.c
+++ b/commit-tree.c
#include <string.h>
#include <ctype.h>
#include <time.h>
-#include <curl/curl.h>
#define BLOCKING (1ul << 14)
}
}
-/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
- (i.e. English) day/month names, and it doesn't work correctly with %z. */
-static void parse_date(char *date, time_t *now, char *result, int maxlen)
-{
- char *p;
- time_t then;
-
- if ((then = curl_getdate(date, now)) == 0)
- return;
-
- /* find the timezone at the end */
- p = date + strlen(date);
- while (p > date && isdigit(*--p))
- ;
- if ((*p == '+' || *p == '-') && strlen(p) == 5)
- snprintf(result, maxlen, "%lu %5.5s", then, p);
-}
-
static void check_valid(unsigned char *sha1, const char *expect)
{
void *buf;
char *audate;
char comment[1000];
struct passwd *pw;
- time_t now;
- struct tm *tm;
char *buffer;
unsigned int size;
strcat(realemail, ".");
getdomainname(realemail+strlen(realemail), sizeof(realemail)-strlen(realemail)-1);
}
- time(&now);
- tm = localtime(&now);
- strftime(realdate, sizeof(realdate), "%s %z", tm);
+ datestamp(realdate, sizeof(realdate));
strcpy(date, realdate);
commitgecos = getenv("COMMIT_AUTHOR_NAME") ? : realgecos;
email = getenv("AUTHOR_EMAIL") ? : realemail;
audate = getenv("AUTHOR_DATE");
if (audate)
- parse_date(audate, &now, date, sizeof(date));
+ parse_date(audate, date, sizeof(date));
remove_special(gecos); remove_special(realgecos); remove_special(commitgecos);
remove_special(email); remove_special(realemail); remove_special(commitemail);
diff --git a/date.c b/date.c
--- /dev/null
+++ b/date.c
@@ -0,0 +1,184 @@
+/*
+ * GIT - The information manager from hell
+ *
+ * Copyright (C) Linus Torvalds, 2005
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <time.h>
+
+static time_t my_mktime(struct tm *tm)
+{
+ static const int mdays[] = {
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+ };
+ int year = tm->tm_year - 70;
+ int month = tm->tm_mon;
+ int day = tm->tm_mday;
+
+ if (year < 0 || year > 129) /* algo only works for 1970-2099 */
+ return -1;
+ if (month < 0 || month > 11) /* array bounds */
+ return -1;
+ if (month < 2 || (year + 2) % 4)
+ day--;
+ return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL +
+ tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec;
+}
+
+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"
+};
+
+
+static char *skipfws(char *str)
+{
+ while (isspace(*str))
+ str++;
+ return str;
+}
+
+
+/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
+ (i.e. English) day/month names, and it doesn't work correctly with %z. */
+void parse_date(char *date, char *result, int maxlen)
+{
+ struct tm tm;
+ char *p, *tz;
+ int i, offset;
+ time_t then;
+
+ memset(&tm, 0, sizeof(tm));
+
+ /* Skip day-name */
+ p = skipfws(date);
+ if (!isdigit(*p)) {
+ for (i=0; i<7; i++) {
+ if (!strncmp(p,weekday_names[i],3) && p[3] == ',') {
+ p = skipfws(p+4);
+ goto day;
+ }
+ }
+ return;
+ }
+
+ /* day */
+ day:
+ tm.tm_mday = strtoul(p, &p, 10);
+
+ if (tm.tm_mday < 1 || tm.tm_mday > 31)
+ return;
+
+ if (!isspace(*p))
+ return;
+
+ p = skipfws(p);
+
+ /* month */
+
+ for (i=0; i<12; i++) {
+ if (!strncmp(p, month_names[i], 3) && isspace(p[3])) {
+ tm.tm_mon = i;
+ p = skipfws(p+strlen(month_names[i]));
+ goto year;
+ }
+ }
+ return; /* Error -- bad month */
+
+ /* year */
+ year:
+ tm.tm_year = strtoul(p, &p, 10);
+
+ if (!tm.tm_year && !isspace(*p))
+ return;
+
+ if (tm.tm_year > 1900)
+ tm.tm_year -= 1900;
+
+ p=skipfws(p);
+
+ /* hour */
+ if (!isdigit(*p))
+ return;
+ tm.tm_hour = strtoul(p, &p, 10);
+
+ if (tm.tm_hour > 23)
+ return;
+
+ if (*p != ':')
+ return; /* Error -- bad time */
+ p++;
+
+ /* minute */
+ if (!isdigit(*p))
+ return;
+ tm.tm_min = strtoul(p, &p, 10);
+
+ if (tm.tm_min > 59)
+ return;
+
+ if (*p != ':')
+ goto zone;
+ p++;
+
+ /* second */
+ if (!isdigit(*p))
+ return;
+ tm.tm_sec = strtoul(p, &p, 10);
+
+ if (tm.tm_sec > 60)
+ return;
+
+ zone:
+ if (!isspace(*p))
+ return;
+
+ p = skipfws(p);
+
+ if (*p == '-')
+ offset = -60;
+ else if (*p == '+')
+ offset = 60;
+ else
+ return;
+
+ if (!isdigit(p[1]) || !isdigit(p[2]) || !isdigit(p[3]) || !isdigit(p[4]))
+ return;
+
+ tz = p;
+ i = strtoul(p+1, NULL, 10);
+ offset *= ((i % 100) + ((i / 100) * 60));
+
+ p = skipfws(p + 5);
+ if (*p && *p != '(') /* trailing comment like (EDT) is ok */
+ return;
+
+ then = my_mktime(&tm); /* mktime uses local timezone */
+ if (then == -1)
+ return;
+
+ then -= offset;
+
+ snprintf(result, maxlen, "%lu %5.5s", then, tz);
+}
+
+void datestamp(char *buf, int bufsize)
+{
+ time_t now;
+ int offset;
+
+ time(&now);
+
+ offset = my_mktime(localtime(&now)) - now;
+ offset /= 60;
+
+ snprintf(buf, bufsize, "%lu %+05d", now, offset/60*100 + offset%60);
+}