display UTC commit timestamps in tog(1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/got/got.c b/got/got.c
index a80083b..cdf523b 100644
--- a/got/got.c
+++ b/got/got.c
@@ -306,7 +306,7 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
return err;
}
-char *
+static char *
get_datestr(time_t *time, char *datebuf)
{
char *p, *s = ctime_r(time, datebuf);
diff --git a/lib/diff.c b/lib/diff.c
index 2bfa94e..94feecd 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -499,6 +499,16 @@ done:
return err;
}
+static char *
+get_datestr(time_t *time, char *datebuf)
+{
+ char *p, *s = ctime_r(time, datebuf);
+ p = strchr(s, '\n');
+ if (p)
+ *p = '\0';
+ return s;
+}
+
const struct got_error *
got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
struct got_repository *repo, FILE *outfile)
@@ -507,6 +517,8 @@ got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
struct got_commit_object *commit1 = NULL, *commit2 = NULL;
struct got_object *tree_obj1 = NULL, *tree_obj2 = NULL;
char *id_str;
+ char datebuf[26];
+ time_t time;
if (obj2 == NULL)
return got_error(GOT_ERR_NO_OBJ);
@@ -535,12 +547,16 @@ got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
goto done;
}
free(id_str);
- if (fprintf(outfile, "author: %s\n", commit2->author) < 0) {
+ time = mktime(&commit2->tm_author);
+ if (fprintf(outfile, "author: %s %s UTC\n", commit2->author,
+ get_datestr(&time, datebuf)) < 0) {
err = got_error_from_errno();
goto done;
}
+ time = mktime(&commit2->tm_committer);
if (strcmp(commit2->author, commit2->committer) != 0 &&
- fprintf(outfile, "committer: %s\n", commit2->committer) < 0) {
+ fprintf(outfile, "committer: %s %s UTC\n", commit2->committer,
+ get_datestr(&time, datebuf)) < 0) {
err = got_error_from_errno();
goto done;
}