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 @@
1User-agent: *1User-agent: *
2Disallow: /*/snapshot/*2Disallow: /*/snapshot/*
3Disallow: /*/blame/*
3Allow: /4Allow: /
ui-blame.c+4−0
@@ -152,6 +152,10 @@ static void print_object(const struct object_id *oid, const char *path, · 151 unmodified lines
152 cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path);152 cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path);
153 html(")\n");153 html(")\n");
154 154
155 if (buffer_is_binary(buf, size)) {
156 html("<div class='error'>blob is binary.</div>");
157 goto cleanup;
158 }
155 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {159 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
156 htmlf("<div class='error'>blob size (%ldKB)"160 htmlf("<div class='error'>blob size (%ldKB)"
157 " exceeds display size limit (%dKB).</div>",161 " 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
89 enum object_type type;89 enum object_type type;
90 char *buf;90 char *buf;
91 unsigned long size;91 unsigned long size;
92 bool is_binary;
92 93
93 type = oid_object_info(the_repository, oid, &size);94 type = oid_object_info(the_repository, oid, &size);
94 if (type == OBJ_BAD) {95 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
103 "Error reading object %s", oid_to_hex(oid));104 "Error reading object %s", oid_to_hex(oid));
104 return;105 return;
105 }106 }
107 is_binary = buffer_is_binary(buf, size);
106 108
107 cgit_set_title_from_path(path);109 cgit_set_title_from_path(path);
108 110
@@ -110,7 +112,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch · 1 unmodified line
110 htmlf("blob: %s (", oid_to_hex(oid));112 htmlf("blob: %s (", oid_to_hex(oid));
111 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,113 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
112 rev, path);114 rev, path);
113 if (ctx.repo->enable_blame) {115 if (ctx.repo->enable_blame && !is_binary) {
114 html(") (");116 html(") (");
115 cgit_blame_link("blame", NULL, NULL, ctx.qry.head,117 cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
116 rev, path);118 rev, path);
@@ -123,7 +125,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch · 6 unmodified lines
123 return;125 return;
124 }126 }
125 127
126 if (buffer_is_binary(buf, size))128 if (is_binary)
127 print_binary_buffer(buf, size);129 print_binary_buffer(buf, size);
128 else130 else
129 print_text_buffer(basename, buf, size);131 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