allow for custom diff header labels
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 63 64
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);