Commit 62136d3a8b190e48501f0717bfd42e044e92616d

Stefan Sperling 2017-11-29T23:46:24

allow for custom diff header labels

diff --git a/include/got_diff.h b/include/got_diff.h
index e319708..8ba8533 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -15,4 +15,4 @@
  */
 
 const struct got_error *got_diff_blob(struct got_blob_object *,
-    struct got_blob_object *, FILE *);
+    struct got_blob_object *, const char *, const char *, FILE *);
diff --git a/lib/diff.c b/lib/diff.c
index f09406d..0032f42 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -53,7 +53,7 @@ open_tempfile(FILE **sfp, char **sfn)
 
 const struct got_error *
 got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
-    FILE *outfile)
+    const char *label1, const char *label2 ,FILE *outfile)
 {
 	struct got_diff_state ds;
 	struct got_diff_args args;
@@ -104,8 +104,11 @@ 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));
+	args.label[0] = label1 ?
+	    label1 : got_object_id_str(&blob1->id, hex1, sizeof(hex1));
+	args.label[1] = label2 ?
+	    label2 : 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/diff.h b/lib/diff.h
index 40a7cf5..80c64f3 100644
--- a/lib/diff.h
+++ b/lib/diff.h
@@ -112,7 +112,8 @@ struct got_diff_state {
 struct got_diff_args {
 	int	 Tflag;
 	int	 diff_format, diff_context, status;
-	char	*ifdefname, *diffargs, *label[2], *ignore_pats;
+	char	*ifdefname, *diffargs, *ignore_pats;
+	const char *label[2];
 };
 
 char	*splice(char *, char *);
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 13ba983..c589fb4 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -278,7 +278,7 @@ repo_diff_blob(const char *repo_path)
 		return 0;
 
 	putchar('\n');
-	got_diff_blob(blob1, blob2, stdout);
+	got_diff_blob(blob1, blob2, NULL, NULL, stdout);
 	putchar('\n');
 
 	got_object_blob_close(blob1);