commit - 21679dc5afe28d00d3188bb529f3cefffdb06b64
commit + 939d3016601d8c21e69a605f10838024335f3b1a
blob - a346ab5981dac6f616103dfdb281f5c2785c60a2
blob + c23b8863b3184121b8c368dd247b965685f04711
--- gotd/gotd.conf.5
+++ gotd/gotd.conf.5
.Dv committer
but may be unset.
.It Dv date
-String representation of the date as
-.Xr strftime 3
-.Sq %G-%m-%d
-if
-.Dv short
-is set or
-.Sq %a %b %e %X %Y UTC
-otherwise.
+Number, representing the number of seconds since the Epoch in UTC.
.It Dv short_message
The first line of the commit message.
This field is always set.
.Dv commit
notification but with all the field guaranteed to be set.
.It Dv date
-The tag date.
+Number, representing the number of seconds since the Epoch in UTC.
.It Dv object
The object being tagged.
It contains the fields
blob - a0ff1393c1aa0d3ff4f44bd88d6ef8579db72717
blob + 16f1d741593d53dc9c972d53a4536edabae0301a
--- gotd/libexec/got-notify-email/got-notify-email.c
+++ gotd/libexec/got-notify-email/got-notify-email.c
#include <sys/types.h>
#include <sys/socket.h>
+#include <ctype.h>
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <stdint.h>
#include <syslog.h>
#include <getopt.h>
#include <err.h>
if (p)
*p = '\0';
return s;
+}
+
+static const struct got_error *
+print_date(int s, char *date, int shortfmt)
+{
+ const struct got_error *error;
+ struct tm tm;
+ char *t, datebuf[26];
+ const char *errstr;
+ time_t ts;
+
+ date[strcspn(date, " \n")] = '\0';
+
+ ts = strtonum(date, INT64_MIN, INT64_MAX, &errstr);
+ if (errstr)
+ return got_error_set_errno(EINVAL, errstr);
+ if (gmtime_r(&ts, &tm) == NULL)
+ return got_error_set_errno(EINVAL, "gmtime_r");
+
+ if (!shortfmt) {
+ t = asctime_r(&tm, datebuf);
+ if (t == NULL)
+ return got_error_set_errno(EINVAL, "invalid timestamp");
+ t[strcspn(t, "\n")] = '\0';
+ error = got_poll_write_full(s, t, strlen(t));
+ if (error)
+ return error;
+ return got_poll_write_full(s, " UTC\n", 5);
+ }
+
+ if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0)
+ return got_error_set_errno(EINVAL, "invalid timestamp");
+ return got_poll_write_full(s, datebuf, strlen(datebuf));
}
static void
size_t linesize = 0;
ssize_t linelen;
time_t now;
+ int firstline = 1, shortfmt = 0;
char datebuf[26];
char *datestr;
fatalx("could not send body delimiter");
while ((linelen = getline(&line, &linesize, stdin)) != -1) {
+ if (firstline && isdigit((unsigned char)line[0]))
+ shortfmt = 1;
+ firstline = 0;
+
if (line[0] == '.') { /* dot stuffing */
error = got_poll_write_full(s, ".", 1);
if (error)
fatalx("write: %s", error->msg);
}
+
+ if (shortfmt) {
+ char *t;
+ t = strchr(line, ' ');
+ if (t != NULL) {
+ *t++ = '\0';
+ error = print_date(s, line, shortfmt);
+ if (error)
+ fatalx("write: %s", error->msg);
+ error = got_poll_write_full(s, t, strlen(t));
+ continue;
+ }
+ }
+
+ if (!shortfmt && !strncmp(line, "date: ", 6)) {
+ error = got_poll_write_full(s, line, 6);
+ if (error)
+ fatalx("write: %s", error->msg);
+ error = print_date(s, line + 6, shortfmt);
+ if (error)
+ fatalx("write: %s", error->msg);
+ continue;
+ }
+
error = got_poll_write_full(s, line, linelen);
if (error)
fatalx("write: %s", error->msg);
blob - 60f89ca0e57362d2951dc69102b742825ac30059
blob + 86cd2a944e00cac2d2fdbe97332b4f1693761941
--- gotd/libexec/got-notify-http/got-notify-http.c
+++ gotd/libexec/got-notify-http/got-notify-http.c
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
#include "got_opentemp.h"
}
static void
+json_date(FILE *fp, const char *key, const char *date, int comma)
+{
+ fprintf(fp, "\"%s\":%s%s", key, date, comma ? "," : "");
+}
+
+static void
json_author(FILE *fp, const char *type, char *address, int comma)
{
char *gt, *lt, *at, *email, *endname;
json_field(fp, "repo", repo, 1);
json_field(fp, "id", id, 1);
json_author(fp, "committer", author, 1);
- json_field(fp, "date", date, 1);
+ json_date(fp, "date", date, 1);
json_field(fp, "short_message", message, 0);
fprintf(fp, "}");
/* optional */
if (!strncmp(l, "date: ", 6)) {
l += 6;
- json_field(fp, "date", l, 1);
+ json_date(fp, "date", l, 1);
phase = P_PARENT;
break;
}
/* optional */
if (!strncmp(l, "date: ", 6)) {
l += 6;
- json_field(fp, "date", l, 1);
+ json_date(fp, "date", l, 1);
phase = P_OBJECT;
break;
}
blob - abc10999b714c055c44b01f7d380e97962a222f8
blob + 77be7d3f23878f357a4e133557280d9e062ceaa9
--- gotd/notify.c
+++ gotd/notify.c
argv[i++] = "-h";
argv[i++] = target->conf.email.hostname;
}
-
+
if (target->conf.email.port) {
argv[i++] = "-p";
argv[i++] = target->conf.email.port;
blob - 787504ad4f6f0817c648d3f24b5d75d65da66010
blob + a409328c01fae5d0f4136cddf2e34b224469bbc2
--- gotd/repo_write.c
+++ gotd/repo_write.c
return NULL;
}
-
-static char *
-get_datestr(time_t *time, char *datebuf)
-{
- struct tm mytm, *tm;
- char *p, *s;
- tm = gmtime_r(time, &mytm);
- if (tm == NULL)
- return NULL;
- s = asctime_r(tm, datebuf);
- if (s == NULL)
- return NULL;
- p = strchr(s, '\n');
- if (p)
- *p = '\0';
- return s;
-}
-
static const struct got_error *
notify_removed_ref(const char *refname, uint8_t *sha1,
struct gotd_imsgev *iev, int fd)
char *id_str = NULL, *logmsg0 = NULL;
char *s, *nl;
char *committer = NULL, *author = NULL;
- char datebuf[12]; /* YYYY-MM-DD + SPACE + NUL */
- struct tm tm;
time_t committer_time;
err = got_object_id_str(&id_str, id);
return err;
committer_time = got_object_commit_get_committer_time(commit);
- if (gmtime_r(&committer_time, &tm) == NULL) {
- err = got_error_from_errno("gmtime_r");
- goto done;
- }
- if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0) {
- err = got_error(GOT_ERR_NO_SPACE);
- goto done;
- }
err = got_object_commit_get_logmsg(&logmsg0, commit);
if (err)
err = got_error_from_errno("strdup");
goto done;
}
- dprintf(fd, "%s%.7s %.8s %s\n", datebuf, id_str,
- format_author(author), s);
+ dprintf(fd, "%lld %.7s %.8s %s\n", (long long)committer_time,
+ id_str, format_author(author), s);
} else {
committer = strdup(got_object_commit_get_committer(commit));
- if (committer == NULL) {
- err = got_error_from_errno("strdup");
- goto done;
- }
- dprintf(fd, "%s%.7s %.8s %s\n", datebuf, id_str,
- format_author(committer), s);
+ dprintf(fd, "%lld %.7s %.8s %s\n", (long long)committer_time,
+ id_str, format_author(committer), s);
}
if (fsync(fd) == -1 && err == NULL)
struct got_diffstat_cb_arg *diffstat, int fd)
{
const struct got_error *err = NULL;
- char *id_str, *datestr, *logmsg0, *logmsg, *line;
- char datebuf[26];
+ char *id_str, *logmsg0, *logmsg, *line;
time_t committer_time;
const char *author, *committer;
if (strcmp(author, committer) != 0)
dprintf(fd, "via: %s\n", committer);
committer_time = got_object_commit_get_committer_time(commit);
- datestr = get_datestr(&committer_time, datebuf);
- if (datestr)
- dprintf(fd, "date: %s UTC\n", datestr);
+ dprintf(fd, "date: %lld\n", (long long)committer_time);
if (got_object_commit_get_nparents(commit) > 1) {
const struct got_object_id_queue *parent_ids;
struct got_object_qid *qid;
const struct got_error *err = NULL;
struct got_tag_object *tag = NULL;
const char *tagger = NULL;
- char *id_str = NULL, *tagmsg0 = NULL, *tagmsg, *line, *datestr;
- char datebuf[26];
+ char *id_str = NULL, *tagmsg0 = NULL, *tagmsg, *line;
time_t tagger_time;
err = got_object_open_as_tag(&tag, repo, id);
dprintf(fd, "tag %s\n", refname);
dprintf(fd, "from: %s\n", tagger);
- datestr = get_datestr(&tagger_time, datebuf);
- if (datestr)
- dprintf(fd, "date: %s UTC\n", datestr);
+ dprintf(fd, "date: %lld\n", (long long)tagger_time);
switch (got_object_tag_get_object_type(tag)) {
case GOT_OBJ_TYPE_BLOB:
blob - 18726da0df985a0e71d65fb2408032c6677ffe00
blob + 23a8d91f145b36a4fca7522f147af43bd6c98956
--- regress/gotd/http_notification.sh
+++ regress/gotd/http_notification.sh
wait %1 # wait for the http "server"
- d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
-
touch "$testroot/stdout.expected"
ed -s "$testroot/stdout.expected" <<-EOF
a
"mail":"$GIT_AUTHOR_EMAIL",
"user":"$GOT_AUTHOR_11"
},
- "date":"$d",
+ "date":$author_time,
"short_message":"make changes",
"message":"make changes\n",
"diffstat":{
wait %1 # wait for the http "server"
- d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
-
touch "$testroot/stdout.expected"
ed -s "$testroot/stdout.expected" <<-EOF
a
"mail":"$GIT_AUTHOR_EMAIL",
"user":"$GOT_AUTHOR_11"
},
- "date":"$d",
+ "date":$author_time,
"short_message":"make\uFFFD\uFFFDchanges",
"message":"make\uFFFD\uFFFDchanges\n",
"diffstat":{
(cd $testroot/wt && got commit -m 'make changes' > /dev/null)
local commit_id=`git_show_head $testroot/repo-clone`
local author_time=`git_show_author_time $testroot/repo-clone`
- d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
- set -- "$@" "$commit_id $d"
+ set -- "$@" "$commit_id $author_time"
done
timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
"mail":"$GIT_AUTHOR_EMAIL",
"user":"$GOT_AUTHOR_11"
},
- "date":"$commit_time",
+ "date":$commit_time,
"short_message":"make changes",
"message":"make changes\n",
"diffstat":{
local commit_id=`git_show_head $testroot/repo-clone`
local short_commit_id=`trim_obj_id 33 $commit_id`
local author_time=`git_show_author_time $testroot/repo-clone`
- d=`date -u -r $author_time +"%G-%m-%d"`
- set -- "$@" "$short_commit_id $d"
+ set -- "$@" "$short_commit_id $author_time"
done
timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
for i in `seq 1 51`; do
s=`pop_idx $i "$@"`
commit_id=$(echo $s | cut -d' ' -f1)
- commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
+ commit_time=$(echo "$s" | cut -d' ' -f2)
echo "$comma"
comma=','
"committer":{
"user":"$GOT_AUTHOR_8"
},
- "date":"$commit_time",
+ "date":$commit_time,
"short_message":"make changes"
}
EOF
wait %1 # wait for the http "server"
- d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
-
# in the future it should contain something like this too
# {
# "type":"new-branch",
"mail":"$GIT_AUTHOR_EMAIL",
"user":"$GOT_AUTHOR_11"
},
- "date":"$d",
+ "date":$author_time,
"short_message":"newbranch",
"message":"newbranch\n",
"diffstat":{
wait %1 # wait for the http "server"
- d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
-
touch "$testroot/stdout.expected"
ed -s "$testroot/stdout.expected" <<-EOF
a
"mail":"$GIT_AUTHOR_EMAIL",
"user":"$GOT_AUTHOR_11"
},
- "date":"$d",
+ "date":$tagger_time,
"object":{
"type":"commit",
"id":"$commit_id"
wait %1 # wait for the http "server"
- d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
-
# XXX: at the moment this is exactly the same as the "new tag"
# notification
"mail":"$GIT_AUTHOR_EMAIL",
"user":"$GOT_AUTHOR_11"
},
- "date":"$d",
+ "date":$tagger_time,
"object":{
"type":"commit",
"id":"$commit_id"