Commit bacc99353dcb86d36bf8ffe0f99e0a47984b3bc7

Stefan Sperling 2018-05-20T13:02:12

show log message above a diff between commits

diff --git a/include/got_object.h b/include/got_object.h
index 2c9c8f8..54d808e 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -80,6 +80,12 @@ struct got_object_id *got_object_id_dup(struct got_object_id *);
 struct got_object_id *got_object_get_id(struct got_object *);
 
 /*
+ * Get a newly allocated copy of an object's ID string.
+ * The caller should dispose of it with free(3).
+ */
+const struct got_error *got_object_get_id_str(char **, struct got_object *);
+
+/*
  * Obtain the type of an object.
  * Returns one of the GOT_OBJ_TYPE_x values (see above).
  */
diff --git a/lib/diff.c b/lib/diff.c
index 6d77494..b46cb06 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -519,12 +519,23 @@ got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
 			goto done;
 	}
 	if (obj2) {
+		char *id_str;
+
 		err = got_object_commit_open(&commit2, repo, obj2);
 		if (err)
 			goto done;
 		err = got_object_open(&tree_obj2, repo, commit2->tree_id);
 		if (err)
 			goto done;
+		err = got_object_get_id_str(&id_str, obj2);
+		if (err)
+			goto done;
+		fprintf(outfile, "commit: %s\n", id_str);
+		free(id_str);
+		fprintf(outfile, "author: %s\n", commit2->author);
+		if (strcmp(commit2->author, commit2->committer) != 0)
+			fprintf(outfile, "committer: %s\n", commit2->committer);
+		fprintf(outfile, "\n%s\n", commit2->logmsg);
 	}
 	err = got_diff_objects_as_trees(tree_obj1, tree_obj2, repo, outfile);
 done:
diff --git a/lib/object.c b/lib/object.c
index 45d21d4..fd3ef97 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -105,6 +105,12 @@ got_object_get_id(struct got_object *obj)
 	return got_object_id_dup(&obj->id);
 }
 
+const struct got_error *
+got_object_get_id_str(char **outbuf, struct got_object *obj)
+{
+	return got_object_id_str(outbuf, &obj->id);
+}
+
 int
 got_object_get_type(struct got_object *obj)
 {