History

ui-tree,ui-blame: bail from blame if blob is binary

This avoids piping binary blobs through the source-filter. Also prevent robots from crawling it, since it's expensive.

June McEnroe committed 6 years ago

Commit cc6d9cc1 parent e1015963 files · +9 −2Browse files

Unified · Split

3 files
  1. robots.txt +1 −0
  2. ui-blame.c +4 −0
  3. ui-tree.c +4 −2
robots.txt+1−0
@@ -1,3 +1,4 @@
11 User-agent: *
22 Disallow: /*/snapshot/*
3+Disallow: /*/blame/*
34 Allow: /
ui-blame.c+4−0
@@ -152,6 +152,10 @@ static void print_object(const struct object_id *oid, const char *path, · 151 unmodified lines
152152 cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path);
153153 html(")\n");
154154
155+ if (buffer_is_binary(buf, size)) {
156+ html("<div class='error'>blob is binary.</div>");
157+ goto cleanup;
158+ }
155159 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
156160 htmlf("<div class='error'>blob size (%ldKB)"
157161 " exceeds display size limit (%dKB).</div>",
ui-tree.c+4−2
@@ -89,6 +89,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch · 88 unmodified lines
8989 enum object_type type;
9090 char *buf;
9191 unsigned long size;
92+ bool is_binary;
9293
9394 type = oid_object_info(the_repository, oid, &size);
9495 if (type == OBJ_BAD) {
@@ -103,6 +104,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch · 8 unmodified lines
103104 "Error reading object %s", oid_to_hex(oid));
104105 return;
105106 }
107+ is_binary = buffer_is_binary(buf, size);
106108
107109 cgit_set_title_from_path(path);
108110
@@ -110,7 +112,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch · 1 unmodified line
110112 htmlf("blob: %s (", oid_to_hex(oid));
111113 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
112114 rev, path);
113− if (ctx.repo->enable_blame) {
115+ if (ctx.repo->enable_blame && !is_binary) {
114116 html(") (");
115117 cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
116118 rev, path);
@@ -123,7 +125,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch · 6 unmodified lines
123125 return;
124126 }
125127
126− if (buffer_is_binary(buf, size))
128+ if (is_binary)
127129 print_binary_buffer(buf, size);
128130 else
129131 print_text_buffer(basename, buf, size);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t