commit 20a750ff945baed4c729142993cb0217f40830b9 from: Sven M. Hallberg date: Thu Aug 01 16:27:44 2024 UTC tog: show author date if different from committer date commit - dee3d788b5980d09c1dac29e67844b3947488112 commit + 20a750ff945baed4c729142993cb0217f40830b9 blob - 674de2c51543e1af563af32b17a4d609805167ec blob + fca64360499d25b37e4da465d063154d61ce89a8 --- tog/tog.c +++ tog/tog.c @@ -5033,7 +5033,7 @@ draw_file(struct tog_view *view, const char *header) } static char * -get_datestr(time_t *time, char *datebuf) +get_datestr(const time_t *time, char *datebuf) { struct tm mytm, *tm; char *p, *s; @@ -5118,7 +5118,33 @@ cat_diff(FILE *dst, FILE *src, struct got_diff_line ** memcpy(*d_lines + *d_nlines, s_lines, s_nlines * sizeof(*s_lines)); *d_nlines += s_nlines; + + return NULL; +} + +static const struct got_error * +write_date(struct got_diff_line **lines, size_t *nlines, + const char *prefix, const time_t *t, FILE *outfile, off_t *outoff) +{ + const struct got_error *err; + char datebuf[26], *datestr; + int n; + + datestr = get_datestr(t, datebuf); + if (datestr == NULL) + return NULL; /* silently ignored */ + n = fprintf(outfile, "%s %s UTC\n", prefix, datestr); + if (n < 0) { + err = got_error_from_errno("fprintf"); + return err; + } + *outoff += n; + err = add_line_metadata(lines, nlines, *outoff, + GOT_DIFF_LINE_DATE); + if (err) + return err; + return NULL; } @@ -5129,10 +5155,9 @@ write_commit_info(struct got_diff_line **lines, size_t struct got_diffstat_cb_arg *dsa, FILE *outfile) { const struct got_error *err = NULL; - char datebuf[26], *datestr; struct got_commit_object *commit; char *id_str = NULL, *logmsg = NULL, *s = NULL, *line; - time_t committer_time; + time_t author_time, committer_time; const char *author, *committer; char *refs_str = NULL; struct got_pathlist_entry *pe; @@ -5168,8 +5193,11 @@ write_commit_info(struct got_diff_line **lines, size_t if (err) goto done; - n = fprintf(outfile, "from: %s\n", - got_object_commit_get_author(commit)); + author = got_object_commit_get_author(commit); + author_time = got_object_commit_get_author_time(commit); + committer = got_object_commit_get_committer(commit); + committer_time = got_object_commit_get_committer_time(commit); + n = fprintf(outfile, "from: %s\n", author); if (n < 0) { err = got_error_from_errno("fprintf"); goto done; @@ -5178,35 +5206,28 @@ write_commit_info(struct got_diff_line **lines, size_t err = add_line_metadata(lines, nlines, outoff, GOT_DIFF_LINE_AUTHOR); if (err) goto done; - - author = got_object_commit_get_author(commit); - committer = got_object_commit_get_committer(commit); - if (strcmp(author, committer) != 0) { - n = fprintf(outfile, "via: %s\n", committer); - if (n < 0) { - err = got_error_from_errno("fprintf"); - goto done; - } - outoff += n; - err = add_line_metadata(lines, nlines, outoff, - GOT_DIFF_LINE_AUTHOR); + if (author_time != committer_time) { + err = write_date(lines, nlines, "orig:", &author_time, outfile, + &outoff); if (err) goto done; } - committer_time = got_object_commit_get_committer_time(commit); - datestr = get_datestr(&committer_time, datebuf); - if (datestr) { - n = fprintf(outfile, "date: %s UTC\n", datestr); + if (strcmp(author, committer) != 0) { + n = fprintf(outfile, "via: %s\n", committer); if (n < 0) { err = got_error_from_errno("fprintf"); goto done; } outoff += n; err = add_line_metadata(lines, nlines, outoff, - GOT_DIFF_LINE_DATE); + GOT_DIFF_LINE_AUTHOR); if (err) goto done; } + err = write_date(lines, nlines, "date:", &committer_time, outfile, + &outoff); + if (err) + goto done; if (got_object_commit_get_nparents(commit) > 1) { const struct got_object_id_queue *parent_ids; struct got_object_qid *qid;