| -rw-r--r-- | Makefile | 14 | ||||
| -rw-r--r-- | cache.c | 53 | ||||
| -rw-r--r-- | cgit.c | 156 | ||||
| -rw-r--r-- | cgit.css | 14 | ||||
| -rw-r--r-- | cgit.h | 52 | ||||
| -rw-r--r-- | cgit.js | 68 | ||||
| -rw-r--r-- | cgitrc.5.txt | 25 | ||||
| -rw-r--r-- | filter.c | 12 | ||||
| -rwxr-xr-x | filters/commit-links.sh | 2 | ||||
| -rwxr-xr-x | filters/html-converters/md2html | 7 | ||||
| m--------- | git | 0 | ||||
| -rw-r--r-- | html.c | 2 | ||||
| -rw-r--r-- | parsing.c | 17 | ||||
| -rw-r--r-- | robots.txt | 1 | ||||
| -rw-r--r-- | scan-tree.c | 43 | ||||
| -rw-r--r-- | scan-tree.h | 4 | ||||
| -rw-r--r-- | shared.c | 54 | ||||
| -rwxr-xr-x | tests/setup.sh | 12 | ||||
| -rwxr-xr-x | tests/t0105-commit.sh | 2 | ||||
| -rwxr-xr-x | tests/t0107-snapshot.sh | 17 | ||||
| -rw-r--r-- | ui-atom.c | 38 | ||||
| -rw-r--r-- | ui-blame.c | 41 | ||||
| -rw-r--r-- | ui-blob.c | 42 | ||||
| -rw-r--r-- | ui-clone.c | 54 | ||||
| -rw-r--r-- | ui-commit.c | 7 | ||||
| -rw-r--r-- | ui-diff.c | 20 | ||||
| -rw-r--r-- | ui-log.c | 27 | ||||
| -rw-r--r-- | ui-patch.c | 12 | ||||
| -rw-r--r-- | ui-plain.c | 19 | ||||
| -rw-r--r-- | ui-refs.c | 11 | ||||
| -rw-r--r-- | ui-repolist.c | 4 | ||||
| -rw-r--r-- | ui-shared.c | 105 | ||||
| -rw-r--r-- | ui-shared.h | 3 | ||||
| -rw-r--r-- | ui-snapshot.c | 16 | ||||
| -rw-r--r-- | ui-stats.c | 63 | ||||
| -rw-r--r-- | ui-tag.c | 6 | ||||
| -rw-r--r-- | ui-tree.c | 61 |
37 files changed, 405 insertions, 679 deletions
@@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v1.3.1 +CGIT_VERSION = v1.2.3 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.54.0 +GIT_VER = 2.29.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r @@ -87,7 +87,6 @@ install: all $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css - $(INSTALL) -m 0644 cgit.js $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png $(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico $(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt @@ -108,20 +107,11 @@ install-pdf: doc-pdf $(INSTALL) -m 0755 -d $(DESTDIR)$(pdfdir) $(INSTALL) -m 0644 $(DOC_PDF) $(DESTDIR)$(pdfdir) -define rm_f -rm -f $(1) - -endef - uninstall: rm -f $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) rm -f $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css - rm -f $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js rm -f $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png rm -f $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico - rm -f $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt - $(foreach file,$(patsubst filters/%,%,$(shell find filters/ ! -type d)), \ - $(call rm_f,$(DESTDIR)$(filterdir)/$(file))) uninstall-doc: uninstall-man uninstall-html uninstall-pdf @@ -85,45 +85,40 @@ static int close_slot(struct cache_slot *slot) /* Print the content of the active cache slot (but skip the key). */ static int print_slot(struct cache_slot *slot) { - off_t off; #ifdef HAVE_LINUX_SENDFILE - off_t size; -#endif - - off = slot->keylen + 1; + off_t start_off; + int ret; -#ifdef HAVE_LINUX_SENDFILE - size = slot->cache_st.st_size; + start_off = slot->keylen + 1; do { - ssize_t ret; - ret = sendfile(STDOUT_FILENO, slot->cache_fd, &off, size - off); + ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off, + slot->cache_st.st_size - start_off); if (ret < 0) { if (errno == EAGAIN || errno == EINTR) continue; - /* Fall back to read/write on EINVAL or ENOSYS */ - if (errno == EINVAL || errno == ENOSYS) - break; return errno; } - if (off == size) - return 0; + return 0; } while (1); -#endif +#else + ssize_t i, j; - if (lseek(slot->cache_fd, off, SEEK_SET) != off) + i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); + if (i != slot->keylen + 1) return errno; do { - ssize_t ret; - ret = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); - if (ret < 0) - return errno; - if (ret == 0) - return 0; - if (write_in_full(STDOUT_FILENO, slot->buf, ret) < 0) - return errno; - } while (1); + i = j = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); + if (i > 0) + j = xwrite(STDOUT_FILENO, slot->buf, i); + } while (i > 0 && j == i); + + if (i < 0 || j != i) + return errno; + else + return 0; +#endif } /* Check if the slot has expired */ @@ -185,8 +180,6 @@ static int lock_slot(struct cache_slot *slot) slot->lock_fd = -1; return saved_errno; } - if (ftruncate(slot->lock_fd, 0) < 0) - return errno; if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0) return errno; return 0; @@ -408,12 +401,12 @@ int cache_process(int size, const char *path, const char *key, int ttl, static char *sprintftime(const char *format, time_t time) { static char buf[64]; - struct tm tm; + struct tm *tm; if (!time) return NULL; - gmtime_r(&time, &tm); - strftime(buf, sizeof(buf)-1, format, &tm); + tm = gmtime(&time); + strftime(buf, sizeof(buf)-1, format, tm); return buf; } @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "cache.h" #include "cmd.h" @@ -41,33 +39,31 @@ static void add_mimetype(const char *name, const char *value) static void process_cached_repolist(const char *path); -void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *value) +static void repo_config(struct cgit_repo *repo, const char *name, const char *value) { const char *path; struct string_list_item *item; if (!strcmp(name, "name")) - repo->name = strdup_first_line(value); + repo->name = xstrdup(value); else if (!strcmp(name, "clone-url")) - repo->clone_url = strdup_first_line(value); + repo->clone_url = xstrdup(value); else if (!strcmp(name, "desc")) - repo->desc = strdup_first_line(value); + repo->desc = xstrdup(value); else if (!strcmp(name, "owner")) - repo->owner = strdup_first_line(value); + repo->owner = xstrdup(value); else if (!strcmp(name, "homepage")) - repo->homepage = strdup_first_line(value); + repo->homepage = xstrdup(value); else if (!strcmp(name, "defbranch")) - repo->defbranch = strdup_first_line(value); + repo->defbranch = xstrdup(value); else if (!strcmp(name, "extra-head-content")) - repo->extra_head_content = strdup_first_line(value); + repo->extra_head_content = xstrdup(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-blame")) repo->enable_blame = atoi(value); else if (!strcmp(name, "enable-commit-graph")) repo->enable_commit_graph = atoi(value); - else if (!strcmp(name, "enable-follow-links")) - repo->enable_follow_links = atoi(value); else if (!strcmp(name, "enable-log-filecount")) repo->enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) @@ -91,22 +87,22 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu } else if (!strcmp(name, "max-stats")) repo->max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "module-link")) - repo->module_link= strdup_first_line(value); + repo->module_link= xstrdup(value); else if (skip_prefix(name, "module-link.", &path)) { - item = string_list_append(&repo->submodules, strdup_first_line(path)); - item->util = strdup_first_line(value); + item = string_list_append(&repo->submodules, xstrdup(path)); + item->util = xstrdup(value); } else if (!strcmp(name, "section")) - repo->section = strdup_first_line(value); + repo->section = xstrdup(value); else if (!strcmp(name, "snapshot-prefix")) - repo->snapshot_prefix = strdup_first_line(value); + repo->snapshot_prefix = xstrdup(value); else if (!strcmp(name, "readme") && value != NULL) { if (repo->readme.items == ctx.cfg.readme.items) memset(&repo->readme, 0, sizeof(repo->readme)); - string_list_append(&repo->readme, strdup_first_line(value)); + string_list_append(&repo->readme, xstrdup(value)); } else if (!strcmp(name, "logo") && value != NULL) - repo->logo = strdup_first_line(value); + repo->logo = xstrdup(value); else if (!strcmp(name, "logo-link") && value != NULL) - repo->logo_link = strdup_first_line(value); + repo->logo_link = xstrdup(value); else if (!strcmp(name, "hide")) repo->hide = atoi(value); else if (!strcmp(name, "ignore")) @@ -130,41 +126,39 @@ static void config_cb(const char *name, const char *value) const char *arg; if (!strcmp(name, "section")) - ctx.cfg.section = strdup_first_line(value); + 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 && skip_prefix(name, "repo.", &arg)) - cgit_repo_config(ctx.repo, arg, value); + repo_config(ctx.repo, arg, value); else if (!strcmp(name, "readme")) - string_list_append(&ctx.cfg.readme, strdup_first_line(value)); + string_list_append(&ctx.cfg.readme, xstrdup(value)); else if (!strcmp(name, "root-title")) - ctx.cfg.root_title = strdup_first_line(value); + ctx.cfg.root_title = xstrdup(value); else if (!strcmp(name, "root-desc")) - ctx.cfg.root_desc = strdup_first_line(value); + ctx.cfg.root_desc = xstrdup(value); else if (!strcmp(name, "root-readme")) - ctx.cfg.root_readme = strdup_first_line(value); + ctx.cfg.root_readme = xstrdup(value); else if (!strcmp(name, "css")) - string_list_append(&ctx.cfg.css, strdup_first_line(value)); - else if (!strcmp(name, "js")) - string_list_append(&ctx.cfg.js, strdup_first_line(value)); + ctx.cfg.css = xstrdup(value); else if (!strcmp(name, "favicon")) - ctx.cfg.favicon = strdup_first_line(value); + ctx.cfg.favicon = xstrdup(value); else if (!strcmp(name, "footer")) - ctx.cfg.footer = strdup_first_line(value); + ctx.cfg.footer = xstrdup(value); else if (!strcmp(name, "head-include")) - ctx.cfg.head_include = strdup_first_line(value); + ctx.cfg.head_include = xstrdup(value); else if (!strcmp(name, "header")) - ctx.cfg.header = strdup_first_line(value); + ctx.cfg.header = xstrdup(value); else if (!strcmp(name, "logo")) - ctx.cfg.logo = strdup_first_line(value); + ctx.cfg.logo = xstrdup(value); else if (!strcmp(name, "logo-link")) - ctx.cfg.logo_link = strdup_first_line(value); + ctx.cfg.logo_link = xstrdup(value); else if (!strcmp(name, "module-link")) - ctx.cfg.module_link = strdup_first_line(value); + ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "strict-export")) - ctx.cfg.strict_export = strdup_first_line(value); + ctx.cfg.strict_export = xstrdup(value); else if (!strcmp(name, "virtual-root")) ctx.cfg.virtual_root = ensure_end(value, '/'); else if (!strcmp(name, "noplainemail")) @@ -206,7 +200,7 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "cache-size")) ctx.cfg.cache_size = atoi(value); else if (!strcmp(name, "cache-root")) - ctx.cfg.cache_root = strdup_first_line(expand_macros(value)); + ctx.cfg.cache_root = xstrdup(expand_macros(value)); else if (!strcmp(name, "cache-root-ttl")) ctx.cfg.cache_root_ttl = atoi(value); else if (!strcmp(name, "cache-repo-ttl")) @@ -243,28 +237,26 @@ static void config_cb(const char *name, const char *value) ctx.cfg.max_repodesc_len = atoi(value); else if (!strcmp(name, "max-blob-size")) ctx.cfg.max_blob_size = atoi(value); - else if (!strcmp(name, "max-repo-count")) { + else if (!strcmp(name, "max-repo-count")) ctx.cfg.max_repo_count = atoi(value); - if (ctx.cfg.max_repo_count <= 0) - ctx.cfg.max_repo_count = INT_MAX; - } else if (!strcmp(name, "max-commit-count")) + else if (!strcmp(name, "max-commit-count")) ctx.cfg.max_commit_count = atoi(value); else if (!strcmp(name, "project-list")) - ctx.cfg.project_list = strdup_first_line(expand_macros(value)); + ctx.cfg.project_list = xstrdup(expand_macros(value)); else if (!strcmp(name, "scan-path")) if (ctx.cfg.cache_size) process_cached_repolist(expand_macros(value)); else if (ctx.cfg.project_list) scan_projects(expand_macros(value), - ctx.cfg.project_list); + ctx.cfg.project_list, repo_config); else - scan_tree(expand_macros(value)); + scan_tree(expand_macros(value), repo_config); else if (!strcmp(name, "scan-hidden-path")) ctx.cfg.scan_hidden_path = atoi(value); else if (!strcmp(name, "section-from-path")) ctx.cfg.section_from_path = atoi(value); else if (!strcmp(name, "repository-sort")) - ctx.cfg.repository_sort = strdup_first_line(value); + ctx.cfg.repository_sort = xstrdup(value); else if (!strcmp(name, "section-sort")) ctx.cfg.section_sort = atoi(value); else if (!strcmp(name, "source-filter")) @@ -278,19 +270,19 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "side-by-side-diffs")) ctx.cfg.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED; else if (!strcmp(name, "agefile")) - ctx.cfg.agefile = strdup_first_line(value); + ctx.cfg.agefile = xstrdup(value); else if (!strcmp(name, "mimetype-file")) - ctx.cfg.mimetype_file = strdup_first_line(value); + ctx.cfg.mimetype_file = xstrdup(value); else if (!strcmp(name, "renamelimit")) ctx.cfg.renamelimit = atoi(value); else if (!strcmp(name, "remove-suffix")) ctx.cfg.remove_suffix = atoi(value); else if (!strcmp(name, "robots")) - ctx.cfg.robots = strdup_first_line(value); + ctx.cfg.robots = xstrdup(value); else if (!strcmp(name, "clone-prefix")) - ctx.cfg.clone_prefix = strdup_first_line(value); + ctx.cfg.clone_prefix = xstrdup(value); else if (!strcmp(name, "clone-url")) - ctx.cfg.clone_url = strdup_first_line(value); + ctx.cfg.clone_url = xstrdup(value); else if (!strcmp(name, "local-time")) ctx.cfg.local_time = atoi(value); else if (!strcmp(name, "commit-sort")) { @@ -384,6 +376,7 @@ static void prepare_context(void) ctx.cfg.case_sensitive_sort = 1; ctx.cfg.branch_sort = 0; ctx.cfg.commit_sort = 0; + ctx.cfg.css = "/cgit.css"; ctx.cfg.logo = "/cgit.png"; ctx.cfg.favicon = "/favicon.ico"; ctx.cfg.local_time = 0; @@ -435,7 +428,7 @@ static void prepare_context(void) ctx.page.modified = time(NULL); ctx.page.expires = ctx.page.modified; ctx.page.etag = NULL; - string_list_init_dup(&ctx.cfg.mimetypes); + string_list_init(&ctx.cfg.mimetypes, 1); if (ctx.env.script_name) ctx.cfg.script_name = xstrdup(ctx.env.script_name); if (ctx.env.query_string) @@ -450,15 +443,16 @@ struct refmatch { int match; }; -static int find_current_ref(const struct reference *ref, void *cb_data) +static int find_current_ref(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { struct refmatch *info; info = (struct refmatch *)cb_data; - if (!strcmp(ref->name, info->req_ref)) + if (!strcmp(refname, info->req_ref)) info->match = 1; if (!info->first_ref) - info->first_ref = xstrdup(ref->name); + info->first_ref = xstrdup(refname); return info->match; } @@ -476,8 +470,7 @@ static char *find_default_branch(struct cgit_repo *repo) info.req_ref = repo->defbranch; info.first_ref = NULL; info.match = 0; - refs_for_each_branch_ref(get_main_ref_store(the_repository), - find_current_ref, &info); + for_each_branch_ref(find_current_ref, &info); if (info.match) ref = info.req_ref; else @@ -494,8 +487,7 @@ static char *guess_defbranch(void) const char *ref, *refname; struct object_id oid; - ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, &oid, NULL); + ref = resolve_ref_unsafe("HEAD", 0, &oid, NULL); if (!ref || !skip_prefix(ref, "refs/heads/", &refname)) return "master"; return xstrdup(refname); @@ -515,11 +507,9 @@ static inline void parse_readme(const char *readme, char **filename, char **ref, /* Check if the readme is tracked in the git repo. */ colon = strchr(readme, ':'); if (colon && strlen(colon) > 1) { - /* If it starts with a colon, we want to use head given - * from query or the default branch */ - if (colon == readme && ctx.qry.head) - *ref = xstrdup(ctx.qry.head); - else if (colon == readme && repo->defbranch) + /* If it starts with a colon, we want to use + * the default branch */ + if (colon == readme && repo->defbranch) *ref = xstrdup(repo->defbranch); else *ref = xstrndup(readme, colon - readme); @@ -636,7 +626,7 @@ static int prepare_repo_cmd(int nongit) return 1; } - if (repo_get_oid(the_repository, ctx.qry.head, &oid)) { + if (get_oid(ctx.qry.head, &oid)) { char *old_head = ctx.qry.head; ctx.qry.head = xstrdup(ctx.repo->defbranch); cgit_print_error_page(404, "Not found", @@ -786,6 +776,15 @@ static char *build_snapshot_setting(int bitmap) return strbuf_detach(&result, NULL); } +static char *get_first_line(char *txt) +{ + char *t = xstrdup(txt); + char *p = strchr(t, '\n'); + if (p) + *p = '\0'; + return t; +} + static void print_repo(FILE *f, struct cgit_repo *repo) { struct string_list_item *item; @@ -794,8 +793,11 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.path=%s\n", repo->path); if (repo->owner) fprintf(f, "repo.owner=%s\n", repo->owner); - if (repo->desc) - fprintf(f, "repo.desc=%s\n", repo->desc); + if (repo->desc) { + char *tmp = get_first_line(repo->desc); + fprintf(f, "repo.desc=%s\n", tmp); + free(tmp); + } for_each_string_list_item(item, &repo->readme) { if (item->util) fprintf(f, "repo.readme=%s:%s\n", (char *)item->util, item->string); @@ -818,8 +820,6 @@ static void print_repo(FILE *f, struct cgit_repo *repo) repo->enable_blame); fprintf(f, "repo.enable-commit-graph=%d\n", repo->enable_commit_graph); - fprintf(f, "repo.enable-follow-links=%d\n", - repo->enable_follow_links); fprintf(f, "repo.enable-log-filecount=%d\n", repo->enable_log_filecount); fprintf(f, "repo.enable-log-linecount=%d\n", @@ -896,9 +896,9 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) } idx = cgit_repolist.count; if (ctx.cfg.project_list) - scan_projects(path, ctx.cfg.project_list); + scan_projects(path, ctx.cfg.project_list, repo_config); else - scan_tree(path); + scan_tree(path, repo_config); print_repolist(f, &cgit_repolist, idx); if (rename(locked_rc.buf, cached_rc)) fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", @@ -928,9 +928,10 @@ static void process_cached_repolist(const char *path) */ if (generate_cached_repolist(path, cached_rc.buf)) { if (ctx.cfg.project_list) - scan_projects(path, ctx.cfg.project_list); + scan_projects(path, ctx.cfg.project_list, + repo_config); else - scan_tree(path); + scan_tree(path, repo_config); } goto out; } @@ -1011,7 +1012,7 @@ static void cgit_parse_args(int argc, const char **argv) */ ctx.cfg.snapshots = 0xFF; scan++; - scan_tree(arg); + scan_tree(arg, repo_config); } } if (scan) { @@ -1045,12 +1046,6 @@ static int calc_ttl(void) return ctx.cfg.cache_repo_ttl; } -static NORETURN void cgit_die_routine(const char *msg, va_list params) -{ - cgit_vprint_error_page(400, "Bad request", msg, params); - exit(0); -} - int cmd_main(int argc, const char **argv) { const char *path; @@ -1058,7 +1053,6 @@ int cmd_main(int argc, const char **argv) cgit_init_filters(); atexit(cgit_cleanup_filters); - set_die_routine(cgit_die_routine); prepare_context(); cgit_repolist.length = 0; @@ -330,11 +330,6 @@ div#cgit table.ssdiff td.lineno a:hover { color: black; } -div#cgit table.blob td.linenumbers a:target:before { - color: red; - content: "\2BA9"; -} - div#cgit table.blame td.hashes, div#cgit table.blame td.lines, div#cgit table.blame td.linenumbers { @@ -368,10 +363,6 @@ div#cgit table.blame td.lines > div > pre { top: 0; } -div#cgit table.blame .oid { - font-size: 100%; -} - div#cgit table.bin-blob { margin-top: 0.5em; border: solid 1px black; @@ -684,7 +675,6 @@ div#cgit a.branch-deco { padding: 0px 0.25em; background-color: #88ff88; border: solid 1px #007700; - border-radius: 2px; } div#cgit a.tag-deco { @@ -693,7 +683,6 @@ div#cgit a.tag-deco { padding: 0px 0.25em; background-color: #ffff88; border: solid 1px #777700; - border-radius: 2px; } div#cgit a.tag-annotated-deco { @@ -702,7 +691,6 @@ div#cgit a.tag-annotated-deco { padding: 0px 0.25em; background-color: #ffcc88; border: solid 1px #777700; - border-radius: 2px; } div#cgit a.remote-deco { @@ -711,7 +699,6 @@ div#cgit a.remote-deco { padding: 0px 0.25em; background-color: #ccccff; border: solid 1px #000077; - border-radius: 2px; } div#cgit a.deco { @@ -720,7 +707,6 @@ div#cgit a.deco { padding: 0px 0.25em; background-color: #ff8888; border: solid 1px #770000; - border-radius: 2px; } div#cgit div.commit-subject a.branch-deco, @@ -1,35 +1,30 @@ #ifndef CGIT_H #define CGIT_H -#include <stdbool.h> #include <git-compat-util.h> +#include <stdbool.h> -#include <archive.h> -#include <commit.h> -#include <diffcore.h> -#include <diff.h> -#include <environment.h> -#include <graph.h> +#include <cache.h> #include <grep.h> -#include <hex.h> -#include <log-tree.h> -#include <notes.h> #include <object.h> -#include <object-name.h> -#include <odb.h> -#include <path.h> +#include <object-store.h> +#include <tree.h> +#include <commit.h> +#include <tag.h> +#include <diff.h> +#include <diffcore.h> +#include <strvec.h> #include <refs.h> #include <revision.h> -#include <setup.h> +#include <log-tree.h> +#include <archive.h> #include <string-list.h> -#include <strvec.h> -#include <tag.h> -#include <tree.h> -#include <utf8.h> -#include <wrapper.h> #include <xdiff-interface.h> #include <xdiff/xdiff.h> +#include <utf8.h> +#include <notes.h> +#include <graph.h> /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */ #undef isgraph @@ -69,7 +64,7 @@ typedef enum { struct cgit_filter { int (*open)(struct cgit_filter *, va_list ap); int (*close)(struct cgit_filter *); - void (*fprintfp)(struct cgit_filter *, FILE *, const char *prefix); + void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix); void (*cleanup)(struct cgit_filter *); int argument_count; }; @@ -101,7 +96,6 @@ struct cgit_repo { int snapshots; int enable_blame; int enable_commit_graph; - int enable_follow_links; int enable_log_filecount; int enable_log_linecount; int enable_remote_branches; @@ -121,6 +115,9 @@ struct cgit_repo { int ignore; }; +typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, + const char *value); + struct cgit_repolist { int length; int count; @@ -198,6 +195,7 @@ struct cgit_config { char *cache_root; char *clone_prefix; char *clone_url; + char *css; char *favicon; char *footer; char *head_include; @@ -208,7 +206,6 @@ struct cgit_config { char *module_link; char *project_list; struct string_list readme; - struct string_list css; char *robots; char *root_title; char *root_desc; @@ -267,7 +264,6 @@ struct cgit_config { int branch_sort; int commit_sort; struct string_list mimetypes; - struct string_list js; struct cgit_filter *about_filter; struct cgit_filter *commit_filter; struct cgit_filter *source_filter; @@ -331,8 +327,7 @@ extern const struct cgit_snapshot_format cgit_snapshot_formats[]; extern char *cgit_default_repo_desc; extern struct cgit_repo *cgit_add_repo(const char *url); extern struct cgit_repo *cgit_get_repoinfo(const char *url); -extern void cgit_repo_config(struct cgit_repo *repo, const char *name, - const char *value); +extern void cgit_repo_config_cb(const char *name, const char *value); extern int chk_zero(int result, char *msg); extern int chk_positive(int result, char *msg); @@ -345,7 +340,8 @@ extern void strbuf_ensure_end(struct strbuf *sb, char c); extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); extern void cgit_free_reflist_inner(struct reflist *list); -extern int cgit_refs_cb(const struct reference *ref, void *cb_data); +extern int cgit_refs_cb(const char *refname, const struct object_id *oid, + int flags, void *cb_data); extern void cgit_free_commitinfo(struct commitinfo *info); extern void cgit_free_taginfo(struct taginfo *info); @@ -393,9 +389,7 @@ extern void cgit_init_filters(void); extern void cgit_prepare_repo_env(struct cgit_repo * repo); -extern int read_first_line(const char *path, char **buf, size_t *size); - -extern char *strdup_first_line(const char *txt); +extern int readfile(const char *path, char **buf, size_t *size); extern char *expand_macros(const char *txt); diff --git a/cgit.js b/cgit.js deleted file mode 100644 index df3ad4e..0000000 --- a/cgit.js +++ /dev/null @@ -1,68 +0,0 @@ -/* cgit.js: javacript functions for cgit - * - * Copyright (C) 2006-2018 cgit Development Team <cgit@lists.zx2c4.com> - * - * Licensed under GNU General Public License v2 - * (see COPYING for full license text) - */ - -(function () { - -/* This follows the logic and suffixes used in ui-shared.c */ - -var age_classes = [ "age-mins", "age-hours", "age-days", "age-weeks", "age-months", "age-years" ]; -var age_suffix = [ "min.", "hours", "days", "weeks", "months", "years", "years" ]; -var age_next = [ 60, 3600, 24 * 3600, 7 * 24 * 3600, 30 * 24 * 3600, 365 * 24 * 3600, 365 * 24 * 3600 ]; -var age_limit = [ 7200, 24 * 7200, 7 * 24 * 7200, 30 * 24 * 7200, 365 * 25 * 7200, 365 * 25 * 7200 ]; -var update_next = [ 10, 5 * 60, 1800, 24 * 3600, 24 * 3600, 24 * 3600, 24 * 3600 ]; - -function render_age(e, age) { - var t, n; - - for (n = 0; n < age_classes.length; n++) - if (age < age_limit[n]) - break; - - t = Math.round(age / age_next[n]) + " " + age_suffix[n]; - - if (e.textContent != t) { - e.textContent = t; - if (n == age_classes.length) - n--; - if (e.className != age_classes[n]) - e.className = age_classes[n]; - } -} - -function aging() { - var n, next = 24 * 3600, - now_ut = Math.round((new Date().getTime() / 1000)); - - for (n = 0; n < age_classes.length; n++) { - var m, elems = document.getElementsByClassName(age_classes[n]); - - if (elems.length && update_next[n] < next) - next = update_next[n]; - - for (m = 0; m < elems.length; m++) { - var age = now_ut - elems[m].getAttribute("data-ut"); - - render_age(elems[m], age); - } - } - - /* - * We only need to come back when the age might have changed. - * Eg, if everything is counted in hours already, once per - * 5 minutes is accurate enough. - */ - - window.setTimeout(aging, next * 1000); -} - -document.addEventListener("DOMContentLoaded", function() { - /* we can do the aging on DOM content load since no layout dependency */ - aging(); -}, false); - -})(); diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 7c39bf9..33a6a8c 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -126,8 +126,7 @@ commit-sort:: css:: Url which specifies the css document to include in all cgit pages. - Default value: "/cgit.css". May be given multiple times, each - css URL path is added in the head section of the document in turn. + Default value: "/cgit.css". email-filter:: Specifies a command which will be invoked to format names and email @@ -239,11 +238,6 @@ include:: Name of a configfile to include before the rest of the current config- file is parsed. Default value: none. See also: "MACRO EXPANSION". -js:: - Url which specifies the javascript script document to include in all cgit - pages. Default value: "/cgit.js". Setting this to an empty string will - disable generation of the link to this file in the head section. - local-time:: Flag which, if set to "1", makes cgit print commit and tag times in the servers timezone. Default value: "0". @@ -275,8 +269,7 @@ max-message-length:: max-repo-count:: Specifies the number of entries to list per page on the repository - index page. The value "0" shows all repositories without limitation. - Default value: "50". + index page. Default value: "50". max-repodesc-length:: Specifies the maximum number of repo description characters to display @@ -503,10 +496,6 @@ repo.enable-commit-graph:: A flag which can be used to disable the global setting `enable-commit-graph'. Default value: none. -repo.enable-follow-links:: - A flag which can be used to disable the global setting - `enable-follow-links'. Default value: none. - repo.enable-html-serving:: A flag which can be used to override the global setting `enable-html-serving`. Default value: none. @@ -590,11 +579,11 @@ repo.readme:: 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". If the value begins - with a colon, i.e. ":docs/readme.rst", the head giving in query or - the default branch of the repository will be used. Sharing any file - will expose that entire directory tree to the "/about/PATH" endpoints, - so be sure that there are no non-public files located in the same - directory as the readme file. Default value: <readme>. + with a colon, i.e. ":docs/readme.rst", the default branch of the + repository will be used. Sharing any file will expose that entire + directory tree to the "/about/PATH" endpoints, so be sure that there + are no non-public files located in the same directory as the readme + file. Default value: <readme>. repo.section:: Override the current section name for this repository. Default value: @@ -114,7 +114,7 @@ static struct cgit_filter *new_exec_filter(const char *cmd, int argument_count) f = xmalloc(sizeof(*f)); /* We leave argv for now and assign it below. */ - cgit_exec_filter_init(f, strdup_first_line(cmd), NULL); + cgit_exec_filter_init(f, xstrdup(cmd), NULL); f->base.argument_count = argument_count; args_size = (2 + argument_count) * sizeof(char *); f->argv = xmalloc(args_size); @@ -128,7 +128,7 @@ void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **ar memset(filter, 0, sizeof(*filter)); filter->base.open = open_exec_filter; filter->base.close = close_exec_filter; - filter->base.fprintfp = fprintf_exec_filter; + filter->base.fprintf = fprintf_exec_filter; filter->base.cleanup = cleanup_exec_filter; filter->cmd = cmd; filter->argv = argv; @@ -353,10 +353,10 @@ static struct cgit_filter *new_lua_filter(const char *cmd, int argument_count) memset(filter, 0, sizeof(*filter)); filter->base.open = open_lua_filter; filter->base.close = close_lua_filter; - filter->base.fprintfp = fprintf_lua_filter; + filter->base.fprintf = fprintf_lua_filter; filter->base.cleanup = cleanup_lua_filter; filter->base.argument_count = argument_count; - filter->script_file = strdup_first_line(cmd); + filter->script_file = xstrdup(cmd); return &filter->base; } @@ -385,7 +385,7 @@ int cgit_close_filter(struct cgit_filter *filter) void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix) { - filter->fprintfp(filter, f, prefix); + filter->fprintf(filter, f, prefix); } @@ -402,7 +402,7 @@ static const struct { struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) { - const char *colon; + char *colon; int i; size_t len; int argument_count; diff --git a/filters/commit-links.sh b/filters/commit-links.sh index 796ac30..5881952 100755 --- a/filters/commit-links.sh +++ b/filters/commit-links.sh @@ -19,7 +19,7 @@ regex='' # This expression generates links to commits referenced by their SHA1. regex=$regex' -s|\b([0-9a-fA-F]{7,64})\b|<a href="./?id=\1">\1</a>|g' +s|\b([0-9a-fA-F]{7,40})\b|<a href="./?id=\1">\1</a>|g' # This expression generates links to a fictional bugtracker. regex=$regex' diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index 59f43a8..dc20f42 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -86,7 +86,11 @@ div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div# margin: 15px 0; } .markdown-body hr { - border: 2px solid #ccc; + background: transparent url("/dirty-shade.png") repeat-x 0 0; + border: 0 none; + color: #ccc; + height: 4px; + padding: 0; } .markdown-body>h2:first-child, .markdown-body>h1:first-child, .markdown-body>h1:first-child+h2, .markdown-body>h3:first-child, .markdown-body>h4:first-child, .markdown-body>h5:first-child, .markdown-body>h6:first-child { margin-top: 0; @@ -297,7 +301,6 @@ markdown.markdownFromFile( "markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables", - "markdown.extensions.sane_lists", TocExtension(anchorlink=True)], extension_configs={ "markdown.extensions.codehilite":{"css_class":"highlight"}}) diff --git a/git b/git -Subproject 94f057755b7941b321fd11fec1b2e3ca5313a4e +Subproject 69986e19ffcfb9af674ae5180689ab7bbf92ed2 @@ -59,7 +59,7 @@ char *fmt(const char *format, ...) va_start(args, format); len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); va_end(args); - if (len >= sizeof(buf[bufidx])) { + if (len > sizeof(buf[bufidx])) { fprintf(stderr, "[html.c] string truncated: %s\n", format); exit(1); } @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" /* @@ -19,7 +17,7 @@ */ void cgit_parse_url(const char *url) { - char *c, *cmd, *p, *buf; + char *c, *cmd, *p; struct cgit_repo *repo; if (!url || url[0] == '\0') @@ -32,12 +30,11 @@ void cgit_parse_url(const char *url) return; } - buf = xstrdup(url); cmd = NULL; - c = strchr(buf, '/'); + c = strchr(url, '/'); while (c) { c[0] = '\0'; - repo = cgit_get_repoinfo(buf); + repo = cgit_get_repoinfo(url); if (repo) { ctx.repo = repo; cmd = c; @@ -57,7 +54,6 @@ void cgit_parse_url(const char *url) if (cmd[1]) ctx.qry.page = xstrdup(cmd + 1); } - free(buf); } static char *substr(const char *head, const char *tail) @@ -131,6 +127,7 @@ static int end_of_header(const char *p) struct commitinfo *cgit_parse_commit(struct commit *commit) { + const int oid_hex_len = 40; struct commitinfo *ret; const char *p = repo_get_commit_buffer(the_repository, commit, NULL); const char *t; @@ -143,10 +140,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) if (!skip_prefix(p, "tree ", &p)) die("Bad commit: %s", oid_to_hex(&commit->object.oid)); - p += the_hash_algo->hexsz + 1; + p += oid_hex_len + 1; while (skip_prefix(p, "parent ", &p)) - p += the_hash_algo->hexsz + 1; + p += oid_hex_len + 1; if (p && skip_prefix(p, "author ", &p)) { parse_user(p, &ret->author, &ret->author_email, @@ -202,7 +199,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) const char *p; struct taginfo *ret = NULL; - data = odb_read_object(the_repository->objects, &tag->object.oid, &type, &size); + data = read_object_file(&tag->object.oid, &type, &size); if (!data || type != OBJ_TAG) goto cleanup; @@ -1,4 +1,3 @@ User-agent: * Disallow: /*/snapshot/* -Disallow: /*/blame/* Allow: / diff --git a/scan-tree.c b/scan-tree.c index c120efe..6a2f65a 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -47,27 +47,27 @@ out: } static struct cgit_repo *repo; +static repo_config_fn config_fn; static void scan_tree_repo_config(const char *name, const char *value) { - cgit_repo_config(repo, name, value); + config_fn(repo, name, value); } -static int gitconfig_config(const char *key, const char *value, - const __attribute__((unused)) struct config_context *ctx, void *cb) +static int gitconfig_config(const char *key, const char *value, void *cb) { const char *name; if (!strcmp(key, "gitweb.owner")) - cgit_repo_config(repo, "owner", value); + config_fn(repo, "owner", value); else if (!strcmp(key, "gitweb.description")) - cgit_repo_config(repo, "desc", value); + config_fn(repo, "desc", value); else if (!strcmp(key, "gitweb.category")) - cgit_repo_config(repo, "section", value); + config_fn(repo, "section", value); else if (!strcmp(key, "gitweb.homepage")) - cgit_repo_config(repo, "homepage", value); + config_fn(repo, "homepage", value); else if (skip_prefix(key, "cgit.", &name)) - cgit_repo_config(repo, name, value); + config_fn(repo, name, value); return 0; } @@ -79,7 +79,7 @@ static char *xstrrchr(char *s, char *from, int c) return from < s ? NULL : from; } -static void add_repo(const char *base, struct strbuf *path) +static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) { struct stat st; struct passwd *pwd; @@ -121,6 +121,7 @@ static void add_repo(const char *base, struct strbuf *path) strbuf_setlen(&rel, rel.len - 1); repo = cgit_add_repo(rel.buf); + config_fn = fn; if (ctx.cfg.enable_git_config) { strbuf_addstr(path, "config"); git_config_from_file(gitconfig_config, path->buf, NULL); @@ -133,7 +134,7 @@ static void add_repo(const char *base, struct strbuf *path) strip_suffix_mem(repo->url, &urllen, "/"); repo->url[urllen] = '\0'; } - repo->path = strdup_first_line(path->buf); + repo->path = xstrdup(path->buf); while (!repo->owner) { if ((pwd = getpwuid(st.st_uid)) == NULL) { fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", @@ -143,13 +144,13 @@ static void add_repo(const char *base, struct strbuf *path) if (pwd->pw_gecos) if ((p = strchr(pwd->pw_gecos, ','))) *p = '\0'; - repo->owner = strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); + repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); } if (repo->desc == cgit_default_repo_desc || !repo->desc) { strbuf_addstr(path, "description"); if (!stat(path->buf, &st)) - read_first_line(path->buf, &repo->desc, &size); + readfile(path->buf, &repo->desc, &size); strbuf_setlen(path, pathlen); } @@ -166,7 +167,7 @@ static void add_repo(const char *base, struct strbuf *path) } if (slash && !n) { *slash = '\0'; - repo->section = strdup_first_line(rel.buf); + repo->section = xstrdup(rel.buf); *slash = '/'; if (starts_with(repo->name, repo->section)) { repo->name += strlen(repo->section); @@ -183,7 +184,7 @@ static void add_repo(const char *base, struct strbuf *path) strbuf_release(&rel); } -static void scan_path(const char *base, const char *path) +static void scan_path(const char *base, const char *path, repo_config_fn fn) { DIR *dir = opendir(path); struct dirent *ent; @@ -199,12 +200,12 @@ static void scan_path(const char *base, const char *path) strbuf_add(&pathbuf, path, strlen(path)); if (is_git_dir(pathbuf.buf)) { - add_repo(base, &pathbuf); + add_repo(base, &pathbuf, fn); goto end; } strbuf_addstr(&pathbuf, "/.git"); if (is_git_dir(pathbuf.buf)) { - add_repo(base, &pathbuf); + add_repo(base, &pathbuf, fn); goto end; } /* @@ -229,14 +230,14 @@ static void scan_path(const char *base, const char *path) continue; } if (S_ISDIR(st.st_mode)) - scan_path(base, pathbuf.buf); + scan_path(base, pathbuf.buf, fn); } end: strbuf_release(&pathbuf); closedir(dir); } -void scan_projects(const char *path, const char *projectsfile) +void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) { struct strbuf line = STRBUF_INIT; FILE *projects; @@ -253,7 +254,7 @@ void scan_projects(const char *path, const char *projectsfile) continue; strbuf_insert(&line, 0, "/", 1); strbuf_insert(&line, 0, path, strlen(path)); - scan_path(path, line.buf); + scan_path(path, line.buf, fn); } if ((err = ferror(projects))) { fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", @@ -263,7 +264,7 @@ void scan_projects(const char *path, const char *projectsfile) strbuf_release(&line); } -void scan_tree(const char *path) +void scan_tree(const char *path, repo_config_fn fn) { - scan_path(path, path); + scan_path(path, path, fn); } diff --git a/scan-tree.h b/scan-tree.h index def0a7a..1afbd4b 100644 --- a/scan-tree.h +++ b/scan-tree.h @@ -1,2 +1,2 @@ -extern void scan_projects(const char *path, const char *projectsfile); -extern void scan_tree(const char *path); +extern void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn); +extern void scan_tree(const char *path, repo_config_fn fn); @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" struct cgit_repolist cgit_repolist; @@ -52,7 +50,6 @@ struct cgit_repo *cgit_add_repo(const char *url) ret = &cgit_repolist.repos[cgit_repolist.count-1]; memset(ret, 0, sizeof(struct cgit_repo)); ret->url = trim_end(url, '/'); - *strchrnul(ret->url, '\n') = '\0'; ret->name = ret->url; ret->path = NULL; ret->desc = cgit_default_repo_desc; @@ -63,7 +60,6 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->snapshots = ctx.cfg.snapshots; ret->enable_blame = ctx.cfg.enable_blame; ret->enable_commit_graph = ctx.cfg.enable_commit_graph; - ret->enable_follow_links = ctx.cfg.enable_follow_links; ret->enable_log_filecount = ctx.cfg.enable_log_filecount; ret->enable_log_linecount = ctx.cfg.enable_log_linecount; ret->enable_remote_branches = ctx.cfg.enable_remote_branches; @@ -214,10 +210,11 @@ void cgit_free_reflist_inner(struct reflist *list) free(list->refs); } -int cgit_refs_cb(const struct reference *ref, void *cb_data) +int cgit_refs_cb(const char *refname, const struct object_id *oid, int flags, + void *cb_data) { struct reflist *list = (struct reflist *)cb_data; - struct refinfo *info = cgit_mk_refinfo(ref->name, ref->oid); + struct refinfo *info = cgit_mk_refinfo(refname, oid); if (info) cgit_add_ref(list, info); @@ -244,7 +241,7 @@ static int load_mmfile(mmfile_t *file, const struct object_id *oid) file->ptr = (char *)""; file->size = 0; } else { - file->ptr = odb_read_object(the_repository->objects, oid, &type, + file->ptr = read_object_file(oid, &type, (unsigned long *)&file->size); } return 1; @@ -344,9 +341,10 @@ void cgit_diff_tree(const struct object_id *old_oid, filepair_fn fn, const char *prefix, int ignorews) { struct diff_options opt; - struct pathspec_item *item; + struct pathspec_item item; - repo_diff_setup(the_repository, &opt); + memset(&item, 0, sizeof(item)); + diff_setup(&opt); opt.output_format = DIFF_FORMAT_CALLBACK; opt.detect_rename = 1; opt.rename_limit = ctx.cfg.renamelimit; @@ -356,11 +354,10 @@ void cgit_diff_tree(const struct object_id *old_oid, opt.format_callback = cgit_diff_tree_cb; opt.format_callback_data = fn; if (prefix) { - item = xcalloc(1, sizeof(*item)); - item->match = xstrdup(prefix); - item->len = strlen(prefix); + item.match = xstrdup(prefix); + item.len = strlen(prefix); opt.pathspec.nr = 1; - opt.pathspec.items = item; + opt.pathspec.items = &item; } diff_setup_done(&opt); @@ -370,6 +367,8 @@ void cgit_diff_tree(const struct object_id *old_oid, diff_root_tree_oid(new_oid, "", &opt); diffcore_std(&opt); diff_flush(&opt); + + free(item.match); } void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) @@ -396,7 +395,7 @@ int cgit_parse_snapshots_mask(const char *str) if (strcmp(str, "all") == 0) return INT_MAX; - string_list_split(&tokens, str, " ", -1); + string_list_split(&tokens, str, ' ', -1); string_list_remove_empty_items(&tokens, 0); for_each_string_list_item(item, &tokens) { @@ -441,10 +440,9 @@ void cgit_prepare_repo_env(struct cgit_repo * repo) } /* Read the content of the specified file into a newly allocated buffer, - * zeroterminate the buffer, truncate at a new line, and return 0 on success, - * errno otherwise. + * zeroterminate the buffer and return 0 on success, errno otherwise. */ -int read_first_line(const char *path, char **buf, size_t *size) +int readfile(const char *path, char **buf, size_t *size) { int fd, e; struct stat st; @@ -465,18 +463,10 @@ int read_first_line(const char *path, char **buf, size_t *size) *size = read_in_full(fd, *buf, st.st_size); e = errno; (*buf)[*size] = '\0'; - *strchrnul(*buf, '\n') = '\0'; close(fd); return (*size == st.st_size ? 0 : e); } -char *strdup_first_line(const char *txt) -{ - char *t = xstrdup(txt); - *strchrnul(t, '\n') = '\0'; - return t; -} - static int is_token_char(char c) { return isalnum(c) || c == '_'; @@ -551,10 +541,7 @@ char *expand_macros(const char *txt) char *get_mimetype_for_filename(const char *filename) { - const char *ext; - char *mimetype, line[1024]; - struct string_list list = STRING_LIST_INIT_NODUP; - int i; + char *ext, *mimetype, *token, line[1024], *saveptr; FILE *file; struct string_list_item *mime; @@ -579,16 +566,13 @@ char *get_mimetype_for_filename(const char *filename) while (fgets(line, sizeof(line), file)) { if (!line[0] || line[0] == '#') continue; - string_list_split_in_place(&list, line, " \t\r\n", -1); - string_list_remove_empty_items(&list, 0); - mimetype = list.items[0].string; - for (i = 1; i < list.nr; i++) { - if (!strcasecmp(ext, list.items[i].string)) { + mimetype = strtok_r(line, " \t\r\n", &saveptr); + while ((token = strtok_r(NULL, " \t\r\n", &saveptr))) { + if (!strcasecmp(ext, token)) { fclose(file); return xstrdup(mimetype); } } - string_list_clear(&list, 0); } fclose(file); return NULL; diff --git a/tests/setup.sh b/tests/setup.sh index 8db810f..5879348 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -80,17 +80,13 @@ mkrepo() { git commit -m "commit $n" n=$(expr $n + 1) done - case "$3" in - testplus) + if test "$3" = "testplus" + then echo "hello" >a+b git add a+b git commit -m "add a+b" git branch "1+2" - ;; - commit-graph) - git commit-graph write - ;; - esac + fi ) } @@ -99,7 +95,7 @@ setup_repos() rm -rf cache mkdir -p cache mkrepo repos/foo 5 >/dev/null - mkrepo repos/bar 50 commit-graph >/dev/null + mkrepo repos/bar 50 >/dev/null mkrepo repos/foo+bar 10 testplus >/dev/null mkrepo "repos/with space" 2 >/dev/null mkrepo repos/filter 5 testplus >/dev/null diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh index 1a12ee3..9cdf55c 100755 --- a/tests/t0105-commit.sh +++ b/tests/t0105-commit.sh @@ -25,7 +25,7 @@ test_expect_success 'get root commit' ' ' test_expect_success 'root commit contains diffstat' ' - grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40,64\}.>file-1</a>" tmp + grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" tmp ' test_expect_success 'root commit contains diff' ' diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index 0811ec4..c164d3e 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh @@ -25,7 +25,7 @@ test_expect_success 'verify gzip format' ' test_expect_success 'untar' ' rm -rf master && - gzip -dc master.tar.gz | tar -xf - + tar -xzf master.tar.gz ' test_expect_success 'count files' ' @@ -61,12 +61,13 @@ test_expect_success LZIP 'strip off the header lines' ' ' test_expect_success LZIP 'verify lzip format' ' - lzip --test master.tar.lz + lzip --test master.tar.lz && + cp master.tar.lz /tmp/. ' test_expect_success LZIP 'untar' ' rm -rf master && - lzip -dc master.tar.lz | tar -xf - + tar --lzip -xf master.tar.lz ' test_expect_success LZIP 'count files' ' @@ -102,12 +103,13 @@ test_expect_success XZ 'strip off the header lines' ' ' test_expect_success XZ 'verify xz format' ' - xz --test master.tar.xz + xz --test master.tar.xz && + cp master.tar.xz /tmp/. ' test_expect_success XZ 'untar' ' rm -rf master && - xz -dc master.tar.xz | tar -xf - + tar --xz -xf master.tar.xz ' test_expect_success XZ 'count files' ' @@ -143,12 +145,13 @@ test_expect_success ZSTD 'strip off the header lines' ' ' test_expect_success ZSTD 'verify zstd format' ' - zstd --test master.tar.zst + zstd --test master.tar.zst && + cp master.tar.zst /tmp/. ' test_expect_success ZSTD 'untar' ' rm -rf master && - zstd -dc master.tar.zst | tar -xf - + tar --zstd -xf master.tar.zst ' test_expect_success ZSTD 'count files' ' @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-atom.h" #include "html.h" @@ -69,12 +67,17 @@ static void add_entry(struct commit *commit, const char *host) html("'/>\n"); free(pageurl); } - html("<id>"); - html_txtf("urn:%s:%s", the_hash_algo->name, hex); - html("</id>\n"); + htmlf("<id>%s</id>\n", hex); html("<content type='text'>\n"); html_txt(info->msg); html("</content>\n"); + html("<content type='xhtml'>\n"); + html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); + html("<pre>\n"); + html_txt(info->msg); + html("</pre>\n"); + html("</div>\n"); + html("</content>\n"); html("</entry>\n"); cgit_free_commitinfo(info); } @@ -87,7 +90,6 @@ void cgit_print_atom(char *tip, const char *path, int max_count) struct commit *commit; struct rev_info rev; int argc = 2; - bool first = true; if (ctx.qry.show_all) argv[1] = "--all"; @@ -99,7 +101,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count) argv[argc++] = path; } - repo_init_revisions(the_repository, &rev, NULL); + init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.verbose_header = 1; @@ -128,30 +130,18 @@ void cgit_print_atom(char *tip, const char *path, int max_count) html_txt(ctx.repo->desc); html("</subtitle>\n"); if (host) { - char *fullurl = cgit_currentfullurl(); char *repourl = cgit_repourl(ctx.repo->url); - html("<id>"); - html_txtf("%s%s%s", cgit_httpscheme(), host, fullurl); - html("</id>\n"); - html("<link rel='self' href='"); - html_attrf("%s%s%s", cgit_httpscheme(), host, fullurl); - html("'/>\n"); html("<link rel='alternate' type='text/html' href='"); - html_attrf("%s%s%s", cgit_httpscheme(), host, repourl); + html(cgit_httpscheme()); + html_attr(host); + html_attr(repourl); html("'/>\n"); - free(fullurl); free(repourl); } while ((commit = get_revision(&rev)) != NULL) { - if (first) { - html("<updated>"); - html_txt(show_date(commit->date, 0, - date_mode_from_type(DATE_ISO8601_STRICT))); - html("</updated>\n"); - first = false; - } add_entry(commit, host); - release_commit_memory(the_repository->parsed_objects, commit); + free_commit_buffer(the_repository->parsed_objects, commit); + free_commit_list(commit->parents); commit->parents = NULL; } html("</feed>\n"); @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-blame.h" #include "html.h" @@ -51,20 +49,11 @@ static void emit_blame_entry_hash(struct blame_entry *ent) char *detail = emit_suspect_detail(suspect); html("<span class='oid'>"); - cgit_commit_link(repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV), detail, + cgit_commit_link(find_unique_abbrev(oid, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); html("</span>"); free(detail); - if (!repo_parse_commit(the_repository, suspect->commit) && suspect->commit->parents) { - struct commit *parent = suspect->commit->parents->item; - - html(" "); - cgit_blame_link("^", "Blame the previous revision", NULL, - ctx.qry.head, oid_to_hex(&parent->object.oid), - suspect->path); - } - while (line++ < ent->num_lines) html("\n"); } @@ -121,14 +110,14 @@ static void print_object(const struct object_id *oid, const char *path, struct blame_origin *o; struct blame_entry *ent = NULL; - type = odb_read_object_info(the_repository->objects, oid, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not found", "Bad object name: %s", oid_to_hex(oid)); return; } - buf = odb_read_object(the_repository->objects, oid, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", oid_to_hex(oid)); @@ -137,14 +126,13 @@ static void print_object(const struct object_id *oid, const char *path, strvec_push(&rev_argv, "blame"); strvec_push(&rev_argv, rev); - repo_init_revisions(the_repository, &revs, NULL); + init_revisions(&revs, NULL); revs.diffopt.flags.allow_textconv = 1; setup_revisions(rev_argv.nr, rev_argv.v, &revs, NULL); init_scoreboard(&sb); sb.revs = &revs; sb.repo = the_repository; - sb.path = path; - setup_scoreboard(&sb, &o); + setup_scoreboard(&sb, path, &o); o->suspects = blame_entry_prepend(NULL, 0, sb.num_lines, o); prio_queue_put(&sb.commits, o->commit); blame_origin_decref(o); @@ -163,10 +151,6 @@ static void print_object(const struct object_id *oid, const char *path, cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); html(")\n"); - if (buffer_is_binary(buf, size)) { - html("<div class='error'>blob is binary.</div>"); - goto cleanup; - } if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { htmlf("<div class='error'>blob size (%ldKB)" " exceeds display size limit (%dKB).</div>", @@ -236,7 +220,8 @@ cleanup: } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *cbdata) + const char *pathname, unsigned mode, int stage, + void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -263,7 +248,7 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, static int basedir_len(const char *path) { - const char *p = strrchr(path, '/'); + char *p = strrchr(path, '/'); if (p) return p - path + 1; return 0; @@ -289,13 +274,13 @@ void cgit_print_blame(void) if (!rev) rev = ctx.qry.head; - if (repo_get_oid(the_repository, rev, &oid)) { + if (get_oid(rev, &oid)) { cgit_print_error_page(404, "Not found", "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(the_repository, &oid); - if (!commit || repo_parse_commit(the_repository, commit)) { + if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); return; @@ -305,8 +290,10 @@ void cgit_print_blame(void) walk_tree_ctx.match_baselen = (path_items.match) ? basedir_len(path_items.match) : -1; - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.state) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.state == 2) @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-blob.h" #include "html.h" @@ -21,7 +19,7 @@ struct walk_tree_context { }; static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *cbdata) + const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -54,13 +52,13 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) .file_only = file_only }; - if (repo_get_oid(the_repository, ref, &oid)) + if (get_oid(ref, &oid)) goto done; - if (odb_read_object_info(the_repository->objects, &oid, &size) != OBJ_COMMIT) + if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree(the_repository, - repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -89,20 +87,22 @@ int cgit_print_file(char *path, const char *head, int file_only) .file_only = file_only }; - if (repo_get_oid(the_repository, head, &oid)) + if (get_oid(head, &oid)) return -1; - type = odb_read_object_info(the_repository->objects, &oid, &size); + type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { commit = lookup_commit_reference(the_repository, &oid); - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; - type = odb_read_object_info(the_repository->objects, &oid, &size); + type = oid_object_info(the_repository, &oid, &size); } if (type == OBJ_BAD) return -1; - buf = odb_read_object(the_repository->objects, &oid, &type, &size); + buf = read_object_file(&oid, &type, &size); if (!buf) return -1; buf[size] = '\0'; @@ -140,20 +140,22 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } } else { - if (repo_get_oid(the_repository, head, &oid)) { + if (get_oid(head, &oid)) { cgit_print_error_page(404, "Not found", "Bad ref: %s", head); return; } } - type = odb_read_object_info(the_repository->objects, &oid, &size); + type = oid_object_info(the_repository, &oid, &size); if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(the_repository, &oid); - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk_tree_ctx); - type = odb_read_object_info(the_repository->objects, &oid, &size); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); + type = oid_object_info(the_repository, &oid, &size); } if (type == OBJ_BAD) { @@ -162,7 +164,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } - buf = odb_read_object(the_repository->objects, &oid, &type, &size); + buf = read_object_file(&oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", hex); @@ -7,52 +7,47 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-clone.h" #include "html.h" #include "ui-shared.h" #include "packfile.h" +#include "object-store.h" -static int print_ref_info(const struct reference *ref, void *cb_data) +static int print_ref_info(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { struct object *obj; - if (!(obj = parse_object(the_repository, ref->oid))) + if (!(obj = parse_object(the_repository, oid))) return 0; - htmlf("%s\t%s\n", oid_to_hex(ref->oid), ref->name); + htmlf("%s\t%s\n", oid_to_hex(oid), refname); if (obj->type == OBJ_TAG) { - if (!(obj = deref_tag(the_repository, obj, ref->name, 0))) + if (!(obj = deref_tag(the_repository, obj, refname, 0))) return 0; - htmlf("%s\t%s^{}\n", oid_to_hex(&obj->oid), ref->name); + htmlf("%s\t%s^{}\n", oid_to_hex(&obj->oid), refname); } return 0; } static void print_pack_info(void) { - struct odb_source *source; + struct packed_git *pack; char *offset; ctx.page.mimetype = "text/plain"; ctx.page.filename = "objects/info/packs"; cgit_print_http_headers(); - odb_reprepare(the_repository->objects); - for (source = the_repository->objects->sources; source; source = source->next) { - struct odb_source_files *files = odb_source_files_downcast(source); - struct packfile_list_entry *e; - for (e = files->packed->packs.head; e; e = e->next) { - struct packed_git *p = e->pack; - if (p->pack_local) { - offset = strrchr(p->pack_name, '/'); - if (offset && offset[1] != '\0') - ++offset; - else - offset = p->pack_name; - htmlf("P %s\n", offset); - } + reprepare_packed_git(the_repository); + for (pack = get_packed_git(the_repository); pack; pack = pack->next) { + if (pack->pack_local) { + offset = strrchr(pack->pack_name, '/'); + if (offset && offset[1] != '\0') + ++offset; + else + offset = pack->pack_name; + htmlf("P %s\n", offset); } } } @@ -92,13 +87,12 @@ void cgit_clone_info(void) ctx.page.mimetype = "text/plain"; ctx.page.filename = "info/refs"; cgit_print_http_headers(); - refs_for_each_ref(get_main_ref_store(the_repository), - print_ref_info, NULL); + for_each_ref(print_ref_info, NULL); } void cgit_clone_objects(void) { - char *p, *path; + char *p; if (!ctx.qry.path) goto err; @@ -119,9 +113,7 @@ void cgit_clone_objects(void) goto err; } - path = repo_git_path(the_repository, "objects/%s", ctx.qry.path); - send_file(path); - free(path); + send_file(git_path("objects/%s", ctx.qry.path)); return; err: @@ -130,9 +122,5 @@ err: void cgit_clone_head(void) { - char *path; - - path = repo_git_path(the_repository, "HEAD"); - send_file(path); - free(path); + send_file(git_path("%s", "HEAD")); } diff --git a/ui-commit.c b/ui-commit.c index 972e9bc..948118c 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-commit.h" #include "html.h" @@ -28,7 +26,7 @@ void cgit_print_commit(char *hex, const char *prefix) if (!hex) hex = ctx.qry.head; - if (repo_get_oid(the_repository, hex, &oid)) { + if (get_oid(hex, &oid)) { cgit_print_error_page(400, "Bad request", "Bad object id: %s", hex); return; @@ -41,11 +39,10 @@ void cgit_print_commit(char *hex, const char *prefix) } info = cgit_parse_commit(commit); - format_display_notes(&oid, ¬es, PAGE_ENCODING, 1); + format_display_notes(&oid, ¬es, PAGE_ENCODING, 0); load_ref_decorations(NULL, DECORATE_FULL_REFS); - ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title); cgit_print_layout_start(); cgit_print_diff_ctrls(); html("<table summary='commit info' class='commit-info'>\n"); @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-diff.h" #include "html.h" @@ -260,8 +258,8 @@ static void header(const struct object_id *oid1, char *path1, int mode1, htmlf("<br/>deleted file mode %.6o", mode1); if (!subproject) { - abbrev1 = xstrdup(repo_find_unique_abbrev(the_repository, oid1, DEFAULT_ABBREV)); - abbrev2 = xstrdup(repo_find_unique_abbrev(the_repository, oid2, DEFAULT_ABBREV)); + abbrev1 = xstrdup(find_unique_abbrev(oid1, DEFAULT_ABBREV)); + abbrev2 = xstrdup(find_unique_abbrev(oid2, DEFAULT_ABBREV)); htmlf("<br/>index %s..%s", abbrev1, abbrev2); free(abbrev1); free(abbrev2); @@ -395,7 +393,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, * entire commit to detect renames so we must limit the paths in our * own callbacks and not pass the prefix to the diff machinery. */ - if (ctx.qry.follow && ctx.repo->enable_follow_links) { + if (ctx.qry.follow && ctx.cfg.enable_follow_links) { current_prefix = prefix; prefix = ""; } else { @@ -404,13 +402,13 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; - if (repo_get_oid(the_repository, new_rev, new_rev_oid)) { + if (get_oid(new_rev, new_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object name: %s", new_rev); return; } commit = lookup_commit_reference(the_repository, new_rev_oid); - if (!commit || repo_parse_commit(the_repository, commit)) { + if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(new_rev_oid)); return; @@ -418,7 +416,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, new_tree_oid = get_commit_tree_oid(commit); if (old_rev) { - if (repo_get_oid(the_repository, old_rev, old_rev_oid)) { + if (get_oid(old_rev, old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object name: %s", old_rev); return; @@ -426,12 +424,12 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, } else if (commit->parents && commit->parents->item) { oidcpy(old_rev_oid, &commit->parents->item->object.oid); } else { - oidclr(old_rev_oid, the_repository->hash_algo); + oidclr(old_rev_oid); } if (!is_null_oid(old_rev_oid)) { commit2 = lookup_commit_reference(the_repository, old_rev_oid); - if (!commit2 || repo_parse_commit(the_repository, commit2)) { + if (!commit2 || parse_commit(commit2)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(old_rev_oid)); return; @@ -444,7 +442,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (raw) { struct diff_options diffopt; - repo_diff_setup(the_repository, &diffopt); + diff_setup(&diffopt); diffopt.output_format = DIFF_FORMAT_PATCH; diffopt.flags.recursive = 1; diff_setup_done(&diffopt); @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-log.h" #include "html.h" @@ -67,9 +65,8 @@ void show_commit_decorations(struct commit *commit) return; html("<span class='decoration'>"); while (deco) { - struct object_id oid_tag, peeled; + struct object_id peeled; int is_annotated = 0; - strlcpy(buf, prettify_refname(deco->name), sizeof(buf)); switch(deco->type) { case DECORATION_NONE: @@ -82,9 +79,8 @@ void show_commit_decorations(struct commit *commit) ctx.qry.showmsg, 0); break; case DECORATION_REF_TAG: - if (!refs_read_ref(get_main_ref_store(the_repository), deco->name, &oid_tag) && - !peel_object(the_repository, &oid_tag, &peeled, PEEL_OBJECT_VERIFY_TAGGED_OBJECT_TYPE)) - is_annotated = !oideq(&oid_tag, &peeled); + if (!peel_ref(deco->name, &peeled)) + is_annotated = !oidcmp(&commit->object.oid, &peeled); cgit_tag_link(buf, NULL, is_annotated ? "tag-annotated-deco" : "tag-deco", buf); break; case DECORATION_REF_REMOTE: @@ -149,7 +145,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs) /* When we get here we have precisely one parent. */ parent = parents->item; /* If we can't parse the commit, let print_commit() report an error. */ - if (repo_parse_commit(the_repository, parent)) + if (parse_commit(parent)) return 1; files = 0; @@ -162,12 +158,11 @@ static int show_commit(struct commit *commit, struct rev_info *revs) "", &revs->diffopt); diffcore_std(&revs->diffopt); - found = !diff_queue_is_empty(&revs->diffopt); + found = !diff_queue_is_empty(); saved_fmt = revs->diffopt.output_format; revs->diffopt.output_format = DIFF_FORMAT_CALLBACK; revs->diffopt.format_callback = cgit_diff_tree_cb; revs->diffopt.format_callback_data = handle_rename; - revs->diffopt.no_free = 1; diff_flush(&revs->diffopt); revs->diffopt.output_format = saved_fmt; revs->diffopt.flags = saved_flags; @@ -334,7 +329,7 @@ static const char *disambiguate_ref(const char *ref, int *must_free_result) struct strbuf longref = STRBUF_INIT; strbuf_addf(&longref, "refs/heads/%s", ref); - if (repo_get_oid(the_repository, longref.buf, &oid) == 0) { + if (get_oid(longref.buf, &oid) == 0) { *must_free_result = 1; return strbuf_detach(&longref, NULL); } @@ -407,7 +402,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern } } - if (!path || !ctx.repo->enable_follow_links) { + if (!path || !ctx.cfg.enable_follow_links) { /* * If we don't have a path, "follow" is a no-op so make sure * the variable is set to false to avoid needing to check @@ -434,7 +429,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (path) strvec_push(&rev_argv, path); - repo_init_revisions(the_repository, &rev, NULL); + init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.verbose_header = 1; @@ -493,7 +488,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) { if (show_commit(commit, &rev)) i++; - release_commit_memory(the_repository->parsed_objects, commit); + free_commit_buffer(the_repository->parsed_objects, commit); + free_commit_list(commit->parents); commit->parents = NULL; } @@ -514,7 +510,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern i++; print_commit(commit, &rev); } - release_commit_memory(the_repository->parsed_objects, commit); + free_commit_buffer(the_repository->parsed_objects, commit); + free_commit_list(commit->parents); commit->parents = NULL; } if (pager) { @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-patch.h" #include "html.h" @@ -33,7 +31,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; - if (repo_get_oid(the_repository, new_rev, &new_rev_oid)) { + if (get_oid(new_rev, &new_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", new_rev); return; @@ -46,7 +44,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, } if (old_rev) { - if (repo_get_oid(the_repository, old_rev, &old_rev_oid)) { + if (get_oid(old_rev, &old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", old_rev); return; @@ -59,11 +57,11 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, } else if (commit->parents && commit->parents->item) { oidcpy(&old_rev_oid, &commit->parents->item->object.oid); } else { - oidclr(&old_rev_oid, the_repository->hash_algo); + oidclr(&old_rev_oid); } if (is_null_oid(&old_rev_oid)) { - memcpy(rev_range, oid_to_hex(&new_rev_oid), the_hash_algo->hexsz + 1); + memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1); } else { xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid), oid_to_hex(&new_rev_oid)); @@ -80,7 +78,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, "%s%n%n%w(0)%b"; } - repo_init_revisions(the_repository, &rev, NULL); + init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.verbose_header = 1; rev.diff = 1; @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-plain.h" #include "html.h" @@ -24,13 +22,13 @@ static int print_object(const struct object_id *oid, const char *path) char *buf, *mimetype; unsigned long size; - type = odb_read_object_info(the_repository->objects, oid, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not found", "Not found"); return 0; } - buf = odb_read_object(the_repository->objects, oid, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) { cgit_print_error_page(404, "Not found", "Not found"); return 0; @@ -132,7 +130,7 @@ static void print_dir_tail(void) } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *cbdata) + const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -157,7 +155,7 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, static int basedir_len(const char *path) { - const char *p = strrchr(path, '/'); + char *p = strrchr(path, '/'); if (p) return p - path + 1; return 0; @@ -183,12 +181,12 @@ void cgit_print_plain(void) if (!rev) rev = ctx.qry.head; - if (repo_get_oid(the_repository, rev, &oid)) { + if (get_oid(rev, &oid)) { cgit_print_error_page(404, "Not found", "Not found"); return; } commit = lookup_commit_reference(the_repository, &oid); - if (!commit || repo_parse_commit(the_repository, commit)) { + if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Not found"); return; } @@ -200,8 +198,9 @@ void cgit_print_plain(void) } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-refs.h" #include "html.h" @@ -157,11 +155,9 @@ void cgit_print_branches(int maxcount) list.refs = NULL; list.alloc = list.count = 0; - refs_for_each_branch_ref(get_main_ref_store(the_repository), - cgit_refs_cb, &list); + for_each_branch_ref(cgit_refs_cb, &list); if (ctx.repo->enable_remote_branches) - refs_for_each_remote_ref(get_main_ref_store(the_repository), - cgit_refs_cb, &list); + for_each_remote_ref(cgit_refs_cb, &list); if (maxcount == 0 || maxcount > list.count) maxcount = list.count; @@ -186,8 +182,7 @@ void cgit_print_tags(int maxcount) list.refs = NULL; list.alloc = list.count = 0; - refs_for_each_tag_ref(get_main_ref_store(the_repository), - cgit_refs_cb, &list); + for_each_tag_ref(cgit_refs_cb, &list); if (list.count == 0) return; qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); diff --git a/ui-repolist.c b/ui-repolist.c index 1b224cf..529a203 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -18,7 +18,7 @@ static time_t read_agefile(const char *path) char *buf = NULL; struct strbuf date_buf = STRBUF_INIT; - if (read_first_line(path, &buf, &size)) { + if (readfile(path, &buf, &size)) { free(buf); return 0; } @@ -321,7 +321,7 @@ void cgit_print_repolist(void) } htmlf("<tr><td class='%s'>", !sorted && section ? "sublevel-repo" : "toplevel-repo"); - cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); + cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); html("</td><td>"); repourl = cgit_repourl(ctx.repo->url); html_link_open(repourl, NULL, NULL); diff --git a/ui-shared.c b/ui-shared.c index df52a9b..151ac17 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-shared.h" #include "cmd.h" @@ -24,11 +22,10 @@ static char *http_date(time_t t) static char month[][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - struct tm tm; - gmtime_r(&t, &tm); - return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm.tm_wday], - tm.tm_mday, month[tm.tm_mon], 1900 + tm.tm_year, - tm.tm_hour, tm.tm_min, tm.tm_sec); + struct tm *tm = gmtime(&t); + return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], + tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year, + tm->tm_hour, tm->tm_min, tm->tm_sec); } void cgit_print_error(const char *fmt, ...) @@ -664,18 +661,18 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -const struct date_mode cgit_date_mode(enum date_mode_type type) +const struct date_mode *cgit_date_mode(enum date_mode_type type) { static struct date_mode mode; mode.type = type; mode.local = ctx.cfg.local_time; - return mode; + return &mode; } static void print_rel_date(time_t t, int tz, double value, const char *class, const char *suffix) { - htmlf("<span class='%s' data-ut='%" PRIu64 "' title='", class, (uint64_t)t); + htmlf("<span class='%s' title='", class); html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601))); htmlf("'>%.0f %s</span>", value, suffix); } @@ -770,38 +767,6 @@ static void print_rel_vcs_link(const char *url) html(" Git repository'/>\n"); } -static int emit_css_link(struct string_list_item *s, void *arg) -{ - /* Do not emit anything if css= is specified. */ - if (s && *s->string == '\0') - return 0; - - html("<link rel='stylesheet' type='text/css' href='"); - if (s) - html_attr(s->string); - else - html_attr((const char *)arg); - html("'/>\n"); - - return 0; -} - -static int emit_js_link(struct string_list_item *s, void *arg) -{ - /* Do not emit anything if js= is specified. */ - if (s && *s->string == '\0') - return 0; - - html("<script type='text/javascript' src='"); - if (s) - html_attr(s->string); - else - html_attr((const char *)arg); - html("'></script>\n"); - - return 0; -} - void cgit_print_docstart(void) { char *host = cgit_hosturl(); @@ -821,18 +786,10 @@ void cgit_print_docstart(void) htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); if (ctx.cfg.robots && *ctx.cfg.robots) htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); - - if (ctx.cfg.css.items) - for_each_string_list(&ctx.cfg.css, emit_css_link, NULL); - else - emit_css_link(NULL, "/cgit.css"); - - if (ctx.cfg.js.items) - for_each_string_list(&ctx.cfg.js, emit_js_link, NULL); - else - emit_js_link(NULL, "/cgit.js"); - - if (ctx.cfg.favicon && *ctx.cfg.favicon) { + html("<link rel='stylesheet' type='text/css' href='"); + html_attr(ctx.cfg.css); + html("'/>\n"); + if (ctx.cfg.favicon) { html("<link rel='shortcut icon' href='"); html_attr(ctx.cfg.favicon); html("'/>\n"); @@ -889,18 +846,13 @@ void cgit_print_docend(void) void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) { va_list ap; - va_start(ap, fmt); - cgit_vprint_error_page(code, msg, fmt, ap); - va_end(ap); -} - -void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap) -{ ctx.page.expires = ctx.cfg.cache_dynamic_ttl; ctx.page.status = code; ctx.page.statusmsg = msg; cgit_print_layout_start(); + va_start(ap, fmt); cgit_vprint_error(fmt, ap); + va_end(ap); cgit_print_layout_end(); } @@ -941,9 +893,10 @@ void cgit_add_clone_urls(void (*fn)(const char *)) add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); } -static int print_branch_option(const struct reference *ref, void *cb_data) +static int print_branch_option(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { - char *name = (char *)ref->name; + char *name = (char *)refname; html_option(name, name, ctx.qry.head); return 0; } @@ -1041,17 +994,15 @@ static void print_header(void) if (ctx.repo) { cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); html(" : "); - cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); + cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); if (ctx.env.authenticated) { html("</td><td class='form'>"); html("<form method='get'>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' onchange='this.form.submit();'>\n"); - refs_for_each_branch_ref(get_main_ref_store(the_repository), - print_branch_option, ctx.qry.head); + for_each_branch_ref(print_branch_option, ctx.qry.head); if (ctx.repo->enable_remote_branches) - refs_for_each_remote_ref(get_main_ref_store(the_repository), - print_branch_option, ctx.qry.head); + for_each_remote_ref(print_branch_option, ctx.qry.head); html("</select> "); html("<input type='submit' value='switch'/>"); html("</form>"); @@ -1064,13 +1015,7 @@ static void print_header(void) if (ctx.repo) { html_txt(ctx.repo->desc); html("</td><td class='sub right'>"); - if (ctx.repo->owner_filter) { - cgit_open_filter(ctx.repo->owner_filter); - html_txt(ctx.repo->owner); - cgit_close_filter(ctx.repo->owner_filter); - } else { - html_txt(ctx.repo->owner); - } + html_txt(ctx.repo->owner); } else { if (ctx.cfg.root_desc) html_txt(ctx.cfg.root_desc); @@ -1158,7 +1103,7 @@ void cgit_print_pageheader(void) html("<div class='path'>"); html("path: "); cgit_print_path_crumbs(ctx.qry.vpath); - if (ctx.repo->enable_follow_links && !strcmp(ctx.qry.page, "log")) { + if (ctx.cfg.enable_follow_links && !strcmp(ctx.qry.page, "log")) { html(" ("); ctx.qry.follow = !ctx.qry.follow; cgit_self_link(ctx.qry.follow ? "follow" : "unfollow", @@ -1196,11 +1141,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, * name starts with {v,V}[0-9] and the prettify mapping is injective, * i.e. each stripped tag can be inverted without ambiguities. */ - if (repo_get_oid(the_repository, fmt("refs/tags/%s", ref), &oid) == 0 && + if (get_oid(fmt("refs/tags/%s", ref), &oid) == 0 && (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && - ((repo_get_oid(the_repository, fmt("refs/tags/%s", ref + 1), &oid) == 0) + - (repo_get_oid(the_repository, fmt("refs/tags/v%s", ref + 1), &oid) == 0) + - (repo_get_oid(the_repository, fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1)) + ((get_oid(fmt("refs/tags/%s", ref + 1), &oid) == 0) + + (get_oid(fmt("refs/tags/v%s", ref + 1), &oid) == 0) + + (get_oid(fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1)) ref++; strbuf_addf(filename, "%s-%s", base, ref); diff --git a/ui-shared.h b/ui-shared.h index 2a3a7f5..6964873 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -65,7 +65,7 @@ __attribute__((format (printf,1,2))) extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); -extern const struct date_mode cgit_date_mode(enum date_mode_type type); +extern const struct date_mode *cgit_date_mode(enum date_mode_type type); extern void cgit_print_age(time_t t, int tz, time_t max_relative); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); @@ -73,7 +73,6 @@ extern void cgit_print_docstart(void); extern void cgit_print_docend(void); __attribute__((format (printf,3,4))) extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); -extern void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap); extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); extern void cgit_compose_snapshot_prefix(struct strbuf *filename, diff --git a/ui-snapshot.c b/ui-snapshot.c index d157222..18361a6 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-snapshot.h" #include "html.h" @@ -119,7 +117,7 @@ const struct object_id *cgit_snapshot_get_sig(const char *ref, struct notes_tree *tree; struct object_id oid; - if (repo_get_oid(the_repository, ref, &oid)) + if (get_oid(ref, &oid)) return NULL; tree = &snapshot_sig_notes[f - &cgit_snapshot_formats[0]]; @@ -158,7 +156,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, { struct object_id oid; - if (repo_get_oid(the_repository, hex, &oid)) { + if (get_oid(hex, &oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", hex); return 1; @@ -192,7 +190,7 @@ static int write_sig(const struct cgit_snapshot_format *format, return 0; } - buf = odb_read_object(the_repository->objects, note, &type, &size); + buf = read_object_file(note, &type, &size); if (!buf) { cgit_print_error_page(404, "Not found", "Not found"); return 0; @@ -232,7 +230,7 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo, strbuf_addstr(&snapshot, filename); strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix)); - if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; reponame = cgit_snapshot_prefix(repo); @@ -244,15 +242,15 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo, strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0); } - if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; strbuf_insert(&snapshot, 0, "v", 1); - if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; strbuf_splice(&snapshot, 0, 1, "V", 1); - if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; result = 0; @@ -1,13 +1,3 @@ -/* ui-stats.c: generate stats view - * - * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> - * - * Licensed under GNU General Public License v2 - * (see COPYING for full license text) - */ - -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-stats.h" #include "html.h" @@ -176,7 +166,7 @@ static void add_commit(struct string_list *authors, struct commit *commit, struct authorstat *authorstat; struct string_list *items; char *tmp; - struct tm date; + struct tm *date; time_t t; uintptr_t *counter; @@ -190,9 +180,9 @@ static void add_commit(struct string_list *authors, struct commit *commit, authorstat = author->util; items = &authorstat->list; t = info->committer_date; - gmtime_r(&t, &date); - period->trunc(&date); - tmp = xstrdup(period->pretty(&date)); + date = gmtime(&t); + period->trunc(date); + tmp = xstrdup(period->pretty(date)); item = string_list_insert(items, tmp); counter = (uintptr_t *)&item->util; if (*counter) @@ -225,22 +215,22 @@ static struct string_list collect_stats(const struct cgit_period *period) int argc = 3; time_t now; long i; - struct tm tm; + struct tm *tm; char tmp[11]; time(&now); - gmtime_r(&now, &tm); - period->trunc(&tm); + tm = gmtime(&now); + period->trunc(tm); for (i = 1; i < period->count; i++) - period->dec(&tm); - strftime(tmp, sizeof(tmp), "%Y-%m-%d", &tm); + period->dec(tm); + strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); argv[2] = xstrdup(fmt("--since=%s", tmp)); if (ctx.qry.path) { argv[3] = "--"; argv[4] = ctx.qry.path; argc += 2; } - repo_init_revisions(the_repository, &rev, NULL); + init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.max_parents = 1; @@ -251,7 +241,8 @@ static struct string_list collect_stats(const struct cgit_period *period) memset(&authors, 0, sizeof(authors)); while ((commit = get_revision(&rev)) != NULL) { add_commit(&authors, commit, period); - release_commit_memory(the_repository->parsed_objects, commit); + free_commit_buffer(the_repository->parsed_objects, commit); + free_commit_list(commit->parents); commit->parents = NULL; } return authors; @@ -270,21 +261,21 @@ static void print_combined_authorrow(struct string_list *authors, int from, struct string_list_item *date; time_t now; long i, j, total, subtotal; - struct tm tm; + struct tm *tm; char *tmp; time(&now); - gmtime_r(&now, &tm); - period->trunc(&tm); + tm = gmtime(&now); + period->trunc(tm); for (i = 1; i < period->count; i++) - period->dec(&tm); + period->dec(tm); total = 0; htmlf("<tr><td class='%s'>%s</td>", leftclass, fmt(name, to - from + 1)); for (j = 0; j < period->count; j++) { - tmp = period->pretty(&tm); - period->inc(&tm); + tmp = period->pretty(tm); + period->inc(tm); subtotal = 0; for (i = from; i <= to; i++) { author = &authors->items[i]; @@ -309,20 +300,20 @@ static void print_authors(struct string_list *authors, int top, struct string_list_item *date; time_t now; long i, j, total; - struct tm tm; + struct tm *tm; char *tmp; time(&now); - gmtime_r(&now, &tm); - period->trunc(&tm); + tm = gmtime(&now); + period->trunc(tm); for (i = 1; i < period->count; i++) - period->dec(&tm); + period->dec(tm); html("<table class='stats'><tr><th>Author</th>"); for (j = 0; j < period->count; j++) { - tmp = period->pretty(&tm); + tmp = period->pretty(tm); htmlf("<th>%s</th>", tmp); - period->inc(&tm); + period->inc(tm); } html("<th>Total</th></tr>\n"); @@ -338,10 +329,10 @@ static void print_authors(struct string_list *authors, int top, items = &authorstat->list; total = 0; for (j = 0; j < period->count; j++) - period->dec(&tm); + period->dec(tm); for (j = 0; j < period->count; j++) { - tmp = period->pretty(&tm); - period->inc(&tm); + tmp = period->pretty(tm); + period->inc(tm); date = string_list_lookup(items, tmp); if (!date) html("<td>0</td>"); @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-tag.h" #include "html.h" @@ -50,7 +48,7 @@ void cgit_print_tag(char *revname) revname = ctx.qry.head; strbuf_addf(&fullref, "refs/tags/%s", revname); - if (repo_get_oid(the_repository, fullref.buf, &oid)) { + if (get_oid(fullref.buf, &oid)) { cgit_print_error_page(404, "Not found", "Bad tag reference: %s", revname); goto cleanup; @@ -66,7 +64,7 @@ void cgit_print_tag(char *revname) struct taginfo *info; tag = lookup_tag(the_repository, &oid); - if (!tag || parse_tag(the_repository, tag) || !(info = cgit_parse_tag(tag))) { + if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { cgit_print_error_page(500, "Internal server error", "Bad tag object: %s", revname); goto cleanup; @@ -6,8 +6,6 @@ * (see COPYING for full license text) */ - #define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" #include "ui-tree.h" #include "html.h" @@ -91,22 +89,20 @@ static void print_object(const struct object_id *oid, const char *path, const ch enum object_type type; char *buf; unsigned long size; - bool is_binary; - type = odb_read_object_info(the_repository->objects, oid, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not found", "Bad object name: %s", oid_to_hex(oid)); return; } - buf = odb_read_object(the_repository->objects, oid, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", oid_to_hex(oid)); return; } - is_binary = buffer_is_binary(buf, size); cgit_set_title_from_path(path); @@ -114,7 +110,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch htmlf("blob: %s (", oid_to_hex(oid)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); - if (ctx.repo->enable_blame && !is_binary) { + if (ctx.repo->enable_blame) { html(") ("); cgit_blame_link("blame", NULL, NULL, ctx.qry.head, rev, path); @@ -127,7 +123,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch return; } - if (is_binary) + if (buffer_is_binary(buf, size)) print_binary_buffer(buf, size); else print_text_buffer(basename, buf, size); @@ -143,7 +139,8 @@ struct single_tree_ctx { }; static int single_tree_cb(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *cbdata) + const char *pathname, unsigned mode, int stage, + void *cbdata) { struct single_tree_ctx *ctx = cbdata; @@ -188,7 +185,8 @@ static void write_tree_link(const struct object_id *oid, char *name, tree_ctx.name = NULL; tree_ctx.count = 0; - read_tree(the_repository, tree, &paths, single_tree_cb, &tree_ctx); + read_tree_recursive(the_repository, tree, "", 0, 1, + &paths, single_tree_cb, &tree_ctx); if (tree_ctx.count != 1) break; @@ -201,28 +199,27 @@ static void write_tree_link(const struct object_id *oid, char *name, } static int ls_item(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *cbdata) + const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; char *name; struct strbuf fullpath = STRBUF_INIT; - struct strbuf linkpath = STRBUF_INIT; struct strbuf class = STRBUF_INIT; enum object_type type; unsigned long size = 0; - char *buf; name = xstrdup(pathname); strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", ctx.qry.path ? "/" : "", name); if (!S_ISGITLINK(mode)) { - type = odb_read_object_info(the_repository->objects, oid, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", name, oid_to_hex(oid)); - goto cleanup; + free(name); + return 0; } } @@ -242,21 +239,6 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, cgit_tree_link(name, NULL, class.buf, ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); } - if (S_ISLNK(mode)) { - html(" -> "); - buf = odb_read_object(the_repository->objects, oid, &type, &size); - if (!buf) { - htmlf("Error reading object: %s", oid_to_hex(oid)); - goto cleanup; - } - strbuf_addbuf(&linkpath, &fullpath); - strbuf_addf(&linkpath, "/../%s", buf); - strbuf_normalize_path(&linkpath); - cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, - walk_tree_ctx->curr_rev, linkpath.buf); - free(buf); - strbuf_release(&linkpath); - } htmlf("</td><td class='ls-size'>%li</td>", size); html("<td>"); @@ -273,8 +255,6 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, cgit_blame_link("blame", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); html("</td></tr>\n"); - -cleanup: free(name); strbuf_release(&fullpath); strbuf_release(&class); @@ -314,13 +294,14 @@ static void ls_tree(const struct object_id *oid, const char *path, struct walk_t } ls_head(); - read_tree(the_repository, tree, &paths, ls_item, walk_tree_ctx); + read_tree_recursive(the_repository, tree, "", 0, 1, + &paths, ls_item, walk_tree_ctx); ls_tail(); } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *cbdata) + const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -345,7 +326,7 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, return 0; } } - ls_item(oid, base, pathname, mode, walk_tree_ctx); + ls_item(oid, base, pathname, mode, stage, walk_tree_ctx); return 0; } @@ -374,13 +355,13 @@ void cgit_print_tree(const char *rev, char *path) if (!rev) rev = ctx.qry.head; - if (repo_get_oid(the_repository, rev, &oid)) { + if (get_oid(rev, &oid)) { cgit_print_error_page(404, "Not found", "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(the_repository, &oid); - if (!commit || repo_parse_commit(the_repository, commit)) { + if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); return; @@ -393,8 +374,10 @@ void cgit_print_tree(const char *rev, char *path) goto cleanup; } - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); else if (walk_tree_ctx.state == 2) |