summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.css27
-rwxr-xr-xtests/t0104-tree.sh4
-rw-r--r--ui-tree.c31
3 files changed, 34 insertions, 28 deletions
diff --git a/cgit.css b/cgit.css
index e8214de..f844efa 100644
--- a/cgit.css
+++ b/cgit.css
@@ -191,116 +191,121 @@ td#content {
div#summary {
vertical-align: top;
margin-bottom: 1em;
}
table#downloads {
float: right;
border-collapse: collapse;
border: solid 1px #777;
margin-left: 0.5em;
margin-bottom: 0.5em;
}
table#downloads th {
background-color: #ccc;
}
div#blob {
border: solid 1px black;
}
div.error {
color: red;
font-weight: bold;
margin: 1em 2em;
}
a.ls-blob, a.ls-dir, a.ls-mod {
font-family: monospace;
}
td.ls-size {
text-align: right;
font-family: monospace;
width: 10em;
}
td.ls-mode {
font-family: monospace;
width: 10em;
}
table.blob {
margin-top: 0.5em;
border-top: solid 1px black;
}
-table.blob td.no {
- border-right: solid 1px black;
+table.blob td.lines {
+ margin: 0; padding: 0;
+ vertical-align: top;
color: black;
+}
+
+table.blob td.linenumbers {
+ margin: 0; padding: 0;
+ vertical-align: top;
+ border-right: 1px solid gray;
background-color: #eee;
- text-align: right;
}
-table.blob td.no a {
- color: black;
+table.blob pre {
+ padding: 0; margin: 0;
}
-table.blob td.no a:hover {
- color: black;
+table.blob a.no {
+ color: gray;
+ text-align: right;
text-decoration: none;
}
-table.blob td.txt {
- white-space: pre;
- font-family: monospace;
- padding-left: 0.5em;
+table.blob a.no a:hover {
+ color: black;
}
table.nowrap td {
white-space: nowrap;
}
table.commit-info {
border-collapse: collapse;
margin-top: 1.5em;
}
table.commit-info th {
text-align: left;
font-weight: normal;
padding: 0.1em 1em 0.1em 0.1em;
vertical-align: top;
}
table.commit-info td {
font-weight: normal;
padding: 0.1em 1em 0.1em 0.1em;
}
div.commit-subject {
font-weight: bold;
font-size: 125%;
margin: 1.5em 0em 0.5em 0em;
padding: 0em;
}
div.commit-msg {
white-space: pre;
font-family: monospace;
}
div.diffstat-header {
font-weight: bold;
padding-top: 1.5em;
}
table.diffstat {
border-collapse: collapse;
border: solid 1px #aaa;
background-color: #eee;
}
table.diffstat th {
font-weight: normal;
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
index 33f4eb0..2ce1251 100755
--- a/tests/t0104-tree.sh
+++ b/tests/t0104-tree.sh
@@ -1,33 +1,33 @@
#!/bin/sh
. ./setup.sh
prepare_tests "Check content on tree page"
run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp'
run_test 'find file-1' 'grep -e "file-1" trash/tmp'
run_test 'find file-50' 'grep -e "file-50" trash/tmp'
run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'
run_test 'find line 1' '
- grep -e "<a id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
+ grep -e "<a class=.no. id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
'
run_test 'no line 2' '
- ! grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
+ ! grep -e "<a class=.no. id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
'
run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp'
run_test 'verify a+b link' '
grep -e "/foo+bar/tree/a+b" trash/tmp
'
run_test 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >trash/tmp'
run_test 'verify a+b?h=1+2 link' '
grep -e "/foo+bar/tree/a+b?h=1%2b2" trash/tmp
'
tests_done
diff --git a/ui-tree.c b/ui-tree.c
index 4b8e7a0..c26ba4c 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,109 +1,110 @@
/* ui-tree.c: functions for tree output
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
char *curr_rev;
char *match_path;
int header = 0;
static void print_object(const unsigned char *sha1, char *path)
{
enum object_type type;
char *buf;
- unsigned long size, lineno, start, idx;
- const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>";
+ unsigned long size, lineno, idx;
+ const char *numberfmt = "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
cgit_print_error(fmt("Bad object name: %s",
sha1_to_hex(sha1)));
return;
}
buf = read_sha1_file(sha1, &type, &size);
if (!buf) {
cgit_print_error(fmt("Error reading object %s",
sha1_to_hex(sha1)));
return;
}
html(" (");
cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
curr_rev, path);
- htmlf(")<br/>blob: %s", sha1_to_hex(sha1));
+ htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
html("<table summary='blob content' class='blob'>\n");
+ html("<tr>\n");
+
+ html("<td class='linenumbers'><pre>");
idx = 0;
- start = 0;
lineno = 0;
- while(idx < size) {
+ htmlf(numberfmt, ++lineno);
+ while(idx < size - 1) { // skip absolute last newline
if (buf[idx] == '\n') {
- buf[idx] = '\0';
- htmlf(linefmt, ++lineno);
- html_txt(buf + start);
- html("</td></tr>\n");
- start = idx + 1;
+ htmlf(numberfmt, ++lineno);
}
idx++;
}
- if (start < idx) {
- htmlf(linefmt, ++lineno);
- html_txt(buf + start);
- }
- html("</td></tr>\n");
+ html("</pre></td>\n");
+
+ html("<td class='lines'><pre><code>");
+ html_txt(buf);
+ html("</code></pre></td>\n");
+
+ html("</tr>\n");
html("</table>\n");
}
static int ls_item(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned int mode, int stage,
void *cbdata)
{
char *name;
char *fullpath;
enum object_type type;
unsigned long size = 0;
name = xstrdup(pathname);
fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
ctx.qry.path ? "/" : "", name);
if (!S_ISGITLINK(mode)) {
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
name,
sha1_to_hex(sha1));
return 0;
}
}
html("<tr><td class='ls-mode'>");
cgit_print_filemode(mode);
html("</td><td>");
if (S_ISGITLINK(mode)) {
htmlf("<a class='ls-mod' href='");
html_attr(fmt(ctx.repo->module_link,
name,
sha1_to_hex(sha1)));
html("'>");
html_txt(name);
html("</a>");
} else if (S_ISDIR(mode)) {
cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
curr_rev, fullpath);
} else {
cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head,
curr_rev, fullpath);
}
htmlf("</td><td class='ls-size'>%li</td>", size);
html("<td>");