author | Onne Gorter <onne.gorter@avinity.net> | 2009-01-07 12:56:14 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-01-10 11:13:54 (UTC) |
commit | a90e2aa4e1bd5c3a9657ce7d675943f4a265cc9f (patch) (side-by-side diff) | |
tree | bd7d4cce277dbe3094dee0130410a738b074e5b2 /ui-tree.c | |
parent | 25f6a1f4c29b6a6009a185e9473317f0fe64616d (diff) | |
download | cgit-a90e2aa4e1bd5c3a9657ce7d675943f4a265cc9f.zip cgit-a90e2aa4e1bd5c3a9657ce7d675943f4a265cc9f.tar.gz cgit-a90e2aa4e1bd5c3a9657ce7d675943f4a265cc9f.tar.bz2 |
changed objects are outputted, allowing for selections of code only
-rw-r--r-- | ui-tree.c | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -1,125 +1,126 @@ /* 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>"); cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, fullpath, 0, NULL, NULL, ctx.qry.showmsg); html("</td></tr>\n"); free(name); return 0; } static void ls_head() { html("<table summary='tree listing' class='list'>\n"); html("<tr class='nohover'>"); html("<th class='left'>Mode</th>"); html("<th class='left'>Name</th>"); html("<th class='right'>Size</th>"); html("<th/>"); html("</tr>\n"); |