-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | cgit.h | 6 | ||||
-rw-r--r-- | parsing.c | 4 | ||||
-rw-r--r-- | ui-repolist.c | 4 |
4 files changed, 31 insertions, 6 deletions
@@ -1,129 +1,152 @@ CGIT_VERSION = v0.8.1 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_CONFIG = /etc/cgitrc CACHE_ROOT = /var/cache/cgit SHA1_HEADER = <openssl/sha.h> GIT_VER = 1.6.0.3 GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 +# Define NO_STRCASESTR if you don't have strcasestr. +# +# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). +# + +#-include config.mak + +# +# Platform specific tweaks +# + +uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') +uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') +uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') + +ifeq ($(uname_O),Cygwin) + NO_STRCASESTR = YesPlease + NEEDS_LIBICONV = YesPlease +endif + # # Let the user override the above settings. # -include cgit.conf # # Define a way to invoke make in subdirs quietly, shamelessly ripped # from git.git # QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir QUIET_SUBDIR1 = ifneq ($(findstring $(MAKEFLAGS),w),w) PRINT_DIR = --no-print-directory else # "make -w" NO_SUBDIR = : endif ifndef V QUIET_CC = @echo ' ' CC $@; QUIET_MM = @echo ' ' MM $@; QUIET_SUBDIR0 = +@subdir= QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ $(MAKE) $(PRINT_DIR) -C $$subdir endif # # Define a pattern rule for automatic dependency building # %.d: %.c $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ # # Define a pattern rule for silent object building # %.o: %.c $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto OBJECTS = OBJECTS += cache.o OBJECTS += cgit.o OBJECTS += cmd.o OBJECTS += configfile.o OBJECTS += html.o OBJECTS += parsing.o OBJECTS += scan-tree.o OBJECTS += shared.o OBJECTS += ui-atom.o OBJECTS += ui-blob.o OBJECTS += ui-clone.o OBJECTS += ui-commit.o OBJECTS += ui-diff.o OBJECTS += ui-log.o OBJECTS += ui-patch.o OBJECTS += ui-plain.o OBJECTS += ui-refs.o OBJECTS += ui-repolist.o OBJECTS += ui-shared.o OBJECTS += ui-snapshot.o OBJECTS += ui-summary.o OBJECTS += ui-tag.o OBJECTS += ui-tree.o ifdef NEEDS_LIBICONV EXTLIBS += -liconv endif .PHONY: all libgit test install uninstall clean force-version get-git all: cgit VERSION: force-version @./gen-version.sh "$(CGIT_VERSION)" -include VERSION CFLAGS += -g -Wall -Igit CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' ifdef NO_ICONV CFLAGS += -DNO_ICONV endif +ifdef NO_STRCASESTR + CFLAGS += -DNO_STRCASESTR +endif cgit: $(OBJECTS) libgit $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) cgit.o: VERSION -include $(OBJECTS:.o=.d) libgit: $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a test: all $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all install: all mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) install -m 0644 cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css install -m 0644 cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png uninstall: rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) rm -f $(CGIT_SCRIPT_PATH)/cgit.css rm -f $(CGIT_SCRIPT_PATH)/cgit.png clean: rm -f cgit VERSION *.o *.d get-git: curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git @@ -140,104 +140,98 @@ struct cgit_config { char *root_title; char *root_desc; char *root_readme; char *script_name; char *virtual_root; int cache_size; int cache_dynamic_ttl; int cache_max_create_time; int cache_repo_ttl; int cache_root_ttl; int cache_static_ttl; int enable_index_links; int enable_log_filecount; int enable_log_linecount; int local_time; int max_repo_count; int max_commit_count; int max_lock_attempts; int max_msg_len; int max_repodesc_len; int nocache; int renamelimit; int snapshots; int summary_branches; int summary_log; int summary_tags; }; struct cgit_page { time_t modified; time_t expires; size_t size; char *mimetype; char *charset; char *filename; char *title; }; struct cgit_context { struct cgit_query qry; struct cgit_config cfg; struct cgit_repo *repo; struct cgit_page page; }; struct cgit_snapshot_format { const char *suffix; const char *mimetype; write_archive_fn_t write_func; int bit; }; extern const char *cgit_version; extern struct cgit_repolist cgit_repolist; extern struct cgit_context ctx; extern const struct cgit_snapshot_format cgit_snapshot_formats[]; 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_cb(const char *name, const char *value); extern int chk_zero(int result, char *msg); extern int chk_positive(int result, char *msg); extern int chk_non_negative(int result, char *msg); extern char *trim_end(const char *str, char c); extern char *strlpart(char *txt, int maxlen); extern char *strrpart(char *txt, int maxlen); extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data); extern void *cgit_free_commitinfo(struct commitinfo *info); extern int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, linediff_fn fn); extern void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, filepair_fn fn, const char *prefix); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); extern char *fmt(const char *format,...); extern struct commitinfo *cgit_parse_commit(struct commit *commit); extern struct taginfo *cgit_parse_tag(struct tag *tag); extern void cgit_parse_url(const char *url); extern const char *cgit_repobasename(const char *reponame); extern int cgit_parse_snapshots_mask(const char *str); -/* libgit.a either links against or compiles its own implementation of - * strcasestr(), and we'd like to reuse it. Simply re-declaring it - * seems to do the trick. - */ -extern char *strcasestr(const char *haystack, const char *needle); - #endif /* CGIT_H */ @@ -3,206 +3,210 @@ * Copyright (C) 2006 Lars Hjemli * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" /* * url syntax: [repo ['/' cmd [ '/' path]]] * repo: any valid repo url, may contain '/' * cmd: log | commit | diff | tree | view | blob | snapshot * path: any valid path, may contain '/' * */ void cgit_parse_url(const char *url) { char *cmd, *p; ctx.repo = NULL; if (!url || url[0] == '\0') return; ctx.repo = cgit_get_repoinfo(url); if (ctx.repo) { ctx.qry.repo = ctx.repo->url; return; } cmd = strchr(url, '/'); while (!ctx.repo && cmd) { cmd[0] = '\0'; ctx.repo = cgit_get_repoinfo(url); if (ctx.repo == NULL) { cmd[0] = '/'; cmd = strchr(cmd + 1, '/'); continue; } ctx.qry.repo = ctx.repo->url; p = strchr(cmd + 1, '/'); if (p) { p[0] = '\0'; if (p[1]) ctx.qry.path = trim_end(p + 1, '/'); } if (cmd[1]) ctx.qry.page = xstrdup(cmd + 1); return; } } char *substr(const char *head, const char *tail) { char *buf; buf = xmalloc(tail - head + 1); strncpy(buf, head, tail - head); buf[tail - head] = '\0'; return buf; } char *parse_user(char *t, char **name, char **email, unsigned long *date) { char *p = t; int mode = 1; while (p && *p) { if (mode == 1 && *p == '<') { *name = substr(t, p - 1); t = p; mode++; } else if (mode == 1 && *p == '\n') { *name = substr(t, p); p++; break; } else if (mode == 2 && *p == '>') { *email = substr(t, p + 1); t = p; mode++; } else if (mode == 2 && *p == '\n') { *email = substr(t, p); p++; break; } else if (mode == 3 && isdigit(*p)) { *date = atol(p); mode++; } else if (*p == '\n') { p++; break; } p++; } return p; } +#ifdef NO_ICONV +#define reencode(a, b, c) +#else const char *reencode(char **txt, const char *src_enc, const char *dst_enc) { char *tmp; if (!txt || !*txt || !src_enc || !dst_enc) return *txt; tmp = reencode_string(*txt, src_enc, dst_enc); if (tmp) { free(*txt); *txt = tmp; } return *txt; } +#endif struct commitinfo *cgit_parse_commit(struct commit *commit) { struct commitinfo *ret; char *p = commit->buffer, *t = commit->buffer; ret = xmalloc(sizeof(*ret)); ret->commit = commit; ret->author = NULL; ret->author_email = NULL; ret->committer = NULL; ret->committer_email = NULL; ret->subject = NULL; ret->msg = NULL; ret->msg_encoding = NULL; if (p == NULL) return ret; if (strncmp(p, "tree ", 5)) die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); else p += 46; // "tree " + hex[40] + "\n" while (!strncmp(p, "parent ", 7)) p += 48; // "parent " + hex[40] + "\n" if (p && !strncmp(p, "author ", 7)) { p = parse_user(p + 7, &ret->author, &ret->author_email, &ret->author_date); } if (p && !strncmp(p, "committer ", 9)) { p = parse_user(p + 9, &ret->committer, &ret->committer_email, &ret->committer_date); } if (p && !strncmp(p, "encoding ", 9)) { p += 9; t = strchr(p, '\n'); if (t) { ret->msg_encoding = substr(p, t + 1); p = t + 1; } } // skip unknown header fields while (p && *p && (*p != '\n')) { p = strchr(p, '\n'); if (p) p++; } // skip empty lines between headers and message while (p && *p == '\n') p++; if (!p) return ret; t = strchr(p, '\n'); if (t) { ret->subject = substr(p, t); p = t + 1; while (p && *p == '\n') { p = strchr(p, '\n'); if (p) p++; } if (p) ret->msg = xstrdup(p); } else ret->subject = xstrdup(p); if (ret->msg_encoding) { reencode(&ret->subject, PAGE_ENCODING, ret->msg_encoding); reencode(&ret->msg, PAGE_ENCODING, ret->msg_encoding); } return ret; } struct taginfo *cgit_parse_tag(struct tag *tag) { void *data; enum object_type type; unsigned long size; char *p; struct taginfo *ret; data = read_sha1_file(tag->object.sha1, &type, &size); if (!data || type != OBJ_TAG) { free(data); return 0; diff --git a/ui-repolist.c b/ui-repolist.c index c23232c..2324273 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -1,104 +1,108 @@ /* ui-repolist.c: functions for generating the repolist page * * Copyright (C) 2006 Lars Hjemli * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ +/* This is needed for strcasestr to be defined by <string.h> */ +#define _GNU_SOURCE 1 +#include <string.h> + #include <time.h> #include "cgit.h" #include "html.h" #include "ui-shared.h" time_t read_agefile(char *path) { FILE *f; static char buf[64], buf2[64]; if (!(f = fopen(path, "r"))) return -1; if (fgets(buf, sizeof(buf), f) == NULL) return -1; fclose(f); if (parse_date(buf, buf2, sizeof(buf2))) return strtoul(buf2, NULL, 10); else return 0; } static void print_modtime(struct cgit_repo *repo) { char *path; struct stat s; path = fmt("%s/%s", repo->path, ctx.cfg.agefile); if (stat(path, &s) == 0) { cgit_print_age(read_agefile(path), -1, NULL); return; } path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); if (stat(path, &s) != 0) return; cgit_print_age(s.st_mtime, -1, NULL); } int is_match(struct cgit_repo *repo) { if (!ctx.qry.search) return 1; if (repo->url && strcasestr(repo->url, ctx.qry.search)) return 1; if (repo->name && strcasestr(repo->name, ctx.qry.search)) return 1; if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) return 1; if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) return 1; return 0; } int is_in_url(struct cgit_repo *repo) { if (!ctx.qry.url) return 1; if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) return 1; return 0; } void print_header(int columns) { html("<tr class='nohover'>" "<th class='left'>Name</th>" "<th class='left'>Description</th>" "<th class='left'>Owner</th>" "<th class='left'>Idle</th>"); if (ctx.cfg.enable_index_links) html("<th class='left'>Links</th>"); html("</tr>\n"); } void print_pager(int items, int pagelen, char *search) { int i; html("<div class='pager'>"); for(i = 0; i * pagelen < items; i++) cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, search, i * pagelen); html("</div>"); } void cgit_print_repolist() { int i, columns = 4, hits = 0, header = 0; char *last_group = NULL; if (ctx.cfg.enable_index_links) columns++; ctx.page.title = ctx.cfg.root_title; cgit_print_http_headers(&ctx); |