-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgitrc.5.txt | 4 | ||||
-rw-r--r-- | ui-blob.c | 35 | ||||
-rw-r--r-- | ui-blob.h | 1 | ||||
-rw-r--r-- | ui-summary.c | 26 |
5 files changed, 63 insertions, 7 deletions
@@ -1,138 +1,140 @@ /* cgit.c: cgi for the git scm * * Copyright (C) 2006 Lars Hjemli + * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" #include "cache.h" #include "cmd.h" #include "configfile.h" #include "html.h" #include "ui-shared.h" #include "ui-stats.h" #include "scan-tree.h" const char *cgit_version = CGIT_VERSION; void add_mimetype(const char *name, const char *value) { struct string_list_item *item; item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); item->util = xstrdup(value); } struct cgit_filter *new_filter(const char *cmd, int extra_args) { struct cgit_filter *f; if (!cmd || !cmd[0]) return NULL; f = xmalloc(sizeof(struct cgit_filter)); f->cmd = xstrdup(cmd); f->argv = xmalloc((2 + extra_args) * sizeof(char *)); f->argv[0] = f->cmd; f->argv[1] = NULL; return f; } static void process_cached_repolist(const char *path); void repo_config(struct cgit_repo *repo, const char *name, const char *value) { if (!strcmp(name, "name")) repo->name = xstrdup(value); else if (!strcmp(name, "clone-url")) repo->clone_url = xstrdup(value); else if (!strcmp(name, "desc")) repo->desc = xstrdup(value); else if (!strcmp(name, "owner")) repo->owner = xstrdup(value); else if (!strcmp(name, "defbranch")) repo->defbranch = xstrdup(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-log-filecount")) repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); else if (!strcmp(name, "enable-log-linecount")) repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); else if (!strcmp(name, "enable-remote-branches")) repo->enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) repo->enable_subject_links = atoi(value); else if (!strcmp(name, "max-stats")) repo->max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "module-link")) repo->module_link= xstrdup(value); else if (!strcmp(name, "section")) repo->section = xstrdup(value); else if (!strcmp(name, "readme") && value != NULL) { - if (*value == '/') + char *colon; + if (*value == '/' || ((colon = strchr(value, ':')) != NULL && colon != value && *(colon + 1) != '\0')) repo->readme = xstrdup(value); else repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); } else if (ctx.cfg.enable_filter_overrides) { if (!strcmp(name, "about-filter")) repo->about_filter = new_filter(value, 0); else if (!strcmp(name, "commit-filter")) repo->commit_filter = new_filter(value, 0); else if (!strcmp(name, "source-filter")) repo->source_filter = new_filter(value, 1); } } void config_cb(const char *name, const char *value) { if (!strcmp(name, "section") || !strcmp(name, "repo.group")) ctx.cfg.section = xstrdup(value); else if (!strcmp(name, "repo.url")) ctx.repo = cgit_add_repo(value); else if (ctx.repo && !strcmp(name, "repo.path")) ctx.repo->path = trim_end(value, '/'); else if (ctx.repo && !prefixcmp(name, "repo.")) repo_config(ctx.repo, name + 5, value); else if (!strcmp(name, "root-title")) ctx.cfg.root_title = xstrdup(value); else if (!strcmp(name, "root-desc")) ctx.cfg.root_desc = xstrdup(value); else if (!strcmp(name, "root-readme")) ctx.cfg.root_readme = xstrdup(value); else if (!strcmp(name, "css")) ctx.cfg.css = xstrdup(value); else if (!strcmp(name, "favicon")) ctx.cfg.favicon = xstrdup(value); else if (!strcmp(name, "footer")) ctx.cfg.footer = xstrdup(value); else if (!strcmp(name, "head-include")) ctx.cfg.head_include = xstrdup(value); else if (!strcmp(name, "header")) ctx.cfg.header = xstrdup(value); else if (!strcmp(name, "logo")) ctx.cfg.logo = xstrdup(value); else if (!strcmp(name, "index-header")) ctx.cfg.index_header = xstrdup(value); else if (!strcmp(name, "index-info")) ctx.cfg.index_info = xstrdup(value); else if (!strcmp(name, "logo-link")) ctx.cfg.logo_link = xstrdup(value); else if (!strcmp(name, "module-link")) ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "virtual-root")) { ctx.cfg.virtual_root = trim_end(value, '/'); if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) ctx.cfg.virtual_root = ""; } else if (!strcmp(name, "nocache")) ctx.cfg.nocache = atoi(value); else if (!strcmp(name, "noplainemail")) ctx.cfg.noplainemail = atoi(value); else if (!strcmp(name, "noheader")) ctx.cfg.noheader = atoi(value); else if (!strcmp(name, "snapshots")) ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-filter-overrides")) ctx.cfg.enable_filter_overrides = atoi(value); else if (!strcmp(name, "enable-gitweb-owner")) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 5d77973..c643fae 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -310,129 +310,131 @@ summary-tags:: virtual-root:: Url which, if specified, will be used as root for all cgit links. It will also cause cgit to generate 'virtual urls', i.e. urls like '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default value: none. NOTE: cgit has recently learned how to use PATH_INFO to achieve the same kind of virtual urls, so this option will probably be deprecated. REPOSITORY SETTINGS ------------------- repo.about-filter:: Override the default about-filter. Default value: none. See also: "enable-filter-overrides". repo.clone-url:: A list of space-separated urls which can be used to clone this repo. Default value: none. repo.commit-filter:: Override the default commit-filter. Default value: none. See also: "enable-filter-overrides". repo.defbranch:: The name of the default branch for this repository. If no such branch exists in the repository, the first branch name (when sorted) is used as default instead. Default value: "master". repo.desc:: The value to show as repository description. Default value: none. repo.enable-log-filecount:: A flag which can be used to disable the global setting `enable-log-filecount'. Default value: none. repo.enable-log-linecount:: A flag which can be used to disable the global setting `enable-log-linecount'. Default value: none. repo.enable-remote-branches:: Flag which, when set to "1", will make cgit display remote branches in the summary and refs views. Default value: <enable-remote-branches>. repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. repo.max-stats:: Override the default maximum statistics period. Valid values are equal to the values specified for the global "max-stats" setting. Default value: none. repo.name:: The value to show as repository name. Default value: <repo.url>. repo.owner:: A value used to identify the owner of the repository. Default value: none. repo.path:: An absolute path to the repository directory. For non-bare repositories this is the .git-directory. Default value: none. repo.readme:: A path (relative to <repo.path>) which specifies a file to include - verbatim as the "About" page for this repo. Default value: none. + verbatim as the "About" page for this repo. You may also specify a + git refspec by head or by hash by prepending the refspec followed by + a colon. For example, "master:docs/readme.mkd" Default value: none. repo.snapshots:: A mask of allowed snapshot-formats for this repo, restricted by the "snapshots" global setting. Default value: <snapshots>. repo.section:: Override the current section name for this repository. Default value: none. repo.source-filter:: Override the default source-filter. Default value: none. See also: "enable-filter-overrides". repo.url:: The relative url used to access the repository. This must be the first setting specified for each repo. Default value: none. REPOSITORY-SPECIFIC CGITRC FILE ------------------------------- When the option "scan-path" is used to auto-discover git repositories, cgit will try to parse the file "cgitrc" within any found repository. Such a repo-specific config file may contain any of the repo-specific options described above, except "repo.url" and "repo.path". Additionally, the "filter" options are only acknowledged in repo-specific config files when "enable-filter-overrides" is set to "1". Note: the "repo." prefix is dropped from the option names in repo-specific config files, e.g. "repo.desc" becomes "desc". EXAMPLE CGITRC FILE ------------------- .... # Enable caching of up to 1000 output entriess cache-size=1000 # Specify some default clone prefixes clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git # Specify the css url css=/css/cgit.css # Show extra links for each repository on the index page enable-index-links=1 # Show number of affected files per commit on the log pages enable-log-filecount=1 # Show number of added/removed lines per commit on the log pages enable-log-linecount=1 # Add a cgit favicon favicon=/favicon.ico # Use a custom logo logo=/img/mylogo.png @@ -1,79 +1,112 @@ /* ui-blob.c: show blob content * * Copyright (C) 2008 Lars Hjemli + * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" #include "html.h" #include "ui-shared.h" static char *match_path; static unsigned char *matched_sha1; +static int found_path; static int walk_tree(const unsigned char *sha1, const char *base,int baselen, const char *pathname, unsigned mode, int stage, void *cbdata) { if(strncmp(base,match_path,baselen) || strcmp(match_path+baselen,pathname) ) return READ_TREE_RECURSIVE; memmove(matched_sha1,sha1,20); + found_path = 1; return 0; } -void cgit_print_blob(const char *hex, char *path, const char *head) +int cgit_print_file(char *path, const char *head) { + unsigned char sha1[20]; + enum object_type type; + char *buf; + unsigned long size; + struct commit *commit; + const char *paths[] = {path, NULL}; + if (get_sha1(head, sha1)) + return -1; + type = sha1_object_info(sha1, &size); + if(type == OBJ_COMMIT && path) { + commit = lookup_commit_reference(sha1); + match_path = path; + matched_sha1 = sha1; + found_path = 0; + read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); + if (!found_path) + return -1; + type = sha1_object_info(sha1, &size); + } + if (type == OBJ_BAD) + return -1; + buf = read_sha1_file(sha1, &type, &size); + if (!buf) + return -1; + buf[size] = '\0'; + write(htmlfd, buf, size); + return 0; +} +void cgit_print_blob(const char *hex, char *path, const char *head) +{ unsigned char sha1[20]; enum object_type type; char *buf; unsigned long size; struct commit *commit; const char *paths[] = {path, NULL}; if (hex) { if (get_sha1_hex(hex, sha1)){ cgit_print_error(fmt("Bad hex value: %s", hex)); return; } } else { if (get_sha1(head,sha1)) { cgit_print_error(fmt("Bad ref: %s", head)); return; } } type = sha1_object_info(sha1, &size); if((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(sha1); match_path = path; matched_sha1 = sha1; read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); 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'; ctx.page.mimetype = ctx.qry.mimetype; if (!ctx.page.mimetype) { if (buffer_is_binary(buf, size)) ctx.page.mimetype = "application/octet-stream"; else ctx.page.mimetype = "text/plain"; } ctx.page.filename = path; cgit_print_http_headers(&ctx); write(htmlfd, buf, size); } @@ -1,6 +1,7 @@ #ifndef UI_BLOB_H #define UI_BLOB_H +extern int cgit_print_file(char *path, const char *head); extern void cgit_print_blob(const char *hex, char *path, const char *head); #endif /* UI_BLOB_H */ diff --git a/ui-summary.c b/ui-summary.c index a2c018e..02f191e 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -1,92 +1,110 @@ /* ui-summary.c: functions for generating repo summary page * * Copyright (C) 2006 Lars Hjemli + * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" #include "html.h" #include "ui-log.h" #include "ui-refs.h" +#include "ui-blob.h" int urls = 0; static void print_url(char *base, char *suffix) { if (!base || !*base) return; if (urls++ == 0) { html("<tr class='nohover'><td colspan='4'> </td></tr>"); html("<tr><th class='left' colspan='4'>Clone</th></tr>\n"); } if (suffix && *suffix) base = fmt("%s/%s", base, suffix); html("<tr><td colspan='4'><a href='"); html_url_path(base); html("'>"); html_txt(base); html("</a></td></tr>\n"); } static void print_urls(char *txt, char *suffix) { char *h = txt, *t, c; while (h && *h) { while (h && *h == ' ') h++; t = h; while (t && *t && *t != ' ') t++; c = *t; *t = 0; print_url(h, suffix); *t = c; h = t; } } void cgit_print_summary() { html("<table summary='repository info' class='list nowrap'>"); cgit_print_branches(ctx.cfg.summary_branches); html("<tr class='nohover'><td colspan='4'> </td></tr>"); cgit_print_tags(ctx.cfg.summary_tags); if (ctx.cfg.summary_log > 0) { html("<tr class='nohover'><td colspan='4'> </td></tr>"); cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, NULL, NULL, 0); } if (ctx.repo->clone_url) print_urls(ctx.repo->clone_url, NULL); else if (ctx.cfg.clone_prefix) print_urls(ctx.cfg.clone_prefix, ctx.repo->url); html("</table>"); } void cgit_print_repo_readme(char *path) { - char *slash, *tmp; + char *slash, *tmp, *colon, *ref = 0; if (!ctx.repo->readme) return; if (path) { slash = strrchr(ctx.repo->readme, '/'); - if (!slash) - return; + if (!slash) { + slash = strchr(ctx.repo->readme, ':'); + if (!slash) + return; + } tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); strcpy(tmp + (slash - ctx.repo->readme + 1), path); } else tmp = ctx.repo->readme; + colon = strchr(tmp, ':'); + if (colon && strlen(colon) > 1) { + *colon = '\0'; + ref = tmp; + tmp = colon + 1; + while ((*tmp == '/' || *tmp == ':') && *tmp != '\0') + ++tmp; + if (!(*tmp)) + return; + } html("<div id='summary'>"); if (ctx.repo->about_filter) cgit_open_filter(ctx.repo->about_filter); - html_include(tmp); + if (ref) + cgit_print_file(tmp, ref); + else + html_include(tmp); if (ctx.repo->about_filter) cgit_close_filter(ctx.repo->about_filter); html("</div>"); } |