Commit Diff


commit - 7b0989c733694e4d79049803668c74b4840b6e20
commit + 5f2b57d4a3b2a0b0a66e032ca158b370e32d3067
blob - db270280ca4d6040a9b0446506b8b3dbb684c927
blob + 4ea8a78d3b0816de91a5213adb84b8c113384b69
--- tog/tog.c
+++ tog/tog.c
@@ -5103,7 +5103,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;
@@ -5254,16 +5254,41 @@ write_diffstat(FILE *outfile, struct got_diff_line **l
 }
 
 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;
+}
+
+static const struct got_error *
 write_commit_info(struct got_diff_line **lines, size_t *nlines,
     struct got_object_id *commit_id, struct got_reflist_head *refs,
     struct got_repository *repo, int ignore_ws, int force_text_diff,
     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;
 	off_t outoff = 0;
@@ -5298,8 +5323,12 @@ 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 and committer data */
+	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;
@@ -5308,9 +5337,6 @@ 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) {
@@ -5323,20 +5349,18 @@ write_commit_info(struct got_diff_line **lines, size_t
 		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 (n < 0) {
-			err = got_error_from_errno("fprintf");
-			goto done;
-		}
-		outoff += n;
-		err = add_line_metadata(lines, nlines, outoff,
-		    GOT_DIFF_LINE_DATE);
+	err = write_date(lines, nlines, "date:", &committer_time, outfile,
+	    &outoff);
+	if (err)
+		goto done;
+	if (author_time != committer_time) {
+		err = write_date(lines, nlines, "orig:", &author_time, outfile,
+		    &outoff);
 		if (err)
 			goto done;
 	}
+
+	/* parent commits */
 	if (got_object_commit_get_nparents(commit) > 1) {
 		const struct got_object_id_queue *parent_ids;
 		struct got_object_qid *qid;