Commit f78b0693d753895550a74d1b49c4c281cb805d39

Stefan Sperling 2017-11-29T23:42:16

show blob IDs in diff header

diff --git a/include/got_object.h b/include/got_object.h
index bdb83fc..0c42f4e 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -32,6 +32,7 @@ struct got_blob_object {
 	FILE *f;
 	struct got_zstream_buf zb;
 	size_t hdrlen;
+	struct got_object_id id;
 };
 
 struct got_tree_entry {
@@ -75,7 +76,7 @@ struct got_object {
 
 struct got_repository;
 
-const char * got_object_id_str(struct got_object_id *, char *, size_t);
+char * got_object_id_str(struct got_object_id *, char *, size_t);
 const struct got_error *got_object_open(struct got_object **,
     struct got_repository *, struct got_object_id *);
 void got_object_close(struct got_object *);
diff --git a/lib/diff.c b/lib/diff.c
index 2137919..f09406d 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -61,6 +61,8 @@ got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
 	FILE *f1, *f2;
 	char *n1, *n2;
 	size_t len, hdrlen;
+	char hex1[SHA1_DIGEST_STRING_LENGTH];
+	char hex2[SHA1_DIGEST_STRING_LENGTH];
 	int res;
 
 	err = open_tempfile(&f1, &n1);
@@ -102,6 +104,8 @@ got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
 	memset(&args, 0, sizeof(args));
 
 	args.diff_format = D_UNIFIED;
+	args.label[0] = got_object_id_str(&blob1->id, hex1, sizeof(hex1));
+	args.label[1] = got_object_id_str(&blob2->id, hex2, sizeof(hex2));
 	err = got_diffreg(&res, n1, n2, 0, &args, &ds);
 done:
 	unlink(n1);
diff --git a/lib/object.c b/lib/object.c
index 9f51ba2..a000e96 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -47,7 +47,7 @@
 #define GOT_COMMIT_TAG_AUTHOR		"author "
 #define GOT_COMMIT_TAG_COMMITTER	"committer "
 
-const char *
+char *
 got_object_id_str(struct got_object_id *id, char *buf, size_t size)
 {
 	char *p = buf;
@@ -692,6 +692,7 @@ got_object_blob_open(struct got_blob_object **blob,
 	}
 
 	(*blob)->hdrlen = obj->hdrlen;
+	memcpy(&(*blob)->id.sha1, obj->id.sha1, SHA1_DIGEST_LENGTH);
 
 	free(path);
 	return err;
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 926fc74..13ba983 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -27,6 +27,7 @@
 #include "got_refs.h"
 #include "got_repository.h"
 #include "got_sha1.h"
+#include "got_diff.h"
 
 #define RUN_TEST(expr, name) \
 	if (!(expr)) { printf("test %s failed", (name)); failure = 1; }
@@ -277,7 +278,7 @@ repo_diff_blob(const char *repo_path)
 		return 0;
 
 	putchar('\n');
-	got_diff_blob(blob1, blob2, repo);
+	got_diff_blob(blob1, blob2, stdout);
 	putchar('\n');
 
 	got_object_blob_close(blob1);