cgit

commit 9003cc172a4cbc6678f3d8003ae1ad3a55f62fed

Author: Lukas Fleischer <cgit@cryptocrack.de>

Allow for creating raw diffs with cgit_print_diff()

This adds a parameter to cgit_print_diff() to create raw diffs, using
the same format as `git diff <commit>`.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>

 cmd.c | 2 +-
 ui-commit.c | 2 +-
 ui-diff.c | 10 +++++++++-
 ui-diff.h | 2 +-


diff --git a/cmd.c b/cmd.c
index abe8e46098c0a284cb412b4328a5e9d33950566f..10761ce74fc24510722160da1edb911777ae25da 100644
--- a/cmd.c
+++ b/cmd.c
@@ -57,7 +57,7 @@ }
 
 static void diff_fn(struct cgit_context *ctx)
 {
-	cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1);
+	cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1, 0);
 }
 
 static void info_fn(struct cgit_context *ctx)




diff --git a/ui-commit.c b/ui-commit.c
index a5a6ea83c8e1049ccd3d4bca5649467fe2c7e916..ef85a499e9fb7b98e7613fb69c5147f4fd0a67fe 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -137,7 +137,7 @@ 		if (parents)
 			tmp = sha1_to_hex(commit->parents->item->object.sha1);
 		else
 			tmp = NULL;
-		cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
+		cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
 	}
 	strbuf_release(&notes);
 	cgit_free_commitinfo(info);




diff --git a/ui-diff.c b/ui-diff.c
index 8b38209a82e12dff0f89e62484dd8a2b84e4d83a..838db8c29a42df4e6355a3cd62d404fd4e5efeec 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -358,7 +358,7 @@ 	html("
"); } void cgit_print_diff(const char *new_rev, const char *old_rev, - const char *prefix, int show_ctrls) + const char *prefix, int show_ctrls, int raw) { enum object_type type; unsigned long size; @@ -396,6 +396,14 @@ if (!commit2 || parse_commit(commit2)) { cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1)); return; } + } + + if (raw) { + ctx.page.mimetype = "text/plain"; + cgit_print_http_headers(&ctx); + cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb_raw, + prefix, 0); + return; } use_ssdiff = ctx.qry.has_ssdiff ? ctx.qry.ssdiff : ctx.cfg.ssdiff; diff --git a/ui-diff.h b/ui-diff.h index 25a92969c76353e1457787714697a30f9ae58d1a..04f90293d132ce6581ae4258f820a9256930479a 100644 --- a/ui-diff.h +++ b/ui-diff.h @@ -4,7 +4,7 @@ extern void cgit_print_diff_ctrls(); extern void cgit_print_diff(const char *new_hex, const char *old_hex, - const char *prefix, int show_ctrls); + const char *prefix, int show_ctrls, int raw); extern struct diff_filespec *cgit_get_current_old_file(void); extern struct diff_filespec *cgit_get_current_new_file(void);