List for cgit developers and users
 help / color / Atom feed
* [PATCH 1/2] ui-blame: bail if blob is binary
@ 2019-12-18 21:52 june
  2019-12-18 21:52 ` [PATCH 2/2] ui-tree: don't link to blame for binary blobs june
  0 siblings, 1 reply; 2+ messages in thread
From: june @ 2019-12-18 21:52 UTC (permalink / raw)


This avoids piping binary blobs through the source-filter.
---
 ui-blame.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ui-blame.c b/ui-blame.c
index 644c30a..ecbe325 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -151,6 +151,10 @@ static void print_object(const struct object_id *oid, const char *path,
 	cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path);
 	html(")\n");
 
+	if (buffer_is_binary(buf, size)) {
+		html("<div class='error'>blob is binary.</div>");
+		goto cleanup;
+	}
 	if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
 		htmlf("<div class='error'>blob size (%ldKB)"
 		      " exceeds display size limit (%dKB).</div>",
-- 
2.23.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] ui-tree: don't link to blame for binary blobs
  2019-12-18 21:52 [PATCH 1/2] ui-blame: bail if blob is binary june
@ 2019-12-18 21:52 ` june
  0 siblings, 0 replies; 2+ messages in thread
From: june @ 2019-12-18 21:52 UTC (permalink / raw)


---
 ui-tree.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ui-tree.c b/ui-tree.c
index 84eb17d..c4f2dac 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -89,6 +89,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
 	enum object_type type;
 	char *buf;
 	unsigned long size;
+	int is_binary;
 
 	type = oid_object_info(the_repository, oid, &size);
 	if (type == OBJ_BAD) {
@@ -103,6 +104,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
 			"Error reading object %s", oid_to_hex(oid));
 		return;
 	}
+	is_binary = buffer_is_binary(buf, size);
 
 	cgit_set_title_from_path(path);
 
@@ -110,7 +112,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
 	htmlf("blob: %s (", oid_to_hex(oid));
 	cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
 		        rev, path);
-	if (ctx.repo->enable_blame) {
+	if (ctx.repo->enable_blame && !is_binary) {
 		html(") (");
 		cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
 			        rev, path);
@@ -123,7 +125,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
 		return;
 	}
 
-	if (buffer_is_binary(buf, size))
+	if (is_binary)
 		print_binary_buffer(buf, size);
 	else
 		print_text_buffer(basename, buf, size);
-- 
2.23.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18 21:52 [PATCH 1/2] ui-blame: bail if blob is binary june
2019-12-18 21:52 ` [PATCH 2/2] ui-tree: don't link to blame for binary blobs june

List for cgit developers and users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/cgit

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.cgit


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git