-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.css | 16 | ||||
-rw-r--r-- | cgit.h | 8 | ||||
-rw-r--r-- | shared.c | 3 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-tree.c | 194 | ||||
-rw-r--r-- | ui-view.c | 55 |
8 files changed, 174 insertions, 112 deletions
@@ -1,65 +1,65 @@ CGIT_VERSION = 0.5 prefix = /var/www/htdocs/cgit SHA1_HEADER = <openssl/sha.h> CACHE_ROOT = /var/cache/cgit CGIT_CONFIG = /etc/cgitrc CGIT_SCRIPT_NAME = cgit.cgi # # Let the user override the above settings. # -include cgit.conf EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ - ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ + ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ ui-snapshot.o ui-blob.o CFLAGS += -Wall ifdef DEBUG CFLAGS += -g endif CFLAGS += -Igit CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' # # If make is run on a nongit platform, get the git sources as a tarball. # GITVER = $(shell git version 2>/dev/null || echo nogit) ifeq ($(GITVER),nogit) GITURL = http://www.kernel.org/pub/software/scm/git/git-1.5.2.tar.bz2 INITGIT = test -e git/git.c || ((curl "$(GITURL)" | tar -xj) && mv git-1.5.2 git) else INITGIT = ./submodules.sh -i endif # # basic build rules # all: cgit cgit: cgit.c cgit.h $(OBJECTS) $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) $(OBJECTS): cgit.h git/libgit.a git/libgit.a: $(INITGIT) $(MAKE) -C git # # phony targets # install: all clean-cache mkdir -p $(prefix) install cgit $(prefix)/$(CGIT_SCRIPT_NAME) install cgit.css $(prefix)/cgit.css @@ -52,104 +52,101 @@ static void cgit_print_repo_page(struct cacheitem *item) int show_search; if (!cgit_query_head) cgit_query_head = cgit_repo->defbranch; if (chdir(cgit_repo->path)) { title = fmt("%s - %s", cgit_root_title, "Bad request"); cgit_print_docstart(title, item); cgit_print_pageheader(title, 0); cgit_print_error(fmt("Unable to scan repository: %s", strerror(errno))); cgit_print_docend(); return; } title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); show_search = 0; setenv("GIT_DIR", cgit_repo->path, 1); if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { cgit_print_snapshot(item, cgit_query_sha1, "zip", cgit_repo->url, cgit_query_name); return; } if (cgit_cmd == CMD_BLOB) { cgit_print_blob(item, cgit_query_sha1, cgit_query_path); return; } show_search = (cgit_cmd == CMD_LOG); cgit_print_docstart(title, item); if (!cgit_cmd) { cgit_print_pageheader("summary", show_search); cgit_print_summary(); cgit_print_docend(); return; } cgit_print_pageheader(cgit_query_page, show_search); switch(cgit_cmd) { case CMD_LOG: cgit_print_log(cgit_query_head, cgit_query_ofs, cgit_max_commit_count, cgit_query_search, cgit_query_path, 1); break; case CMD_TREE: - cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); + cgit_print_tree(cgit_query_sha1, cgit_query_path); break; case CMD_COMMIT: cgit_print_commit(cgit_query_head); break; - case CMD_VIEW: - cgit_print_view(cgit_query_sha1, cgit_query_path); - break; case CMD_DIFF: cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, cgit_query_path); break; default: cgit_print_error("Invalid request"); } cgit_print_docend(); } static void cgit_fill_cache(struct cacheitem *item, int use_cache) { static char buf[PATH_MAX]; int stdout2; getcwd(buf, sizeof(buf)); item->st.st_mtime = time(NULL); if (use_cache) { stdout2 = chk_positive(dup(STDOUT_FILENO), "Preserving STDOUT"); chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); } if (cgit_repo) cgit_print_repo_page(item); else cgit_print_repolist(item); if (use_cache) { chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); chk_positive(dup2(stdout2, STDOUT_FILENO), "Restoring original STDOUT"); chk_zero(close(stdout2), "Closing temporary STDOUT"); } chdir(buf); } static void cgit_check_cache(struct cacheitem *item) { int i = 0; top: if (++i > cgit_max_lock_attempts) { die("cgit_refresh_cache: unable to lock %s: %s", item->name, strerror(errno)); @@ -154,100 +154,112 @@ table#downloads { border: solid 1px #777; margin-left: 0.5em; margin-bottom: 0.5em; } table#downloads th { background-color: #ccc; } td#content { padding: 1em 0.5em; } div#blob { border: solid 1px black; } div.error { color: red; font-weight: bold; margin: 1em 2em; } td.ls-blob, td.ls-dir, td.ls-mod { font-family: monospace; } div.ls-dir a { font-weight: bold; } th.filesize, td.filesize { text-align: right; } td.filesize { font-family: monospace; } td.links { font-size: 80%; padding-left: 2em; } td.filemode { font-family: monospace; } -td.blob { +table.blob { + margin-top: 0.5em; + border-top: solid 1px black; +} + +table.blob td.no { + border-right: solid 1px black; + color: black; + background-color: #eee; + text-align: right; +} + +table.blob td.txt { white-space: pre; font-family: monospace; - background-color: white; + padding-left: 0.5em; } 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; } 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; width: 100%; border: solid 1px #aaa; background-color: #eee; } table.diffstat tr:hover { background-color: #ccc; @@ -1,78 +1,77 @@ #ifndef CGIT_H #define CGIT_H #include <git-compat-util.h> #include <cache.h> #include <grep.h> #include <object.h> #include <tree.h> #include <commit.h> #include <tag.h> #include <diff.h> #include <diffcore.h> #include <refs.h> #include <revision.h> #include <log-tree.h> #include <archive.h> #include <xdiff/xdiff.h> /* * The valid cgit repo-commands */ #define CMD_LOG 1 #define CMD_COMMIT 2 #define CMD_DIFF 3 #define CMD_TREE 4 -#define CMD_VIEW 5 -#define CMD_BLOB 6 -#define CMD_SNAPSHOT 7 +#define CMD_BLOB 5 +#define CMD_SNAPSHOT 6 /* * Dateformats used on misc. pages */ #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" #define FMT_SHORTDATE "%Y-%m-%d" /* * Limits used for relative dates */ #define TM_MIN 60 #define TM_HOUR (TM_MIN * 60) #define TM_DAY (TM_HOUR * 24) #define TM_WEEK (TM_DAY * 7) #define TM_YEAR (TM_DAY * 365) #define TM_MONTH (TM_YEAR / 12.0) typedef void (*configfn)(const char *name, const char *value); typedef void (*filepair_fn)(struct diff_filepair *pair); typedef void (*linediff_fn)(char *line, int len); struct cacheitem { char *name; struct stat st; int ttl; int fd; }; struct repoinfo { char *url; char *name; char *path; char *desc; char *owner; char *defbranch; char *group; char *module_link; char *readme; int snapshots; int enable_log_filecount; int enable_log_linecount; }; struct repolist { int length; @@ -170,59 +169,58 @@ extern void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, filepair_fn fn); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); extern char *fmt(const char *format,...); extern void html(const char *txt); extern void htmlf(const char *format,...); extern void html_txt(char *txt); extern void html_ntxt(int len, char *txt); extern void html_attr(char *txt); extern void html_hidden(char *name, char *value); extern void html_link_open(char *url, char *title, char *class); extern void html_link_close(void); extern void html_filemode(unsigned short mode); extern int html_include(const char *filename); extern int cgit_read_config(const char *filename, configfn fn); extern int cgit_parse_query(char *txt, configfn fn); extern struct commitinfo *cgit_parse_commit(struct commit *commit); extern struct taginfo *cgit_parse_tag(struct tag *tag); extern void cgit_parse_url(const char *url); extern char *cache_safe_filename(const char *unsafe); extern int cache_lock(struct cacheitem *item); extern int cache_unlock(struct cacheitem *item); extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern void cgit_print_error(char *msg); extern void cgit_print_date(time_t secs, char *format); extern void cgit_print_age(time_t t, time_t max_relative, char *format); extern void cgit_print_docstart(char *title, struct cacheitem *item); extern void cgit_print_docend(); extern void cgit_print_pageheader(char *title, int show_search); extern void cgit_print_snapshot_start(const char *mimetype, const char *filename, struct cacheitem *item); extern void cgit_print_repolist(struct cacheitem *item); extern void cgit_print_summary(); extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); -extern void cgit_print_view(const char *hex, char *path); extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); -extern void cgit_print_tree(const char *rev, const char *hex, char *path); +extern void cgit_print_tree(const char *rev, char *path); extern void cgit_print_commit(const char *hex); extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path); extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, const char *format, const char *prefix, const char *filename); #endif /* CGIT_H */ @@ -14,97 +14,98 @@ int cgit_cmd; char *cgit_root_title = "Git repository browser"; char *cgit_css = "/cgit.css"; char *cgit_logo = "/git-logo.png"; char *cgit_index_header = NULL; char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; char *cgit_agefile = "info/web/last-modified"; char *cgit_virtual_root = NULL; char *cgit_script_name = CGIT_SCRIPT_NAME; char *cgit_cache_root = "/var/cache/cgit"; char *cgit_repo_group = NULL; int cgit_nocache = 0; int cgit_snapshots = 0; int cgit_enable_log_filecount = 0; int cgit_enable_log_linecount = 0; int cgit_max_lock_attempts = 5; int cgit_cache_root_ttl = 5; int cgit_cache_repo_ttl = 5; int cgit_cache_dynamic_ttl = 5; int cgit_cache_static_ttl = -1; int cgit_cache_max_create_time = 5; int cgit_summary_log = 0; int cgit_max_msg_len = 60; int cgit_max_repodesc_len = 60; int cgit_max_commit_count = 50; int cgit_query_has_symref = 0; int cgit_query_has_sha1 = 0; char *cgit_querystring = NULL; char *cgit_query_repo = NULL; char *cgit_query_page = NULL; char *cgit_query_head = NULL; char *cgit_query_search = NULL; char *cgit_query_sha1 = NULL; char *cgit_query_sha2 = NULL; char *cgit_query_path = NULL; char *cgit_query_name = NULL; int cgit_query_ofs = 0; int htmlfd = 0; int cgit_get_cmd_index(const char *cmd) { - static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL}; + static char *cmds[] = {"log", "commit", "diff", "tree", "blob", + "snapshot", NULL}; int i; for(i = 0; cmds[i]; i++) if (!strcmp(cmd, cmds[i])) return i + 1; return 0; } int chk_zero(int result, char *msg) { if (result != 0) die("%s: %s", msg, strerror(errno)); return result; } int chk_positive(int result, char *msg) { if (result <= 0) die("%s: %s", msg, strerror(errno)); return result; } struct repoinfo *add_repo(const char *url) { struct repoinfo *ret; if (++cgit_repolist.count > cgit_repolist.length) { if (cgit_repolist.length == 0) cgit_repolist.length = 8; else cgit_repolist.length *= 2; cgit_repolist.repos = xrealloc(cgit_repolist.repos, cgit_repolist.length * sizeof(struct repoinfo)); } ret = &cgit_repolist.repos[cgit_repolist.count-1]; ret->url = xstrdup(url); ret->name = ret->url; ret->path = NULL; ret->desc = NULL; ret->owner = NULL; ret->group = cgit_repo_group; ret->defbranch = "master"; ret->snapshots = cgit_snapshots; ret->enable_log_filecount = cgit_enable_log_filecount; ret->enable_log_linecount = cgit_enable_log_linecount; ret->module_link = cgit_module_link; diff --git a/ui-commit.c b/ui-commit.c index 1d12bbb..ed5384d 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -137,98 +137,97 @@ void inspect_filepair(struct diff_filepair *pair) items[files-1].old_path = xstrdup(pair->one->path); items[files-1].new_path = xstrdup(pair->two->path); items[files-1].added = lines_added; items[files-1].removed = lines_removed; if (lines_added + lines_removed > max_changes) max_changes = lines_added + lines_removed; total_adds += lines_added; total_rems += lines_removed; } void cgit_print_commit(const char *hex) { struct commit *commit, *parent; struct commitinfo *info; struct commit_list *p; unsigned char sha1[20]; char *query; char *filename; int i; if (get_sha1(hex, sha1)) { cgit_print_error(fmt("Bad object id: %s", hex)); return; } commit = lookup_commit_reference(sha1); if (!commit) { cgit_print_error(fmt("Bad commit reference: %s", hex)); return; } info = cgit_parse_commit(commit); html("<table class='commit-info'>\n"); html("<tr><th>author</th><td>"); html_txt(info->author); html(" "); html_txt(info->author_email); html("</td><td class='right'>"); cgit_print_date(info->author_date, FMT_LONGDATE); html("</td></tr>\n"); html("<tr><th>committer</th><td>"); html_txt(info->committer); html(" "); html_txt(info->committer_email); html("</td><td class='right'>"); cgit_print_date(info->committer_date, FMT_LONGDATE); html("</td></tr>\n"); html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); - query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), - sha1_to_hex(commit->tree->object.sha1)); + query = fmt("h=%s", sha1_to_hex(commit->object.sha1)); html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); for (p = commit->parents; p ; p = p->next) { parent = lookup_commit_reference(p->item->object.sha1); if (!parent) { html("<tr><td colspan='3'>"); cgit_print_error("Error reading parent commit"); html("</td></tr>"); continue; } html("<tr><th>parent</th>" "<td colspan='2' class='sha1'>" "<a href='"); query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); htmlf("'>%s</a> (<a href='", sha1_to_hex(p->item->object.sha1)); query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), sha1_to_hex(commit->tree->object.sha1)); html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); html("'>diff</a>)</td></tr>"); } if (cgit_repo->snapshots) { htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); filename = fmt("%s-%s.zip", cgit_query_repo, hex); html_attr(cgit_pageurl(cgit_query_repo, "snapshot", fmt("id=%s&name=%s", hex, filename))); htmlf("'>%s</a></td></tr>", filename); } html("</table>\n"); html("<div class='commit-subject'>"); html_txt(info->subject); html("</div>"); html("<div class='commit-msg'>"); html_txt(info->msg); html("</div>"); if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { html("<div class='diffstat-header'>Diffstat</div>"); html("<table class='diffstat'>"); max_changes = 0; cgit_diff_commit(commit, inspect_filepair); for(i = 0; i<files; i++) print_fileinfo(&items[i]); html("</table>"); html("<div class='diffstat-summary'>"); htmlf("%d files changed, %d insertions, %d deletions (", files, total_adds, total_rems); query = fmt("h=%s", hex); @@ -1,104 +1,214 @@ /* 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" char *curr_rev; +char *match_path; +int header = 0; -static int print_entry(const unsigned char *sha1, const char *base, - int baselen, const char *pathname, unsigned int mode, - int stage) +static void print_object(const unsigned char *sha1, char *path) +{ + enum object_type type; + unsigned char *buf; + unsigned long size, lineno, start, idx; + + 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("<table class='blob'>\n"); + idx = 0; + start = 0; + lineno = 0; + while(idx < size) { + if (buf[idx] == '\n') { + buf[idx] = '\0'; + htmlf("<tr><td class='no'>%d</td><td class='txt'>", + ++lineno); + html_txt(buf + start); + html("</td></tr>\n"); + start = idx + 1; + } + idx++; + } + html("\n</td></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) { char *name; enum object_type type; unsigned long size = 0; + char *url, *qry; name = xstrdup(pathname); type = sha1_object_info(sha1, &size); if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", name, sha1_to_hex(sha1)); return 0; } + qry = fmt("h=%s&path=%s%s%s", curr_rev, + cgit_query_path ? cgit_query_path : "", + cgit_query_path ? "/" : "", pathname); + url = cgit_pageurl(cgit_query_repo, "tree", qry); html("<tr><td class='filemode'>"); html_filemode(mode); html("</td><td "); if (S_ISDIRLNK(mode)) { htmlf("class='ls-mod'><a href='"); html_attr(fmt(cgit_repo->module_link, name, sha1_to_hex(sha1))); } else if (S_ISDIR(mode)) { html("class='ls-dir'><a href='"); - html_attr(cgit_pageurl(cgit_query_repo, "tree", - fmt("h=%s&id=%s&path=%s%s/", - curr_rev, - sha1_to_hex(sha1), - cgit_query_path ? cgit_query_path : "", - pathname))); + html_attr(url); } else { html("class='ls-blob'><a href='"); - html_attr(cgit_pageurl(cgit_query_repo, "view", - fmt("h=%s&id=%s&path=%s%s", curr_rev, - sha1_to_hex(sha1), - cgit_query_path ? cgit_query_path : "", - pathname))); + html_attr(url); } htmlf("'>%s</a></td>", name); htmlf("<td class='filesize'>%li</td>", size); html("<td class='links'><a href='"); - html_attr(cgit_pageurl(cgit_query_repo, "log", - fmt("h=%s&path=%s%s", - curr_rev, - cgit_query_path ? cgit_query_path : "", - pathname))); - html("'>history</a></td>"); + qry = fmt("h=%s&path=%s%s%s", curr_rev, + cgit_query_path ? cgit_query_path : "", + cgit_query_path ? "/" : "", pathname); + url = cgit_pageurl(cgit_query_repo, "log", qry); + html_attr(url); + html("' class='button'>H</a></td>"); html("</tr>\n"); free(name); return 0; } -void cgit_print_tree(const char *rev, const char *hex, char *path) +static void ls_head() +{ + html("<table 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"); + header = 1; +} + +static void ls_tail() +{ + if (!header) + return; + html("</table>\n"); + header = 0; +} + +static void ls_tree(const unsigned char *sha1, char *path) { struct tree *tree; + + tree = parse_tree_indirect(sha1); + if (!tree) { + cgit_print_error(fmt("Not a tree object: %s", + sha1_to_hex(sha1))); + return; + } + + ls_head(); + read_tree_recursive(tree, "", 0, 1, NULL, ls_item); + ls_tail(); +} + + +static int walk_tree(const unsigned char *sha1, const char *base, int baselen, + const char *pathname, unsigned mode, int stage) +{ + static int state; + static char buffer[PATH_MAX]; + char *url; + + if (state == 0) { + memcpy(buffer, base, baselen); + strcpy(buffer+baselen, pathname); + url = cgit_pageurl(cgit_query_repo, "tree", + fmt("h=%s&path=%s", curr_rev, buffer)); + htmlf(" / <a href='"); + html_attr(url); + html("'>"); + html_txt(xstrdup(pathname)); + html("</a>"); + + if (strcmp(match_path, buffer)) + return READ_TREE_RECURSIVE; + + if (S_ISDIR(mode)) { + state = 1; + ls_head(); + return READ_TREE_RECURSIVE; + } else { + print_object(sha1, buffer); + return 0; + } + } + ls_item(sha1, base, baselen, pathname, mode, stage); + return 0; +} + + +/* + * Show a tree or a blob + * rev: the commit pointing at the root tree object + * path: path to tree or blob + */ +void cgit_print_tree(const char *rev, char *path) +{ unsigned char sha1[20]; struct commit *commit; + const char *paths[] = {path, NULL}; + + if (!rev) + rev = cgit_query_head; curr_rev = xstrdup(rev); - get_sha1(rev, sha1); + if (get_sha1(rev, sha1)) { + cgit_print_error(fmt("Invalid revision name: %s", rev)); + return; + } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { - cgit_print_error(fmt("Invalid head: %s", rev)); + cgit_print_error(fmt("Invalid commit reference: %s", rev)); return; } - if (!hex) - hex = sha1_to_hex(commit->tree->object.sha1); - if (get_sha1_hex(hex, sha1)) { - cgit_print_error(fmt("Invalid object id: %s", hex)); - return; - } - tree = parse_tree_indirect(sha1); - if (!tree) { - cgit_print_error(fmt("Not a tree object: %s", hex)); + html("path: <a href='"); + html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); + html("'>root</a>"); + + if (path == NULL) { + ls_tree(commit->tree->object.sha1, NULL); return; } - html_txt(path); - html("<table 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"); - read_tree_recursive(tree, "", 0, 1, NULL, print_entry); - html("</table>\n"); + match_path = path; + read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); + ls_tail(); } diff --git a/ui-view.c b/ui-view.c deleted file mode 100644 index 8873415..0000000 --- a/ui-view.c +++ b/dev/null @@ -1,55 +0,0 @@ -/* ui-view.c: functions to output _any_ object, given it's sha1 - * - * Copyright (C) 2006 Lars Hjemli - * - * Licensed under GNU General Public License v2 - * (see COPYING for full license text) - */ - -#include "cgit.h" - -void cgit_print_view(const char *hex, char *path) -{ - unsigned char sha1[20]; - enum object_type type; - unsigned char *buf; - unsigned long size; - - if (get_sha1_hex(hex, sha1)){ - cgit_print_error(fmt("Bad hex value: %s", hex)); - return; - } - - type = sha1_object_info(sha1, &size); - if (type == OBJ_BAD) { - cgit_print_error(fmt("Bad object name: %s", hex)); - return; - } - - buf = read_sha1_file(sha1, &type, &size); - if (!buf) { - cgit_print_error(fmt("Error reading object %s", hex)); - return; - } - - buf[size] = '\0'; - html("<table class='list'>\n"); - html("<tr class='nohover'><th class='left'>"); - if (path) - htmlf("%s (", path); - htmlf("%s %s, %li bytes", typename(type), hex, size); - if (path) - html(")"); - - html(" <a href='"); - html_attr(cgit_pageurl(cgit_query_repo, "blob", - fmt("id=%s&path=%s", - hex, - path))); - html("'>download</a>"); - html("</th></tr>\n"); - html("<tr><td class='blob'>\n"); - html_txt(buf); - html("\n</td></tr>\n"); - html("</table>\n"); -} |