commit 09867e481449ff3ca17bfc7132da42e839319511 from: Stefan Sperling date: Tue Aug 13 15:01:23 2019 UTC properly parse timestamps in commit objects as UTC (patch by Hiltjo Posthuma) commit - 5943eee28016d0b1f6e87c25366b3a85a95a727a commit + 09867e481449ff3ca17bfc7132da42e839319511 blob - 8c1f0a2fe706b6338dc31930faca0cb9c0d7bb2e blob + 0ebd0d6734cfc7bed752a53694a775aa00e278cd --- got/got.c +++ got/got.c @@ -1361,7 +1361,15 @@ done: static char * get_datestr(time_t *time, char *datebuf) { - char *p, *s = ctime_r(time, 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'; @@ -1439,7 +1447,8 @@ print_commit(struct got_commit_object *commit, struct printf("from: %s\n", got_object_commit_get_author(commit)); committer_time = got_object_commit_get_committer_time(commit); datestr = get_datestr(&committer_time, datebuf); - printf("date: %s UTC\n", datestr); + if (datestr) + printf("date: %s UTC\n", datestr); author = got_object_commit_get_author(commit); committer = got_object_commit_get_committer(commit); if (strcmp(author, committer) != 0) blob - 3a4758573cc31e0fe79549eef2a7b05ccce29621 blob + bf2e9f2ec10bebbef9454911e9980f3f1250ffbb --- lib/object_parse.c +++ lib/object_parse.c @@ -338,14 +338,11 @@ parse_commit_time(time_t *time, time_t *gmtoff, char * if (space == NULL) return got_error(GOT_ERR_BAD_OBJ_DATA); - /* Timestamp parsed here is expressed in comitter's local time. */ + /* Timestamp parsed here is expressed as UNIX timestamp (UTC). */ *time = strtonum(space + 1, 0, INT64_MAX, &errstr); if (errstr) return got_error(GOT_ERR_BAD_OBJ_DATA); - /* Express the time stamp in UTC. */ - *time -= *gmtoff; - /* Strip off parsed time information, leaving just author and email. */ *space = '\0'; blob - 0119a32cf90c03a3afc72f5b5dfdbe5b3ec1e7d4 blob + 6f4b6076ae0d011c28278b2e69626ade8a7f8b2e --- tog/tog.c +++ tog/tog.c @@ -2432,7 +2432,15 @@ draw_file(struct tog_view *view, FILE *f, int *first_d static char * get_datestr(time_t *time, char *datebuf) { - char *p, *s = ctime_r(time, 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'; @@ -2444,7 +2452,7 @@ write_commit_info(struct got_object_id *commit_id, struct got_reflist_head *refs, struct got_repository *repo, FILE *outfile) { const struct got_error *err = NULL; - char datebuf[26]; + char datebuf[26], *datestr; struct got_commit_object *commit; char *id_str = NULL, *logmsg = NULL; time_t committer_time; @@ -2478,8 +2486,8 @@ write_commit_info(struct got_object_id *commit_id, goto done; } committer_time = got_object_commit_get_committer_time(commit); - if (fprintf(outfile, "date: %s UTC\n", - get_datestr(&committer_time, datebuf)) < 0) { + datestr = get_datestr(&committer_time, datebuf); + if (datestr && fprintf(outfile, "date: %s UTC\n", datestr) < 0) { err = got_error_from_errno("fprintf"); goto done; }