show log message above a diff between commits
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/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)
{