diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 75 | ||||
| -rw-r--r-- | cache.c | 21 | ||||
| -rw-r--r-- | cache.h | 23 | ||||
| -rw-r--r-- | cgit.c | 391 | ||||
| -rw-r--r-- | cgit.h | 237 | ||||
| -rw-r--r-- | cmd.c | 112 | ||||
| -rw-r--r-- | cmd.h | 15 | ||||
| -rw-r--r-- | configfile.c | 87 | ||||
| -rw-r--r-- | configfile.h | 8 | ||||
| -rw-r--r-- | html.c | 95 | ||||
| -rw-r--r-- | html.h | 20 | ||||
| -rw-r--r-- | parsing.c | 146 | ||||
| -rw-r--r-- | shared.c | 257 | ||||
| -rw-r--r-- | ui-blob.c | 16 | ||||
| -rw-r--r-- | ui-blob.h | 6 | ||||
| -rw-r--r-- | ui-commit.c | 26 | ||||
| -rw-r--r-- | ui-commit.h | 6 | ||||
| -rw-r--r-- | ui-diff.c | 9 | ||||
| -rw-r--r-- | ui-diff.h | 7 | ||||
| -rw-r--r-- | ui-log.c | 32 | ||||
| -rw-r--r-- | ui-log.h | 7 | ||||
| -rw-r--r-- | ui-patch.c | 10 | ||||
| -rw-r--r-- | ui-patch.h | 6 | ||||
| -rw-r--r-- | ui-refs.c | 175 | ||||
| -rw-r--r-- | ui-refs.h | 8 | ||||
| -rw-r--r-- | ui-repolist.c | 54 | ||||
| -rw-r--r-- | ui-repolist.h | 6 | ||||
| -rw-r--r-- | ui-shared.c | 237 | ||||
| -rw-r--r-- | ui-shared.h | 36 | ||||
| -rw-r--r-- | ui-snapshot.c | 123 | ||||
| -rw-r--r-- | ui-snapshot.h | 8 | ||||
| -rw-r--r-- | ui-summary.c | 189 | ||||
| -rw-r--r-- | ui-summary.h | 6 | ||||
| -rw-r--r-- | ui-tag.c | 3 | ||||
| -rw-r--r-- | ui-tag.h | 6 | ||||
| -rw-r--r-- | ui-tree.c | 26 | ||||
| -rw-r--r-- | ui-tree.h | 6 |
38 files changed, 1379 insertions, 1117 deletions
| @@ -3,3 +3,4 @@ cgit | |||
| 3 | cgit.conf | 3 | cgit.conf |
| 4 | VERSION | 4 | VERSION |
| 5 | *.o | 5 | *.o |
| 6 | *.d | ||
| @@ -12,13 +12,62 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | |||
| 12 | # | 12 | # |
| 13 | -include cgit.conf | 13 | -include cgit.conf |
| 14 | 14 | ||
| 15 | # | ||
| 16 | # Define a way to invoke make in subdirs quietly, shamelessly ripped | ||
| 17 | # from git.git | ||
| 18 | # | ||
| 19 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | ||
| 20 | QUIET_SUBDIR1 = | ||
| 15 | 21 | ||
| 16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 22 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
| 17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 23 | PRINT_DIR = --no-print-directory |
| 18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 24 | else # "make -w" |
| 19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o | 25 | NO_SUBDIR = : |
| 26 | endif | ||
| 27 | |||
| 28 | ifndef V | ||
| 29 | QUIET_CC = @echo ' ' CC $@; | ||
| 30 | QUIET_MM = @echo ' ' MM $@; | ||
| 31 | QUIET_SUBDIR0 = +@subdir= | ||
| 32 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ | ||
| 33 | $(MAKE) $(PRINT_DIR) -C $$subdir | ||
| 34 | endif | ||
| 35 | |||
| 36 | # | ||
| 37 | # Define a pattern rule for automatic dependency building | ||
| 38 | # | ||
| 39 | %.d: %.c | ||
| 40 | $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ | ||
| 41 | |||
| 42 | # | ||
| 43 | # Define a pattern rule for silent object building | ||
| 44 | # | ||
| 45 | %.o: %.c | ||
| 46 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< | ||
| 20 | 47 | ||
| 21 | 48 | ||
| 49 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | ||
| 50 | OBJECTS = | ||
| 51 | OBJECTS += cache.o | ||
| 52 | OBJECTS += cgit.o | ||
| 53 | OBJECTS += cmd.o | ||
| 54 | OBJECTS += configfile.o | ||
| 55 | OBJECTS += html.o | ||
| 56 | OBJECTS += parsing.o | ||
| 57 | OBJECTS += shared.o | ||
| 58 | OBJECTS += ui-blob.o | ||
| 59 | OBJECTS += ui-commit.o | ||
| 60 | OBJECTS += ui-diff.o | ||
| 61 | OBJECTS += ui-log.o | ||
| 62 | OBJECTS += ui-patch.o | ||
| 63 | OBJECTS += ui-refs.o | ||
| 64 | OBJECTS += ui-repolist.o | ||
| 65 | OBJECTS += ui-shared.o | ||
| 66 | OBJECTS += ui-snapshot.o | ||
| 67 | OBJECTS += ui-summary.o | ||
| 68 | OBJECTS += ui-tag.o | ||
| 69 | OBJECTS += ui-tree.o | ||
| 70 | |||
| 22 | ifdef NEEDS_LIBICONV | 71 | ifdef NEEDS_LIBICONV |
| 23 | EXTLIBS += -liconv | 72 | EXTLIBS += -liconv |
| 24 | endif | 73 | endif |
| @@ -41,21 +90,25 @@ CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | |||
| 41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 90 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
| 42 | 91 | ||
| 43 | 92 | ||
| 44 | cgit: cgit.c $(OBJECTS) | 93 | cgit: $(OBJECTS) |
| 45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 94 | $(QUIET_CC)$(CC) $(CFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) |
| 95 | |||
| 96 | $(OBJECTS): git/xdiff/lib.a git/libgit.a | ||
| 97 | |||
| 98 | cgit.o: VERSION | ||
| 46 | 99 | ||
| 47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 100 | -include $(OBJECTS:.o=.d) |
| 48 | 101 | ||
| 49 | git/xdiff/lib.a: | git | 102 | git/xdiff/lib.a: | git |
| 50 | 103 | ||
| 51 | git/libgit.a: | git | 104 | git/libgit.a: | git |
| 52 | 105 | ||
| 53 | git: | 106 | git: |
| 54 | cd git && $(MAKE) xdiff/lib.a | 107 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a |
| 55 | cd git && $(MAKE) libgit.a | 108 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a |
| 56 | 109 | ||
| 57 | test: all | 110 | test: all |
| 58 | $(MAKE) -C tests | 111 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
| 59 | 112 | ||
| 60 | install: all | 113 | install: all |
| 61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 114 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
| @@ -69,7 +122,7 @@ uninstall: | |||
| 69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png | 122 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png |
| 70 | 123 | ||
| 71 | clean: | 124 | clean: |
| 72 | rm -f cgit VERSION *.o | 125 | rm -f cgit VERSION *.o *.d |
| 73 | cd git && $(MAKE) clean | 126 | cd git && $(MAKE) clean |
| 74 | 127 | ||
| 75 | distclean: clean | 128 | distclean: clean |
| @@ -7,6 +7,7 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "cache.h" | ||
| 10 | 11 | ||
| 11 | const int NOLOCK = -1; | 12 | const int NOLOCK = -1; |
| 12 | 13 | ||
| @@ -44,23 +45,23 @@ int cache_create_dirs() | |||
| 44 | { | 45 | { |
| 45 | char *path; | 46 | char *path; |
| 46 | 47 | ||
| 47 | path = fmt("%s", cgit_cache_root); | 48 | path = fmt("%s", ctx.cfg.cache_root); |
| 48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 49 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
| 49 | return 0; | 50 | return 0; |
| 50 | 51 | ||
| 51 | if (!cgit_repo) | 52 | if (!ctx.repo) |
| 52 | return 0; | 53 | return 0; |
| 53 | 54 | ||
| 54 | path = fmt("%s/%s", cgit_cache_root, | 55 | path = fmt("%s/%s", ctx.cfg.cache_root, |
| 55 | cache_safe_filename(cgit_repo->url)); | 56 | cache_safe_filename(ctx.repo->url)); |
| 56 | 57 | ||
| 57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 58 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
| 58 | return 0; | 59 | return 0; |
| 59 | 60 | ||
| 60 | if (cgit_query_page) { | 61 | if (ctx.qry.page) { |
| 61 | path = fmt("%s/%s/%s", cgit_cache_root, | 62 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
| 62 | cache_safe_filename(cgit_repo->url), | 63 | cache_safe_filename(ctx.repo->url), |
| 63 | cgit_query_page); | 64 | ctx.qry.page); |
| 64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 65 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
| 65 | return 0; | 66 | return 0; |
| 66 | } | 67 | } |
| @@ -74,7 +75,7 @@ int cache_refill_overdue(const char *lockfile) | |||
| 74 | if (stat(lockfile, &st)) | 75 | if (stat(lockfile, &st)) |
| 75 | return 0; | 76 | return 0; |
| 76 | else | 77 | else |
| 77 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); | 78 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | int cache_lock(struct cacheitem *item) | 81 | int cache_lock(struct cacheitem *item) |
| @@ -83,7 +84,7 @@ int cache_lock(struct cacheitem *item) | |||
| 83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); | 84 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
| 84 | 85 | ||
| 85 | top: | 86 | top: |
| 86 | if (++i > cgit_max_lock_attempts) | 87 | if (++i > ctx.cfg.max_lock_attempts) |
| 87 | die("cache_lock: unable to lock %s: %s", | 88 | die("cache_lock: unable to lock %s: %s", |
| 88 | item->name, strerror(errno)); | 89 | item->name, strerror(errno)); |
| 89 | 90 | ||
| @@ -0,0 +1,23 @@ | |||
| 1 | /* | ||
| 2 | * Since git has it's own cache.h which we include, | ||
| 3 | * lets test on CGIT_CACHE_H to avoid confusion | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef CGIT_CACHE_H | ||
| 7 | #define CGIT_CACHE_H | ||
| 8 | |||
| 9 | struct cacheitem { | ||
| 10 | char *name; | ||
| 11 | struct stat st; | ||
| 12 | int ttl; | ||
| 13 | int fd; | ||
| 14 | }; | ||
| 15 | |||
| 16 | extern char *cache_safe_filename(const char *unsafe); | ||
| 17 | extern int cache_lock(struct cacheitem *item); | ||
| 18 | extern int cache_unlock(struct cacheitem *item); | ||
| 19 | extern int cache_cancel_lock(struct cacheitem *item); | ||
| 20 | extern int cache_exist(struct cacheitem *item); | ||
| 21 | extern int cache_expired(struct cacheitem *item); | ||
| 22 | |||
| 23 | #endif /* CGIT_CACHE_H */ | ||
| @@ -7,40 +7,199 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "cache.h" | ||
| 11 | #include "cmd.h" | ||
| 12 | #include "configfile.h" | ||
| 13 | #include "html.h" | ||
| 14 | #include "ui-shared.h" | ||
| 15 | |||
| 16 | const char *cgit_version = CGIT_VERSION; | ||
| 17 | |||
| 18 | void config_cb(const char *name, const char *value) | ||
| 19 | { | ||
| 20 | if (!strcmp(name, "root-title")) | ||
| 21 | ctx.cfg.root_title = xstrdup(value); | ||
| 22 | else if (!strcmp(name, "css")) | ||
| 23 | ctx.cfg.css = xstrdup(value); | ||
| 24 | else if (!strcmp(name, "logo")) | ||
| 25 | ctx.cfg.logo = xstrdup(value); | ||
| 26 | else if (!strcmp(name, "index-header")) | ||
| 27 | ctx.cfg.index_header = xstrdup(value); | ||
| 28 | else if (!strcmp(name, "index-info")) | ||
| 29 | ctx.cfg.index_info = xstrdup(value); | ||
| 30 | else if (!strcmp(name, "logo-link")) | ||
| 31 | ctx.cfg.logo_link = xstrdup(value); | ||
| 32 | else if (!strcmp(name, "module-link")) | ||
| 33 | ctx.cfg.module_link = xstrdup(value); | ||
| 34 | else if (!strcmp(name, "virtual-root")) { | ||
| 35 | ctx.cfg.virtual_root = trim_end(value, '/'); | ||
| 36 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | ||
| 37 | ctx.cfg.virtual_root = ""; | ||
| 38 | } else if (!strcmp(name, "nocache")) | ||
| 39 | ctx.cfg.nocache = atoi(value); | ||
| 40 | else if (!strcmp(name, "snapshots")) | ||
| 41 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | ||
| 42 | else if (!strcmp(name, "enable-index-links")) | ||
| 43 | ctx.cfg.enable_index_links = atoi(value); | ||
| 44 | else if (!strcmp(name, "enable-log-filecount")) | ||
| 45 | ctx.cfg.enable_log_filecount = atoi(value); | ||
| 46 | else if (!strcmp(name, "enable-log-linecount")) | ||
| 47 | ctx.cfg.enable_log_linecount = atoi(value); | ||
| 48 | else if (!strcmp(name, "cache-root")) | ||
| 49 | ctx.cfg.cache_root = xstrdup(value); | ||
| 50 | else if (!strcmp(name, "cache-root-ttl")) | ||
| 51 | ctx.cfg.cache_root_ttl = atoi(value); | ||
| 52 | else if (!strcmp(name, "cache-repo-ttl")) | ||
| 53 | ctx.cfg.cache_repo_ttl = atoi(value); | ||
| 54 | else if (!strcmp(name, "cache-static-ttl")) | ||
| 55 | ctx.cfg.cache_static_ttl = atoi(value); | ||
| 56 | else if (!strcmp(name, "cache-dynamic-ttl")) | ||
| 57 | ctx.cfg.cache_dynamic_ttl = atoi(value); | ||
| 58 | else if (!strcmp(name, "max-message-length")) | ||
| 59 | ctx.cfg.max_msg_len = atoi(value); | ||
| 60 | else if (!strcmp(name, "max-repodesc-length")) | ||
| 61 | ctx.cfg.max_repodesc_len = atoi(value); | ||
| 62 | else if (!strcmp(name, "max-commit-count")) | ||
| 63 | ctx.cfg.max_commit_count = atoi(value); | ||
| 64 | else if (!strcmp(name, "summary-log")) | ||
| 65 | ctx.cfg.summary_log = atoi(value); | ||
| 66 | else if (!strcmp(name, "summary-branches")) | ||
| 67 | ctx.cfg.summary_branches = atoi(value); | ||
| 68 | else if (!strcmp(name, "summary-tags")) | ||
| 69 | ctx.cfg.summary_tags = atoi(value); | ||
| 70 | else if (!strcmp(name, "agefile")) | ||
| 71 | ctx.cfg.agefile = xstrdup(value); | ||
| 72 | else if (!strcmp(name, "renamelimit")) | ||
| 73 | ctx.cfg.renamelimit = atoi(value); | ||
| 74 | else if (!strcmp(name, "robots")) | ||
| 75 | ctx.cfg.robots = xstrdup(value); | ||
| 76 | else if (!strcmp(name, "clone-prefix")) | ||
| 77 | ctx.cfg.clone_prefix = xstrdup(value); | ||
| 78 | else if (!strcmp(name, "repo.group")) | ||
| 79 | ctx.cfg.repo_group = xstrdup(value); | ||
| 80 | else if (!strcmp(name, "repo.url")) | ||
| 81 | ctx.repo = cgit_add_repo(value); | ||
| 82 | else if (!strcmp(name, "repo.name")) | ||
| 83 | ctx.repo->name = xstrdup(value); | ||
| 84 | else if (ctx.repo && !strcmp(name, "repo.path")) | ||
| 85 | ctx.repo->path = trim_end(value, '/'); | ||
| 86 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) | ||
| 87 | ctx.repo->clone_url = xstrdup(value); | ||
| 88 | else if (ctx.repo && !strcmp(name, "repo.desc")) | ||
| 89 | ctx.repo->desc = xstrdup(value); | ||
| 90 | else if (ctx.repo && !strcmp(name, "repo.owner")) | ||
| 91 | ctx.repo->owner = xstrdup(value); | ||
| 92 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) | ||
| 93 | ctx.repo->defbranch = xstrdup(value); | ||
| 94 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) | ||
| 95 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | ||
| 96 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) | ||
| 97 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | ||
| 98 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) | ||
| 99 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | ||
| 100 | else if (ctx.repo && !strcmp(name, "repo.module-link")) | ||
| 101 | ctx.repo->module_link= xstrdup(value); | ||
| 102 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { | ||
| 103 | if (*value == '/') | ||
| 104 | ctx.repo->readme = xstrdup(value); | ||
| 105 | else | ||
| 106 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); | ||
| 107 | } else if (!strcmp(name, "include")) | ||
| 108 | parse_configfile(value, config_cb); | ||
| 109 | } | ||
| 110 | |||
| 111 | static void querystring_cb(const char *name, const char *value) | ||
| 112 | { | ||
| 113 | if (!strcmp(name,"r")) { | ||
| 114 | ctx.qry.repo = xstrdup(value); | ||
| 115 | ctx.repo = cgit_get_repoinfo(value); | ||
| 116 | } else if (!strcmp(name, "p")) { | ||
| 117 | ctx.qry.page = xstrdup(value); | ||
| 118 | } else if (!strcmp(name, "url")) { | ||
| 119 | cgit_parse_url(value); | ||
| 120 | } else if (!strcmp(name, "qt")) { | ||
| 121 | ctx.qry.grep = xstrdup(value); | ||
| 122 | } else if (!strcmp(name, "q")) { | ||
| 123 | ctx.qry.search = xstrdup(value); | ||
| 124 | } else if (!strcmp(name, "h")) { | ||
| 125 | ctx.qry.head = xstrdup(value); | ||
| 126 | ctx.qry.has_symref = 1; | ||
| 127 | } else if (!strcmp(name, "id")) { | ||
| 128 | ctx.qry.sha1 = xstrdup(value); | ||
| 129 | ctx.qry.has_sha1 = 1; | ||
| 130 | } else if (!strcmp(name, "id2")) { | ||
| 131 | ctx.qry.sha2 = xstrdup(value); | ||
| 132 | ctx.qry.has_sha1 = 1; | ||
| 133 | } else if (!strcmp(name, "ofs")) { | ||
| 134 | ctx.qry.ofs = atoi(value); | ||
| 135 | } else if (!strcmp(name, "path")) { | ||
| 136 | ctx.qry.path = trim_end(value, '/'); | ||
| 137 | } else if (!strcmp(name, "name")) { | ||
| 138 | ctx.qry.name = xstrdup(value); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | static void prepare_context(struct cgit_context *ctx) | ||
| 143 | { | ||
| 144 | memset(ctx, 0, sizeof(ctx)); | ||
| 145 | ctx->cfg.agefile = "info/web/last-modified"; | ||
| 146 | ctx->cfg.cache_dynamic_ttl = 5; | ||
| 147 | ctx->cfg.cache_max_create_time = 5; | ||
| 148 | ctx->cfg.cache_repo_ttl = 5; | ||
| 149 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | ||
| 150 | ctx->cfg.cache_root_ttl = 5; | ||
| 151 | ctx->cfg.cache_static_ttl = -1; | ||
| 152 | ctx->cfg.css = "/cgit.css"; | ||
| 153 | ctx->cfg.logo = "/git-logo.png"; | ||
| 154 | ctx->cfg.max_commit_count = 50; | ||
| 155 | ctx->cfg.max_lock_attempts = 5; | ||
| 156 | ctx->cfg.max_msg_len = 60; | ||
| 157 | ctx->cfg.max_repodesc_len = 60; | ||
| 158 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | ||
| 159 | ctx->cfg.renamelimit = -1; | ||
| 160 | ctx->cfg.robots = "index, nofollow"; | ||
| 161 | ctx->cfg.root_title = "Git repository browser"; | ||
| 162 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | ||
| 163 | ctx->page.mimetype = "text/html"; | ||
| 164 | ctx->page.charset = PAGE_ENCODING; | ||
| 165 | ctx->page.filename = NULL; | ||
| 166 | } | ||
| 10 | 167 | ||
| 11 | static int cgit_prepare_cache(struct cacheitem *item) | 168 | static int cgit_prepare_cache(struct cacheitem *item) |
| 12 | { | 169 | { |
| 13 | if (!cgit_repo && cgit_query_repo) { | 170 | if (!ctx.repo && ctx.qry.repo) { |
| 14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 171 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
| 15 | cgit_print_docstart(title, item); | 172 | "Bad request"); |
| 16 | cgit_print_pageheader(title, 0); | 173 | cgit_print_http_headers(&ctx); |
| 17 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 174 | cgit_print_docstart(&ctx); |
| 175 | cgit_print_pageheader(&ctx); | ||
| 176 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | ||
| 18 | cgit_print_docend(); | 177 | cgit_print_docend(); |
| 19 | return 0; | 178 | return 0; |
| 20 | } | 179 | } |
| 21 | 180 | ||
| 22 | if (!cgit_repo) { | 181 | if (!ctx.repo) { |
| 23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 182 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
| 24 | item->ttl = cgit_cache_root_ttl; | 183 | item->ttl = ctx.cfg.cache_root_ttl; |
| 25 | return 1; | 184 | return 1; |
| 26 | } | 185 | } |
| 27 | 186 | ||
| 28 | if (!cgit_cmd) { | 187 | if (!ctx.qry.page) { |
| 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, | 188 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
| 30 | cache_safe_filename(cgit_repo->url), | 189 | cache_safe_filename(ctx.repo->url), |
| 31 | cache_safe_filename(cgit_querystring))); | 190 | cache_safe_filename(ctx.qry.raw))); |
| 32 | item->ttl = cgit_cache_repo_ttl; | 191 | item->ttl = ctx.cfg.cache_repo_ttl; |
| 33 | } else { | 192 | } else { |
| 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 193 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
| 35 | cache_safe_filename(cgit_repo->url), | 194 | cache_safe_filename(ctx.repo->url), |
| 36 | cgit_query_page, | 195 | ctx.qry.page, |
| 37 | cache_safe_filename(cgit_querystring))); | 196 | cache_safe_filename(ctx.qry.raw))); |
| 38 | if (cgit_query_has_symref) | 197 | if (ctx.qry.has_symref) |
| 39 | item->ttl = cgit_cache_dynamic_ttl; | 198 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
| 40 | else if (cgit_query_has_sha1) | 199 | else if (ctx.qry.has_sha1) |
| 41 | item->ttl = cgit_cache_static_ttl; | 200 | item->ttl = ctx.cfg.cache_static_ttl; |
| 42 | else | 201 | else |
| 43 | item->ttl = cgit_cache_repo_ttl; | 202 | item->ttl = ctx.cfg.cache_repo_ttl; |
| 44 | } | 203 | } |
| 45 | return 1; | 204 | return 1; |
| 46 | } | 205 | } |
| @@ -64,7 +223,7 @@ int find_current_ref(const char *refname, const unsigned char *sha1, | |||
| 64 | return info->match; | 223 | return info->match; |
| 65 | } | 224 | } |
| 66 | 225 | ||
| 67 | char *find_default_branch(struct repoinfo *repo) | 226 | char *find_default_branch(struct cgit_repo *repo) |
| 68 | { | 227 | { |
| 69 | struct refmatch info; | 228 | struct refmatch info; |
| 70 | 229 | ||
| @@ -78,113 +237,98 @@ char *find_default_branch(struct repoinfo *repo) | |||
| 78 | return info.first_ref; | 237 | return info.first_ref; |
| 79 | } | 238 | } |
| 80 | 239 | ||
| 81 | static void cgit_print_repo_page(struct cacheitem *item) | 240 | static int prepare_repo_cmd(struct cgit_context *ctx) |
| 82 | { | 241 | { |
| 83 | char *title, *tmp; | 242 | char *tmp; |
| 84 | int show_search; | ||
| 85 | unsigned char sha1[20]; | 243 | unsigned char sha1[20]; |
| 86 | 244 | int nongit = 0; | |
| 87 | if (chdir(cgit_repo->path)) { | 245 | |
| 88 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 246 | setenv("GIT_DIR", ctx->repo->path, 1); |
| 89 | cgit_print_docstart(title, item); | 247 | setup_git_directory_gently(&nongit); |
| 90 | cgit_print_pageheader(title, 0); | 248 | if (nongit) { |
| 91 | cgit_print_error(fmt("Unable to scan repository: %s", | 249 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
| 92 | strerror(errno))); | 250 | "config error"); |
| 251 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); | ||
| 252 | ctx->repo = NULL; | ||
| 253 | cgit_print_http_headers(ctx); | ||
| 254 | cgit_print_docstart(ctx); | ||
| 255 | cgit_print_pageheader(ctx); | ||
| 256 | cgit_print_error(tmp); | ||
| 93 | cgit_print_docend(); | 257 | cgit_print_docend(); |
| 94 | return; | 258 | return 1; |
| 95 | } | 259 | } |
| 260 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | ||
| 96 | 261 | ||
| 97 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 262 | if (!ctx->qry.head) { |
| 98 | show_search = 0; | 263 | ctx->qry.head = xstrdup(find_default_branch(ctx->repo)); |
| 99 | setenv("GIT_DIR", cgit_repo->path, 1); | 264 | ctx->repo->defbranch = ctx->qry.head; |
| 100 | |||
| 101 | if (!cgit_query_head) { | ||
| 102 | cgit_query_head = xstrdup(find_default_branch(cgit_repo)); | ||
| 103 | cgit_repo->defbranch = cgit_query_head; | ||
| 104 | } | 265 | } |
| 105 | 266 | ||
| 106 | if (!cgit_query_head) { | 267 | if (!ctx->qry.head) { |
| 107 | cgit_print_docstart(title, item); | 268 | cgit_print_http_headers(ctx); |
| 108 | cgit_print_pageheader(title, 0); | 269 | cgit_print_docstart(ctx); |
| 270 | cgit_print_pageheader(ctx); | ||
| 109 | cgit_print_error("Repository seems to be empty"); | 271 | cgit_print_error("Repository seems to be empty"); |
| 110 | cgit_print_docend(); | 272 | cgit_print_docend(); |
| 111 | return; | 273 | return 1; |
| 112 | } | 274 | } |
| 113 | 275 | ||
| 114 | if (get_sha1(cgit_query_head, sha1)) { | 276 | if (get_sha1(ctx->qry.head, sha1)) { |
| 115 | tmp = xstrdup(cgit_query_head); | 277 | tmp = xstrdup(ctx->qry.head); |
| 116 | cgit_query_head = cgit_repo->defbranch; | 278 | ctx->qry.head = ctx->repo->defbranch; |
| 117 | cgit_print_docstart(title, item); | 279 | cgit_print_http_headers(ctx); |
| 118 | cgit_print_pageheader(title, 0); | 280 | cgit_print_docstart(ctx); |
| 281 | cgit_print_pageheader(ctx); | ||
| 119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 282 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
| 120 | cgit_print_docend(); | 283 | cgit_print_docend(); |
| 121 | return; | 284 | return 1; |
| 122 | } | 285 | } |
| 286 | return 0; | ||
| 287 | } | ||
| 123 | 288 | ||
| 124 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 289 | static void process_request(struct cgit_context *ctx) |
| 125 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, | 290 | { |
| 126 | cgit_repobasename(cgit_repo->url), | 291 | struct cgit_cmd *cmd; |
| 127 | cgit_query_path, | 292 | |
| 128 | cgit_repo->snapshots ); | 293 | cmd = cgit_get_cmd(ctx); |
| 294 | if (!cmd) { | ||
| 295 | ctx->page.title = "cgit error"; | ||
| 296 | ctx->repo = NULL; | ||
| 297 | cgit_print_http_headers(ctx); | ||
| 298 | cgit_print_docstart(ctx); | ||
| 299 | cgit_print_pageheader(ctx); | ||
| 300 | cgit_print_error("Invalid request"); | ||
| 301 | cgit_print_docend(); | ||
| 129 | return; | 302 | return; |
| 130 | } | 303 | } |
| 131 | 304 | ||
| 132 | if (cgit_cmd == CMD_PATCH) { | 305 | if (cmd->want_repo && prepare_repo_cmd(ctx)) |
| 133 | cgit_print_patch(cgit_query_sha1, item); | ||
| 134 | return; | 306 | return; |
| 135 | } | ||
| 136 | 307 | ||
| 137 | if (cgit_cmd == CMD_BLOB) { | 308 | if (cmd->want_layout) { |
| 138 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 309 | cgit_print_http_headers(ctx); |
| 139 | return; | 310 | cgit_print_docstart(ctx); |
| 311 | cgit_print_pageheader(ctx); | ||
| 140 | } | 312 | } |
| 141 | 313 | ||
| 142 | show_search = (cgit_cmd == CMD_LOG); | 314 | cmd->fn(ctx); |
| 143 | cgit_print_docstart(title, item); | 315 | |
| 144 | if (!cgit_cmd) { | 316 | if (cmd->want_layout) |
| 145 | cgit_print_pageheader("summary", show_search); | ||
| 146 | cgit_print_summary(); | ||
| 147 | cgit_print_docend(); | 317 | cgit_print_docend(); |
| 148 | return; | 318 | } |
| 149 | } | ||
| 150 | 319 | ||
| 151 | cgit_print_pageheader(cgit_query_page, show_search); | 320 | static long ttl_seconds(long ttl) |
| 152 | 321 | { | |
| 153 | switch(cgit_cmd) { | 322 | if (ttl<0) |
| 154 | case CMD_LOG: | 323 | return 60 * 60 * 24 * 365; |
| 155 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 324 | else |
| 156 | cgit_max_commit_count, cgit_query_grep, cgit_query_search, | 325 | return ttl * 60; |
| 157 | cgit_query_path, 1); | ||
| 158 | break; | ||
| 159 | case CMD_TREE: | ||
| 160 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | ||
| 161 | break; | ||
| 162 | case CMD_COMMIT: | ||
| 163 | cgit_print_commit(cgit_query_sha1); | ||
| 164 | break; | ||
| 165 | case CMD_REFS: | ||
| 166 | cgit_print_refs(); | ||
| 167 | break; | ||
| 168 | case CMD_TAG: | ||
| 169 | cgit_print_tag(cgit_query_sha1); | ||
| 170 | break; | ||
| 171 | case CMD_DIFF: | ||
| 172 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); | ||
| 173 | break; | ||
| 174 | default: | ||
| 175 | cgit_print_error("Invalid request"); | ||
| 176 | } | ||
| 177 | cgit_print_docend(); | ||
| 178 | } | 326 | } |
| 179 | 327 | ||
| 180 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 328 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
| 181 | { | 329 | { |
| 182 | static char buf[PATH_MAX]; | ||
| 183 | int stdout2; | 330 | int stdout2; |
| 184 | 331 | ||
| 185 | getcwd(buf, sizeof(buf)); | ||
| 186 | item->st.st_mtime = time(NULL); | ||
| 187 | |||
| 188 | if (use_cache) { | 332 | if (use_cache) { |
| 189 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 333 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
| 190 | "Preserving STDOUT"); | 334 | "Preserving STDOUT"); |
| @@ -192,10 +336,9 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) | |||
| 192 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 336 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
| 193 | } | 337 | } |
| 194 | 338 | ||
| 195 | if (cgit_repo) | 339 | ctx.page.modified = time(NULL); |
| 196 | cgit_print_repo_page(item); | 340 | ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl); |
| 197 | else | 341 | process_request(&ctx); |
| 198 | cgit_print_repolist(item); | ||
| 199 | 342 | ||
| 200 | if (use_cache) { | 343 | if (use_cache) { |
| 201 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 344 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
| @@ -203,8 +346,6 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) | |||
| 203 | "Restoring original STDOUT"); | 346 | "Restoring original STDOUT"); |
| 204 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 347 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
| 205 | } | 348 | } |
| 206 | |||
| 207 | chdir(buf); | ||
| 208 | } | 349 | } |
| 209 | 350 | ||
| 210 | static void cgit_check_cache(struct cacheitem *item) | 351 | static void cgit_check_cache(struct cacheitem *item) |
| @@ -212,7 +353,7 @@ static void cgit_check_cache(struct cacheitem *item) | |||
| 212 | int i = 0; | 353 | int i = 0; |
| 213 | 354 | ||
| 214 | top: | 355 | top: |
| 215 | if (++i > cgit_max_lock_attempts) { | 356 | if (++i > ctx.cfg.max_lock_attempts) { |
| 216 | die("cgit_refresh_cache: unable to lock %s: %s", | 357 | die("cgit_refresh_cache: unable to lock %s: %s", |
| 217 | item->name, strerror(errno)); | 358 | item->name, strerror(errno)); |
| 218 | } | 359 | } |
| @@ -258,30 +399,30 @@ static void cgit_parse_args(int argc, const char **argv) | |||
| 258 | 399 | ||
| 259 | for (i = 1; i < argc; i++) { | 400 | for (i = 1; i < argc; i++) { |
| 260 | if (!strncmp(argv[i], "--cache=", 8)) { | 401 | if (!strncmp(argv[i], "--cache=", 8)) { |
| 261 | cgit_cache_root = xstrdup(argv[i]+8); | 402 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
| 262 | } | 403 | } |
| 263 | if (!strcmp(argv[i], "--nocache")) { | 404 | if (!strcmp(argv[i], "--nocache")) { |
| 264 | cgit_nocache = 1; | 405 | ctx.cfg.nocache = 1; |
| 265 | } | 406 | } |
| 266 | if (!strncmp(argv[i], "--query=", 8)) { | 407 | if (!strncmp(argv[i], "--query=", 8)) { |
| 267 | cgit_querystring = xstrdup(argv[i]+8); | 408 | ctx.qry.raw = xstrdup(argv[i]+8); |
| 268 | } | 409 | } |
| 269 | if (!strncmp(argv[i], "--repo=", 7)) { | 410 | if (!strncmp(argv[i], "--repo=", 7)) { |
| 270 | cgit_query_repo = xstrdup(argv[i]+7); | 411 | ctx.qry.repo = xstrdup(argv[i]+7); |
| 271 | } | 412 | } |
| 272 | if (!strncmp(argv[i], "--page=", 7)) { | 413 | if (!strncmp(argv[i], "--page=", 7)) { |
| 273 | cgit_query_page = xstrdup(argv[i]+7); | 414 | ctx.qry.page = xstrdup(argv[i]+7); |
| 274 | } | 415 | } |
| 275 | if (!strncmp(argv[i], "--head=", 7)) { | 416 | if (!strncmp(argv[i], "--head=", 7)) { |
| 276 | cgit_query_head = xstrdup(argv[i]+7); | 417 | ctx.qry.head = xstrdup(argv[i]+7); |
| 277 | cgit_query_has_symref = 1; | 418 | ctx.qry.has_symref = 1; |
| 278 | } | 419 | } |
| 279 | if (!strncmp(argv[i], "--sha1=", 7)) { | 420 | if (!strncmp(argv[i], "--sha1=", 7)) { |
| 280 | cgit_query_sha1 = xstrdup(argv[i]+7); | 421 | ctx.qry.sha1 = xstrdup(argv[i]+7); |
| 281 | cgit_query_has_sha1 = 1; | 422 | ctx.qry.has_sha1 = 1; |
| 282 | } | 423 | } |
| 283 | if (!strncmp(argv[i], "--ofs=", 6)) { | 424 | if (!strncmp(argv[i], "--ofs=", 6)) { |
| 284 | cgit_query_ofs = atoi(argv[i]+6); | 425 | ctx.qry.ofs = atoi(argv[i]+6); |
| 285 | } | 426 | } |
| 286 | } | 427 | } |
| 287 | } | 428 | } |
| @@ -291,24 +432,24 @@ int main(int argc, const char **argv) | |||
| 291 | struct cacheitem item; | 432 | struct cacheitem item; |
| 292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 433 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
| 293 | 434 | ||
| 294 | htmlfd = STDOUT_FILENO; | 435 | prepare_context(&ctx); |
| 295 | item.st.st_mtime = time(NULL); | 436 | item.st.st_mtime = time(NULL); |
| 296 | cgit_repolist.length = 0; | 437 | cgit_repolist.length = 0; |
| 297 | cgit_repolist.count = 0; | 438 | cgit_repolist.count = 0; |
| 298 | cgit_repolist.repos = NULL; | 439 | cgit_repolist.repos = NULL; |
| 299 | 440 | ||
| 300 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, | 441 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
| 301 | cgit_global_config_cb); | 442 | config_cb); |
| 302 | cgit_repo = NULL; | 443 | ctx.repo = NULL; |
| 303 | if (getenv("SCRIPT_NAME")) | 444 | if (getenv("SCRIPT_NAME")) |
| 304 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); | 445 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
| 305 | if (getenv("QUERY_STRING")) | 446 | if (getenv("QUERY_STRING")) |
| 306 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 447 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
| 307 | cgit_parse_args(argc, argv); | 448 | cgit_parse_args(argc, argv); |
| 308 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 449 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
| 309 | if (!cgit_prepare_cache(&item)) | 450 | if (!cgit_prepare_cache(&item)) |
| 310 | return 0; | 451 | return 0; |
| 311 | if (cgit_nocache) { | 452 | if (ctx.cfg.nocache) { |
| 312 | cgit_fill_cache(&item, 0); | 453 | cgit_fill_cache(&item, 0); |
| 313 | } else { | 454 | } else { |
| 314 | cgit_check_cache(&item); | 455 | cgit_check_cache(&item); |
| @@ -20,19 +20,6 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | /* | 22 | /* |
| 23 | * The valid cgit repo-commands | ||
| 24 | */ | ||
| 25 | #define CMD_LOG 1 | ||
| 26 | #define CMD_COMMIT 2 | ||
| 27 | #define CMD_DIFF 3 | ||
| 28 | #define CMD_TREE 4 | ||
| 29 | #define CMD_BLOB 5 | ||
| 30 | #define CMD_SNAPSHOT 6 | ||
| 31 | #define CMD_TAG 7 | ||
| 32 | #define CMD_REFS 8 | ||
| 33 | #define CMD_PATCH 9 | ||
| 34 | |||
| 35 | /* | ||
| 36 | * Dateformats used on misc. pages | 23 | * Dateformats used on misc. pages |
| 37 | */ | 24 | */ |
| 38 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 25 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
| @@ -59,14 +46,7 @@ typedef void (*configfn)(const char *name, const char *value); | |||
| 59 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 46 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
| 60 | typedef void (*linediff_fn)(char *line, int len); | 47 | typedef void (*linediff_fn)(char *line, int len); |
| 61 | 48 | ||
| 62 | struct cacheitem { | 49 | struct cgit_repo { |
| 63 | char *name; | ||
| 64 | struct stat st; | ||
| 65 | int ttl; | ||
| 66 | int fd; | ||
| 67 | }; | ||
| 68 | |||
| 69 | struct repoinfo { | ||
| 70 | char *url; | 50 | char *url; |
| 71 | char *name; | 51 | char *name; |
| 72 | char *path; | 52 | char *path; |
| @@ -82,10 +62,10 @@ struct repoinfo { | |||
| 82 | int enable_log_linecount; | 62 | int enable_log_linecount; |
| 83 | }; | 63 | }; |
| 84 | 64 | ||
| 85 | struct repolist { | 65 | struct cgit_repolist { |
| 86 | int length; | 66 | int length; |
| 87 | int count; | 67 | int count; |
| 88 | struct repoinfo *repos; | 68 | struct cgit_repo *repos; |
| 89 | }; | 69 | }; |
| 90 | 70 | ||
| 91 | struct commitinfo { | 71 | struct commitinfo { |
| @@ -123,74 +103,94 @@ struct reflist { | |||
| 123 | int count; | 103 | int count; |
| 124 | }; | 104 | }; |
| 125 | 105 | ||
| 106 | struct cgit_query { | ||
| 107 | int has_symref; | ||
| 108 | int has_sha1; | ||
| 109 | char *raw; | ||
| 110 | char *repo; | ||
| 111 | char *page; | ||
| 112 | char *search; | ||
| 113 | char *grep; | ||
| 114 | char *head; | ||
| 115 | char *sha1; | ||
| 116 | char *sha2; | ||
| 117 | char *path; | ||
| 118 | char *name; | ||
| 119 | int ofs; | ||
| 120 | }; | ||
| 121 | |||
| 122 | struct cgit_config { | ||
| 123 | char *agefile; | ||
| 124 | char *cache_root; | ||
| 125 | char *clone_prefix; | ||
| 126 | char *css; | ||
| 127 | char *index_header; | ||
| 128 | char *index_info; | ||
| 129 | char *logo; | ||
| 130 | char *logo_link; | ||
| 131 | char *module_link; | ||
| 132 | char *repo_group; | ||
| 133 | char *robots; | ||
| 134 | char *root_title; | ||
| 135 | char *script_name; | ||
| 136 | char *virtual_root; | ||
| 137 | int cache_dynamic_ttl; | ||
| 138 | int cache_max_create_time; | ||
| 139 | int cache_repo_ttl; | ||
| 140 | int cache_root_ttl; | ||
| 141 | int cache_static_ttl; | ||
| 142 | int enable_index_links; | ||
| 143 | int enable_log_filecount; | ||
| 144 | int enable_log_linecount; | ||
| 145 | int max_commit_count; | ||
| 146 | int max_lock_attempts; | ||
| 147 | int max_msg_len; | ||
| 148 | int max_repodesc_len; | ||
| 149 | int nocache; | ||
| 150 | int renamelimit; | ||
| 151 | int snapshots; | ||
| 152 | int summary_branches; | ||
| 153 | int summary_log; | ||
| 154 | int summary_tags; | ||
| 155 | }; | ||
| 156 | |||
| 157 | struct cgit_page { | ||
| 158 | time_t modified; | ||
| 159 | time_t expires; | ||
| 160 | char *mimetype; | ||
| 161 | char *charset; | ||
| 162 | char *filename; | ||
| 163 | char *title; | ||
| 164 | }; | ||
| 165 | |||
| 166 | struct cgit_context { | ||
| 167 | struct cgit_query qry; | ||
| 168 | struct cgit_config cfg; | ||
| 169 | struct cgit_repo *repo; | ||
| 170 | struct cgit_page page; | ||
| 171 | }; | ||
| 172 | |||
| 173 | struct cgit_snapshot_format { | ||
| 174 | const char *suffix; | ||
| 175 | const char *mimetype; | ||
| 176 | write_archive_fn_t write_func; | ||
| 177 | int bit; | ||
| 178 | }; | ||
| 179 | |||
| 126 | extern const char *cgit_version; | 180 | extern const char *cgit_version; |
| 127 | 181 | ||
| 128 | extern struct repolist cgit_repolist; | 182 | extern struct cgit_repolist cgit_repolist; |
| 129 | extern struct repoinfo *cgit_repo; | 183 | extern struct cgit_context ctx; |
| 130 | extern int cgit_cmd; | 184 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
| 131 | 185 | ||
| 132 | extern char *cgit_root_title; | 186 | extern struct cgit_repo *cgit_add_repo(const char *url); |
| 133 | extern char *cgit_css; | 187 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
| 134 | extern char *cgit_logo; | ||
| 135 | extern char *cgit_index_header; | ||
| 136 | extern char *cgit_index_info; | ||
| 137 | extern char *cgit_logo_link; | ||
| 138 | extern char *cgit_module_link; | ||
| 139 | extern char *cgit_agefile; | ||
| 140 | extern char *cgit_virtual_root; | ||
| 141 | extern char *cgit_script_name; | ||
| 142 | extern char *cgit_cache_root; | ||
| 143 | extern char *cgit_repo_group; | ||
| 144 | extern char *cgit_robots; | ||
| 145 | extern char *cgit_clone_prefix; | ||
| 146 | |||
| 147 | extern int cgit_nocache; | ||
| 148 | extern int cgit_snapshots; | ||
| 149 | extern int cgit_enable_index_links; | ||
| 150 | extern int cgit_enable_log_filecount; | ||
| 151 | extern int cgit_enable_log_linecount; | ||
| 152 | extern int cgit_max_lock_attempts; | ||
| 153 | extern int cgit_cache_root_ttl; | ||
| 154 | extern int cgit_cache_repo_ttl; | ||
| 155 | extern int cgit_cache_dynamic_ttl; | ||
| 156 | extern int cgit_cache_static_ttl; | ||
| 157 | extern int cgit_cache_max_create_time; | ||
| 158 | extern int cgit_summary_log; | ||
| 159 | extern int cgit_summary_tags; | ||
| 160 | extern int cgit_summary_branches; | ||
| 161 | |||
| 162 | extern int cgit_max_msg_len; | ||
| 163 | extern int cgit_max_repodesc_len; | ||
| 164 | extern int cgit_max_commit_count; | ||
| 165 | |||
| 166 | extern int cgit_query_has_symref; | ||
| 167 | extern int cgit_query_has_sha1; | ||
| 168 | |||
| 169 | extern char *cgit_querystring; | ||
| 170 | extern char *cgit_query_repo; | ||
| 171 | extern char *cgit_query_page; | ||
| 172 | extern char *cgit_query_search; | ||
| 173 | extern char *cgit_query_grep; | ||
| 174 | extern char *cgit_query_head; | ||
| 175 | extern char *cgit_query_sha1; | ||
| 176 | extern char *cgit_query_sha2; | ||
| 177 | extern char *cgit_query_path; | ||
| 178 | extern char *cgit_query_name; | ||
| 179 | extern int cgit_query_ofs; | ||
| 180 | |||
| 181 | extern int htmlfd; | ||
| 182 | |||
| 183 | extern int cgit_get_cmd_index(const char *cmd); | ||
| 184 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | ||
| 185 | extern void cgit_global_config_cb(const char *name, const char *value); | ||
| 186 | extern void cgit_repo_config_cb(const char *name, const char *value); | 188 | extern void cgit_repo_config_cb(const char *name, const char *value); |
| 187 | extern void cgit_querystring_cb(const char *name, const char *value); | ||
| 188 | 189 | ||
| 189 | extern int chk_zero(int result, char *msg); | 190 | extern int chk_zero(int result, char *msg); |
| 190 | extern int chk_positive(int result, char *msg); | 191 | extern int chk_positive(int result, char *msg); |
| 191 | extern int chk_non_negative(int result, char *msg); | 192 | extern int chk_non_negative(int result, char *msg); |
| 192 | 193 | ||
| 193 | extern int hextoint(char c); | ||
| 194 | extern char *trim_end(const char *str, char c); | 194 | extern char *trim_end(const char *str, char c); |
| 195 | extern char *strlpart(char *txt, int maxlen); | 195 | extern char *strlpart(char *txt, int maxlen); |
| 196 | extern char *strrpart(char *txt, int maxlen); | 196 | extern char *strrpart(char *txt, int maxlen); |
| @@ -213,83 +213,12 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | |||
| 213 | 213 | ||
| 214 | extern char *fmt(const char *format,...); | 214 | extern char *fmt(const char *format,...); |
| 215 | 215 | ||
| 216 | extern void html(const char *txt); | ||
| 217 | extern void htmlf(const char *format,...); | ||
| 218 | extern void html_txt(char *txt); | ||
| 219 | extern void html_ntxt(int len, char *txt); | ||
| 220 | extern void html_attr(char *txt); | ||
| 221 | extern void html_hidden(char *name, char *value); | ||
| 222 | extern void html_option(char *value, char *text, char *selected_value); | ||
| 223 | extern void html_link_open(char *url, char *title, char *class); | ||
| 224 | extern void html_link_close(void); | ||
| 225 | extern void html_filemode(unsigned short mode); | ||
| 226 | extern int html_include(const char *filename); | ||
| 227 | |||
| 228 | extern int cgit_read_config(const char *filename, configfn fn); | ||
| 229 | extern int cgit_parse_query(char *txt, configfn fn); | ||
| 230 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 216 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
| 231 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 217 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
| 232 | extern void cgit_parse_url(const char *url); | 218 | extern void cgit_parse_url(const char *url); |
| 233 | 219 | ||
| 234 | extern char *cache_safe_filename(const char *unsafe); | ||
| 235 | extern int cache_lock(struct cacheitem *item); | ||
| 236 | extern int cache_unlock(struct cacheitem *item); | ||
| 237 | extern int cache_cancel_lock(struct cacheitem *item); | ||
| 238 | extern int cache_exist(struct cacheitem *item); | ||
| 239 | extern int cache_expired(struct cacheitem *item); | ||
| 240 | |||
| 241 | extern char *cgit_repourl(const char *reponame); | ||
| 242 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | ||
| 243 | const char *filename, const char *query); | ||
| 244 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | ||
| 245 | const char *query); | ||
| 246 | |||
| 247 | extern const char *cgit_repobasename(const char *reponame); | 220 | extern const char *cgit_repobasename(const char *reponame); |
| 248 | 221 | ||
| 249 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | ||
| 250 | char *rev, char *path); | ||
| 251 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | ||
| 252 | char *rev, char *path, int ofs, char *grep, | ||
| 253 | char *pattern); | ||
| 254 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
| 255 | char *rev); | ||
| 256 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | ||
| 257 | char *rev, char *path); | ||
| 258 | extern void cgit_snapshot_link(char *name, char *title, char *class, | ||
| 259 | char *head, char *rev, char *archivename); | ||
| 260 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | ||
| 261 | char *new_rev, char *old_rev, char *path); | ||
| 262 | |||
| 263 | extern void cgit_object_link(struct object *obj); | ||
| 264 | |||
| 265 | extern void cgit_print_error(char *msg); | ||
| 266 | extern void cgit_print_date(time_t secs, char *format); | ||
| 267 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | ||
| 268 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | ||
| 269 | extern void cgit_print_docend(); | ||
| 270 | extern void cgit_print_pageheader(char *title, int show_search); | ||
| 271 | extern void cgit_print_snapshot_start(const char *mimetype, | ||
| 272 | const char *filename, | ||
| 273 | struct cacheitem *item); | ||
| 274 | extern void cgit_print_branches(int maxcount); | ||
| 275 | extern void cgit_print_tags(int maxcount); | ||
| 276 | |||
| 277 | extern void cgit_print_repolist(struct cacheitem *item); | ||
| 278 | extern void cgit_print_summary(); | ||
| 279 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, | ||
| 280 | char *pattern, char *path, int pager); | ||
| 281 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | ||
| 282 | extern void cgit_print_tree(const char *rev, char *path); | ||
| 283 | extern void cgit_print_commit(char *hex); | ||
| 284 | extern void cgit_print_refs(); | ||
| 285 | extern void cgit_print_tag(char *revname); | ||
| 286 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | ||
| 287 | extern void cgit_print_patch(char *hex, struct cacheitem *item); | ||
| 288 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | ||
| 289 | const char *hex, const char *prefix, | ||
| 290 | const char *filename, int snapshot); | ||
| 291 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | ||
| 292 | const char *hex, int snapshots); | ||
| 293 | extern int cgit_parse_snapshots_mask(const char *str); | 222 | extern int cgit_parse_snapshots_mask(const char *str); |
| 294 | 223 | ||
| 295 | #endif /* CGIT_H */ | 224 | #endif /* CGIT_H */ |
| @@ -0,0 +1,112 @@ | |||
| 1 | /* cmd.c: the cgit command dispatcher | ||
| 2 | * | ||
| 3 | * Copyright (C) 2008 Lars Hjemli | ||
| 4 | * | ||
| 5 | * Licensed under GNU General Public License v2 | ||
| 6 | * (see COPYING for full license text) | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "cgit.h" | ||
| 10 | #include "cmd.h" | ||
| 11 | #include "ui-blob.h" | ||
| 12 | #include "ui-commit.h" | ||
| 13 | #include "ui-diff.h" | ||
| 14 | #include "ui-log.h" | ||
| 15 | #include "ui-patch.h" | ||
| 16 | #include "ui-refs.h" | ||
| 17 | #include "ui-repolist.h" | ||
| 18 | #include "ui-snapshot.h" | ||
| 19 | #include "ui-summary.h" | ||
| 20 | #include "ui-tag.h" | ||
| 21 | #include "ui-tree.h" | ||
| 22 | |||
| 23 | static void blob_fn(struct cgit_context *ctx) | ||
| 24 | { | ||
| 25 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path); | ||
| 26 | } | ||
| 27 | |||
| 28 | static void commit_fn(struct cgit_context *ctx) | ||
| 29 | { | ||
| 30 | cgit_print_commit(ctx->qry.sha1); | ||
| 31 | } | ||
| 32 | |||
| 33 | static void diff_fn(struct cgit_context *ctx) | ||
| 34 | { | ||
| 35 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); | ||
| 36 | } | ||
| 37 | |||
| 38 | static void repolist_fn(struct cgit_context *ctx) | ||
| 39 | { | ||
| 40 | cgit_print_repolist(); | ||
| 41 | } | ||
| 42 | |||
| 43 | static void log_fn(struct cgit_context *ctx) | ||
| 44 | { | ||
| 45 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, | ||
| 46 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); | ||
| 47 | } | ||
| 48 | |||
| 49 | static void patch_fn(struct cgit_context *ctx) | ||
| 50 | { | ||
| 51 | cgit_print_patch(ctx->qry.sha1); | ||
| 52 | } | ||
| 53 | |||
| 54 | static void refs_fn(struct cgit_context *ctx) | ||
| 55 | { | ||
| 56 | cgit_print_refs(); | ||
| 57 | } | ||
| 58 | |||
| 59 | static void snapshot_fn(struct cgit_context *ctx) | ||
| 60 | { | ||
| 61 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, | ||
| 62 | cgit_repobasename(ctx->repo->url), ctx->qry.path, | ||
| 63 | ctx->repo->snapshots); | ||
| 64 | } | ||
| 65 | |||
| 66 | static void summary_fn(struct cgit_context *ctx) | ||
| 67 | { | ||
| 68 | cgit_print_summary(); | ||
| 69 | } | ||
| 70 | |||
| 71 | static void tag_fn(struct cgit_context *ctx) | ||
| 72 | { | ||
| 73 | cgit_print_tag(ctx->qry.sha1); | ||
| 74 | } | ||
| 75 | |||
| 76 | static void tree_fn(struct cgit_context *ctx) | ||
| 77 | { | ||
| 78 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); | ||
| 79 | } | ||
| 80 | |||
| 81 | #define def_cmd(name, want_repo, want_layout) \ | ||
| 82 | {#name, name##_fn, want_repo, want_layout} | ||
| 83 | |||
| 84 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) | ||
| 85 | { | ||
| 86 | static struct cgit_cmd cmds[] = { | ||
| 87 | def_cmd(blob, 1, 0), | ||
| 88 | def_cmd(commit, 1, 1), | ||
| 89 | def_cmd(diff, 1, 1), | ||
| 90 | def_cmd(log, 1, 1), | ||
| 91 | def_cmd(patch, 1, 0), | ||
| 92 | def_cmd(refs, 1, 1), | ||
| 93 | def_cmd(repolist, 0, 0), | ||
| 94 | def_cmd(snapshot, 1, 0), | ||
| 95 | def_cmd(summary, 1, 1), | ||
| 96 | def_cmd(tag, 1, 1), | ||
| 97 | def_cmd(tree, 1, 1), | ||
| 98 | }; | ||
| 99 | int i; | ||
| 100 | |||
| 101 | if (ctx->qry.page == NULL) { | ||
| 102 | if (ctx->repo) | ||
| 103 | ctx->qry.page = "summary"; | ||
| 104 | else | ||
| 105 | ctx->qry.page = "repolist"; | ||
| 106 | } | ||
| 107 | |||
| 108 | for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) | ||
| 109 | if (!strcmp(ctx->qry.page, cmds[i].name)) | ||
| 110 | return &cmds[i]; | ||
| 111 | return NULL; | ||
| 112 | } | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifndef CMD_H | ||
| 2 | #define CMD_H | ||
| 3 | |||
| 4 | typedef void (*cgit_cmd_fn)(struct cgit_context *ctx); | ||
| 5 | |||
| 6 | struct cgit_cmd { | ||
| 7 | const char *name; | ||
| 8 | cgit_cmd_fn fn; | ||
| 9 | unsigned int want_repo:1, | ||
| 10 | want_layout:1; | ||
| 11 | }; | ||
| 12 | |||
| 13 | extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx); | ||
| 14 | |||
| 15 | #endif /* CMD_H */ | ||
diff --git a/configfile.c b/configfile.c new file mode 100644 index 0000000..4908058 --- /dev/null +++ b/configfile.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* configfile.c: parsing of config files | ||
| 2 | * | ||
| 3 | * Copyright (C) 2008 Lars Hjemli | ||
| 4 | * | ||
| 5 | * Licensed under GNU General Public License v2 | ||
| 6 | * (see COPYING for full license text) | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <ctype.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include "configfile.h" | ||
| 12 | |||
| 13 | int next_char(FILE *f) | ||
| 14 | { | ||
| 15 | int c = fgetc(f); | ||
| 16 | if (c=='\r') { | ||
| 17 | c = fgetc(f); | ||
| 18 | if (c!='\n') { | ||
| 19 | ungetc(c, f); | ||
| 20 | c = '\r'; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | return c; | ||
| 24 | } | ||
| 25 | |||
| 26 | void skip_line(FILE *f) | ||
| 27 | { | ||
| 28 | int c; | ||
| 29 | |||
| 30 | while((c=next_char(f)) && c!='\n' && c!=EOF) | ||
| 31 | ; | ||
| 32 | } | ||
| 33 | |||
| 34 | int read_config_line(FILE *f, char *line, const char **value, int bufsize) | ||
| 35 | { | ||
| 36 | int i = 0, isname = 0; | ||
| 37 | |||
| 38 | *value = NULL; | ||
| 39 | while(i<bufsize-1) { | ||
| 40 | int c = next_char(f); | ||
| 41 | if (!isname && (c=='#' || c==';')) { | ||
| 42 | skip_line(f); | ||
| 43 | continue; | ||
| 44 | } | ||
| 45 | if (!isname && isspace(c)) | ||
| 46 | continue; | ||
| 47 | |||
| 48 | if (c=='=' && !*value) { | ||
| 49 | line[i] = 0; | ||
| 50 | *value = &line[i+1]; | ||
| 51 | } else if (c=='\n' && !isname) { | ||
| 52 | i = 0; | ||
| 53 | continue; | ||
| 54 | } else if (c=='\n' || c==EOF) { | ||
| 55 | line[i] = 0; | ||
| 56 | break; | ||
| 57 | } else { | ||
| 58 | line[i]=c; | ||
| 59 | } | ||
| 60 | isname = 1; | ||
| 61 | i++; | ||
| 62 | } | ||
| 63 | line[i+1] = 0; | ||
| 64 | return i; | ||
| 65 | } | ||
| 66 | |||
| 67 | int parse_configfile(const char *filename, configfile_value_fn fn) | ||
| 68 | { | ||
| 69 | static int nesting; | ||
| 70 | int len; | ||
| 71 | char line[256]; | ||
| 72 | const char *value; | ||
| 73 | FILE *f; | ||
| 74 | |||
| 75 | /* cancel deeply nested include-commands */ | ||
| 76 | if (nesting > 8) | ||
| 77 | return -1; | ||
| 78 | if (!(f = fopen(filename, "r"))) | ||
| 79 | return -1; | ||
| 80 | nesting++; | ||
| 81 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) | ||
| 82 | fn(line, value); | ||
| 83 | nesting--; | ||
| 84 | fclose(f); | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | |||
diff --git a/configfile.h b/configfile.h new file mode 100644 index 0000000..04235e5 --- /dev/null +++ b/configfile.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #ifndef CONFIGFILE_H | ||
| 2 | #define CONFIGFILE_H | ||
| 3 | |||
| 4 | typedef void (*configfile_value_fn)(const char *name, const char *value); | ||
| 5 | |||
| 6 | extern int parse_configfile(const char *filename, configfile_value_fn fn); | ||
| 7 | |||
| 8 | #endif /* CONFIGFILE_H */ | ||
| @@ -6,7 +6,13 @@ | |||
| 6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include <unistd.h> |
| 10 | #include <stdio.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <stdarg.h> | ||
| 13 | #include <string.h> | ||
| 14 | |||
| 15 | int htmlfd = STDOUT_FILENO; | ||
| 10 | 16 | ||
| 11 | char *fmt(const char *format, ...) | 17 | char *fmt(const char *format, ...) |
| 12 | { | 18 | { |
| @@ -21,8 +27,10 @@ char *fmt(const char *format, ...) | |||
| 21 | va_start(args, format); | 27 | va_start(args, format); |
| 22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 28 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
| 23 | va_end(args); | 29 | va_end(args); |
| 24 | if (len>sizeof(buf[bufidx])) | 30 | if (len>sizeof(buf[bufidx])) { |
| 25 | die("[html.c] string truncated: %s", format); | 31 | fprintf(stderr, "[html.c] string truncated: %s\n", format); |
| 32 | exit(1); | ||
| 33 | } | ||
| 26 | return buf[bufidx]; | 34 | return buf[bufidx]; |
| 27 | } | 35 | } |
| 28 | 36 | ||
| @@ -150,25 +158,10 @@ void html_link_close(void) | |||
| 150 | 158 | ||
| 151 | void html_fileperm(unsigned short mode) | 159 | void html_fileperm(unsigned short mode) |
| 152 | { | 160 | { |
| 153 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 161 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
| 154 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 162 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
| 155 | } | 163 | } |
| 156 | 164 | ||
| 157 | void html_filemode(unsigned short mode) | ||
| 158 | { | ||
| 159 | if (S_ISDIR(mode)) | ||
| 160 | html("d"); | ||
| 161 | else if (S_ISLNK(mode)) | ||
| 162 | html("l"); | ||
| 163 | else if (S_ISGITLINK(mode)) | ||
| 164 | html("m"); | ||
| 165 | else | ||
| 166 | html("-"); | ||
| 167 | html_fileperm(mode >> 6); | ||
| 168 | html_fileperm(mode >> 3); | ||
| 169 | html_fileperm(mode); | ||
| 170 | } | ||
| 171 | |||
| 172 | int html_include(const char *filename) | 165 | int html_include(const char *filename) |
| 173 | { | 166 | { |
| 174 | FILE *f; | 167 | FILE *f; |
| @@ -182,3 +175,67 @@ int html_include(const char *filename) | |||
| 182 | fclose(f); | 175 | fclose(f); |
| 183 | return 0; | 176 | return 0; |
| 184 | } | 177 | } |
| 178 | |||
| 179 | int hextoint(char c) | ||
| 180 | { | ||
| 181 | if (c >= 'a' && c <= 'f') | ||
| 182 | return 10 + c - 'a'; | ||
| 183 | else if (c >= 'A' && c <= 'F') | ||
| 184 | return 10 + c - 'A'; | ||
| 185 | else if (c >= '0' && c <= '9') | ||
| 186 | return c - '0'; | ||
| 187 | else | ||
| 188 | return -1; | ||
| 189 | } | ||
| 190 | |||
| 191 | char *convert_query_hexchar(char *txt) | ||
| 192 | { | ||
| 193 | int d1, d2; | ||
| 194 | if (strlen(txt) < 3) { | ||
| 195 | *txt = '\0'; | ||
| 196 | return txt-1; | ||
| 197 | } | ||
| 198 | d1 = hextoint(*(txt+1)); | ||
| 199 | d2 = hextoint(*(txt+2)); | ||
| 200 | if (d1<0 || d2<0) { | ||
| 201 | strcpy(txt, txt+3); | ||
| 202 | return txt-1; | ||
| 203 | } else { | ||
| 204 | *txt = d1 * 16 + d2; | ||
| 205 | strcpy(txt+1, txt+3); | ||
| 206 | return txt; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) | ||
| 211 | { | ||
| 212 | char *t, *value = NULL, c; | ||
| 213 | |||
| 214 | if (!txt) | ||
| 215 | return 0; | ||
| 216 | |||
| 217 | t = txt = strdup(txt); | ||
| 218 | if (t == NULL) { | ||
| 219 | printf("Out of memory\n"); | ||
| 220 | exit(1); | ||
| 221 | } | ||
| 222 | while((c=*t) != '\0') { | ||
| 223 | if (c=='=') { | ||
| 224 | *t = '\0'; | ||
| 225 | value = t+1; | ||
| 226 | } else if (c=='+') { | ||
| 227 | *t = ' '; | ||
| 228 | } else if (c=='%') { | ||
| 229 | t = convert_query_hexchar(t); | ||
| 230 | } else if (c=='&') { | ||
| 231 | *t = '\0'; | ||
| 232 | (*fn)(txt, value); | ||
| 233 | txt = t+1; | ||
| 234 | value = NULL; | ||
| 235 | } | ||
| 236 | t++; | ||
| 237 | } | ||
| 238 | if (t!=txt) | ||
| 239 | (*fn)(txt, value); | ||
| 240 | return 0; | ||
| 241 | } | ||
| @@ -0,0 +1,20 @@ | |||
| 1 | #ifndef HTML_H | ||
| 2 | #define HTML_H | ||
| 3 | |||
| 4 | extern int htmlfd; | ||
| 5 | |||
| 6 | extern void html(const char *txt); | ||
| 7 | extern void htmlf(const char *format,...); | ||
| 8 | extern void html_txt(char *txt); | ||
| 9 | extern void html_ntxt(int len, char *txt); | ||
| 10 | extern void html_attr(char *txt); | ||
| 11 | extern void html_hidden(char *name, char *value); | ||
| 12 | extern void html_option(char *value, char *text, char *selected_value); | ||
| 13 | extern void html_link_open(char *url, char *title, char *class); | ||
| 14 | extern void html_link_close(void); | ||
| 15 | extern void html_fileperm(unsigned short mode); | ||
| 16 | extern int html_include(const char *filename); | ||
| 17 | |||
| 18 | extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); | ||
| 19 | |||
| 20 | #endif /* HTML_H */ | ||
| @@ -8,130 +8,6 @@ | |||
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | 10 | ||
| 11 | int next_char(FILE *f) | ||
| 12 | { | ||
| 13 | int c = fgetc(f); | ||
| 14 | if (c=='\r') { | ||
| 15 | c = fgetc(f); | ||
| 16 | if (c!='\n') { | ||
| 17 | ungetc(c, f); | ||
| 18 | c = '\r'; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | return c; | ||
| 22 | } | ||
| 23 | |||
| 24 | void skip_line(FILE *f) | ||
| 25 | { | ||
| 26 | int c; | ||
| 27 | |||
| 28 | while((c=next_char(f)) && c!='\n' && c!=EOF) | ||
| 29 | ; | ||
| 30 | } | ||
| 31 | |||
| 32 | int read_config_line(FILE *f, char *line, const char **value, int bufsize) | ||
| 33 | { | ||
| 34 | int i = 0, isname = 0; | ||
| 35 | |||
| 36 | *value = NULL; | ||
| 37 | while(i<bufsize-1) { | ||
| 38 | int c = next_char(f); | ||
| 39 | if (!isname && (c=='#' || c==';')) { | ||
| 40 | skip_line(f); | ||
| 41 | continue; | ||
| 42 | } | ||
| 43 | if (!isname && isspace(c)) | ||
| 44 | continue; | ||
| 45 | |||
| 46 | if (c=='=' && !*value) { | ||
| 47 | line[i] = 0; | ||
| 48 | *value = &line[i+1]; | ||
| 49 | } else if (c=='\n' && !isname) { | ||
| 50 | i = 0; | ||
| 51 | continue; | ||
| 52 | } else if (c=='\n' || c==EOF) { | ||
| 53 | line[i] = 0; | ||
| 54 | break; | ||
| 55 | } else { | ||
| 56 | line[i]=c; | ||
| 57 | } | ||
| 58 | isname = 1; | ||
| 59 | i++; | ||
| 60 | } | ||
| 61 | line[i+1] = 0; | ||
| 62 | return i; | ||
| 63 | } | ||
| 64 | |||
| 65 | int cgit_read_config(const char *filename, configfn fn) | ||
| 66 | { | ||
| 67 | static int nesting; | ||
| 68 | int len; | ||
| 69 | char line[256]; | ||
| 70 | const char *value; | ||
| 71 | FILE *f; | ||
| 72 | |||
| 73 | /* cancel deeply nested include-commands */ | ||
| 74 | if (nesting > 8) | ||
| 75 | return -1; | ||
| 76 | if (!(f = fopen(filename, "r"))) | ||
| 77 | return -1; | ||
| 78 | nesting++; | ||
| 79 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) | ||
| 80 | (*fn)(line, value); | ||
| 81 | nesting--; | ||
| 82 | fclose(f); | ||
| 83 | return 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | char *convert_query_hexchar(char *txt) | ||
| 87 | { | ||
| 88 | int d1, d2; | ||
| 89 | if (strlen(txt) < 3) { | ||
| 90 | *txt = '\0'; | ||
| 91 | return txt-1; | ||
| 92 | } | ||
| 93 | d1 = hextoint(*(txt+1)); | ||
| 94 | d2 = hextoint(*(txt+2)); | ||
| 95 | if (d1<0 || d2<0) { | ||
| 96 | strcpy(txt, txt+3); | ||
| 97 | return txt-1; | ||
| 98 | } else { | ||
| 99 | *txt = d1 * 16 + d2; | ||
| 100 | strcpy(txt+1, txt+3); | ||
| 101 | return txt; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | int cgit_parse_query(char *txt, configfn fn) | ||
| 106 | { | ||
| 107 | char *t, *value = NULL, c; | ||
| 108 | |||
| 109 | if (!txt) | ||
| 110 | return 0; | ||
| 111 | |||
| 112 | t = txt = xstrdup(txt); | ||
| 113 | |||
| 114 | while((c=*t) != '\0') { | ||
| 115 | if (c=='=') { | ||
| 116 | *t = '\0'; | ||
| 117 | value = t+1; | ||
| 118 | } else if (c=='+') { | ||
| 119 | *t = ' '; | ||
| 120 | } else if (c=='%') { | ||
| 121 | t = convert_query_hexchar(t); | ||
| 122 | } else if (c=='&') { | ||
| 123 | *t = '\0'; | ||
| 124 | (*fn)(txt, value); | ||
| 125 | txt = t+1; | ||
| 126 | value = NULL; | ||
| 127 | } | ||
| 128 | t++; | ||
| 129 | } | ||
| 130 | if (t!=txt) | ||
| 131 | (*fn)(txt, value); | ||
| 132 | return 0; | ||
| 133 | } | ||
| 134 | |||
| 135 | /* | 11 | /* |
| 136 | * url syntax: [repo ['/' cmd [ '/' path]]] | 12 | * url syntax: [repo ['/' cmd [ '/' path]]] |
| 137 | * repo: any valid repo url, may contain '/' | 13 | * repo: any valid repo url, may contain '/' |
| @@ -143,35 +19,35 @@ void cgit_parse_url(const char *url) | |||
| 143 | { | 19 | { |
| 144 | char *cmd, *p; | 20 | char *cmd, *p; |
| 145 | 21 | ||
| 146 | cgit_repo = NULL; | 22 | ctx.repo = NULL; |
| 147 | if (!url || url[0] == '\0') | 23 | if (!url || url[0] == '\0') |
| 148 | return; | 24 | return; |
| 149 | 25 | ||
| 150 | cgit_repo = cgit_get_repoinfo(url); | 26 | ctx.repo = cgit_get_repoinfo(url); |
| 151 | if (cgit_repo) { | 27 | if (ctx.repo) { |
| 152 | cgit_query_repo = cgit_repo->url; | 28 | ctx.qry.repo = ctx.repo->url; |
| 153 | return; | 29 | return; |
| 154 | } | 30 | } |
| 155 | 31 | ||
| 156 | cmd = strchr(url, '/'); | 32 | cmd = strchr(url, '/'); |
| 157 | while (!cgit_repo && cmd) { | 33 | while (!ctx.repo && cmd) { |
| 158 | cmd[0] = '\0'; | 34 | cmd[0] = '\0'; |
| 159 | cgit_repo = cgit_get_repoinfo(url); | 35 | ctx.repo = cgit_get_repoinfo(url); |
| 160 | if (cgit_repo == NULL) { | 36 | if (ctx.repo == NULL) { |
| 161 | cmd[0] = '/'; | 37 | cmd[0] = '/'; |
| 162 | cmd = strchr(cmd + 1, '/'); | 38 | cmd = strchr(cmd + 1, '/'); |
| 163 | continue; | 39 | continue; |
| 164 | } | 40 | } |
| 165 | 41 | ||
| 166 | cgit_query_repo = cgit_repo->url; | 42 | ctx.qry.repo = ctx.repo->url; |
| 167 | p = strchr(cmd + 1, '/'); | 43 | p = strchr(cmd + 1, '/'); |
| 168 | if (p) { | 44 | if (p) { |
| 169 | p[0] = '\0'; | 45 | p[0] = '\0'; |
| 170 | if (p[1]) | 46 | if (p[1]) |
| 171 | cgit_query_path = trim_end(p + 1, '/'); | 47 | ctx.qry.path = trim_end(p + 1, '/'); |
| 172 | } | 48 | } |
| 173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); | 49 | if (cmd[1]) |
| 174 | cgit_query_page = xstrdup(cmd + 1); | 50 | ctx.qry.page = xstrdup(cmd + 1); |
| 175 | return; | 51 | return; |
| 176 | } | 52 | } |
| 177 | } | 53 | } |
| @@ -8,77 +8,10 @@ | |||
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | 10 | ||
| 11 | struct repolist cgit_repolist; | 11 | struct cgit_repolist cgit_repolist; |
| 12 | struct repoinfo *cgit_repo; | 12 | struct cgit_context ctx; |
| 13 | int cgit_cmd; | 13 | int cgit_cmd; |
| 14 | 14 | ||
| 15 | const char *cgit_version = CGIT_VERSION; | ||
| 16 | |||
| 17 | char *cgit_root_title = "Git repository browser"; | ||
| 18 | char *cgit_css = "/cgit.css"; | ||
| 19 | char *cgit_logo = "/git-logo.png"; | ||
| 20 | char *cgit_index_header = NULL; | ||
| 21 | char *cgit_index_info = NULL; | ||
| 22 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | ||
| 23 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | ||
| 24 | char *cgit_agefile = "info/web/last-modified"; | ||
| 25 | char *cgit_virtual_root = NULL; | ||
| 26 | char *cgit_script_name = CGIT_SCRIPT_NAME; | ||
| 27 | char *cgit_cache_root = CGIT_CACHE_ROOT; | ||
| 28 | char *cgit_repo_group = NULL; | ||
| 29 | char *cgit_robots = "index, nofollow"; | ||
| 30 | char *cgit_clone_prefix = NULL; | ||
| 31 | |||
| 32 | int cgit_nocache = 0; | ||
| 33 | int cgit_snapshots = 0; | ||
| 34 | int cgit_enable_index_links = 0; | ||
| 35 | int cgit_enable_log_filecount = 0; | ||
| 36 | int cgit_enable_log_linecount = 0; | ||
| 37 | int cgit_max_lock_attempts = 5; | ||
| 38 | int cgit_cache_root_ttl = 5; | ||
| 39 | int cgit_cache_repo_ttl = 5; | ||
| 40 | int cgit_cache_dynamic_ttl = 5; | ||
| 41 | int cgit_cache_static_ttl = -1; | ||
| 42 | int cgit_cache_max_create_time = 5; | ||
| 43 | int cgit_summary_log = 0; | ||
| 44 | int cgit_summary_tags = 0; | ||
| 45 | int cgit_summary_branches = 0; | ||
| 46 | int cgit_renamelimit = -1; | ||
| 47 | |||
| 48 | int cgit_max_msg_len = 60; | ||
| 49 | int cgit_max_repodesc_len = 60; | ||
| 50 | int cgit_max_commit_count = 50; | ||
| 51 | |||
| 52 | int cgit_query_has_symref = 0; | ||
| 53 | int cgit_query_has_sha1 = 0; | ||
| 54 | |||
| 55 | char *cgit_querystring = NULL; | ||
| 56 | char *cgit_query_repo = NULL; | ||
| 57 | char *cgit_query_page = NULL; | ||
| 58 | char *cgit_query_head = NULL; | ||
| 59 | char *cgit_query_search = NULL; | ||
| 60 | char *cgit_query_grep = NULL; | ||
| 61 | char *cgit_query_sha1 = NULL; | ||
| 62 | char *cgit_query_sha2 = NULL; | ||
| 63 | char *cgit_query_path = NULL; | ||
| 64 | char *cgit_query_name = NULL; | ||
| 65 | int cgit_query_ofs = 0; | ||
| 66 | |||
| 67 | int htmlfd = 0; | ||
| 68 | |||
| 69 | |||
| 70 | int cgit_get_cmd_index(const char *cmd) | ||
| 71 | { | ||
| 72 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | ||
| 73 | "snapshot", "tag", "refs", "patch", NULL}; | ||
| 74 | int i; | ||
| 75 | |||
| 76 | for(i = 0; cmds[i]; i++) | ||
| 77 | if (!strcmp(cmd, cmds[i])) | ||
| 78 | return i + 1; | ||
| 79 | return 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | int chk_zero(int result, char *msg) | 15 | int chk_zero(int result, char *msg) |
| 83 | { | 16 | { |
| 84 | if (result != 0) | 17 | if (result != 0) |
| @@ -100,9 +33,9 @@ int chk_non_negative(int result, char *msg) | |||
| 100 | return result; | 33 | return result; |
| 101 | } | 34 | } |
| 102 | 35 | ||
| 103 | struct repoinfo *add_repo(const char *url) | 36 | struct cgit_repo *cgit_add_repo(const char *url) |
| 104 | { | 37 | { |
| 105 | struct repoinfo *ret; | 38 | struct cgit_repo *ret; |
| 106 | 39 | ||
| 107 | if (++cgit_repolist.count > cgit_repolist.length) { | 40 | if (++cgit_repolist.count > cgit_repolist.length) { |
| 108 | if (cgit_repolist.length == 0) | 41 | if (cgit_repolist.length == 0) |
| @@ -111,7 +44,7 @@ struct repoinfo *add_repo(const char *url) | |||
| 111 | cgit_repolist.length *= 2; | 44 | cgit_repolist.length *= 2; |
| 112 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 45 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
| 113 | cgit_repolist.length * | 46 | cgit_repolist.length * |
| 114 | sizeof(struct repoinfo)); | 47 | sizeof(struct cgit_repo)); |
| 115 | } | 48 | } |
| 116 | 49 | ||
| 117 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 50 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
| @@ -120,20 +53,20 @@ struct repoinfo *add_repo(const char *url) | |||
| 120 | ret->path = NULL; | 53 | ret->path = NULL; |
| 121 | ret->desc = "[no description]"; | 54 | ret->desc = "[no description]"; |
| 122 | ret->owner = NULL; | 55 | ret->owner = NULL; |
| 123 | ret->group = cgit_repo_group; | 56 | ret->group = ctx.cfg.repo_group; |
| 124 | ret->defbranch = "master"; | 57 | ret->defbranch = "master"; |
| 125 | ret->snapshots = cgit_snapshots; | 58 | ret->snapshots = ctx.cfg.snapshots; |
| 126 | ret->enable_log_filecount = cgit_enable_log_filecount; | 59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
| 127 | ret->enable_log_linecount = cgit_enable_log_linecount; | 60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
| 128 | ret->module_link = cgit_module_link; | 61 | ret->module_link = ctx.cfg.module_link; |
| 129 | ret->readme = NULL; | 62 | ret->readme = NULL; |
| 130 | return ret; | 63 | return ret; |
| 131 | } | 64 | } |
| 132 | 65 | ||
| 133 | struct repoinfo *cgit_get_repoinfo(const char *url) | 66 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
| 134 | { | 67 | { |
| 135 | int i; | 68 | int i; |
| 136 | struct repoinfo *repo; | 69 | struct cgit_repo *repo; |
| 137 | 70 | ||
| 138 | for (i=0; i<cgit_repolist.count; i++) { | 71 | for (i=0; i<cgit_repolist.count; i++) { |
| 139 | repo = &cgit_repolist.repos[i]; | 72 | repo = &cgit_repolist.repos[i]; |
| @@ -143,131 +76,6 @@ struct repoinfo *cgit_get_repoinfo(const char *url) | |||
| 143 | return NULL; | 76 | return NULL; |
| 144 | } | 77 | } |
| 145 | 78 | ||
| 146 | void cgit_global_config_cb(const char *name, const char *value) | ||
| 147 | { | ||
| 148 | if (!strcmp(name, "root-title")) | ||
| 149 | cgit_root_title = xstrdup(value); | ||
| 150 | else if (!strcmp(name, "css")) | ||
| 151 | cgit_css = xstrdup(value); | ||
| 152 | else if (!strcmp(name, "logo")) | ||
| 153 | cgit_logo = xstrdup(value); | ||
| 154 | else if (!strcmp(name, "index-header")) | ||
| 155 | cgit_index_header = xstrdup(value); | ||
| 156 | else if (!strcmp(name, "index-info")) | ||
| 157 | cgit_index_info = xstrdup(value); | ||
| 158 | else if (!strcmp(name, "logo-link")) | ||
| 159 | cgit_logo_link = xstrdup(value); | ||
| 160 | else if (!strcmp(name, "module-link")) | ||
| 161 | cgit_module_link = xstrdup(value); | ||
| 162 | else if (!strcmp(name, "virtual-root")) { | ||
| 163 | cgit_virtual_root = trim_end(value, '/'); | ||
| 164 | if (!cgit_virtual_root && (!strcmp(value, "/"))) | ||
| 165 | cgit_virtual_root = ""; | ||
| 166 | } else if (!strcmp(name, "nocache")) | ||
| 167 | cgit_nocache = atoi(value); | ||
| 168 | else if (!strcmp(name, "snapshots")) | ||
| 169 | cgit_snapshots = cgit_parse_snapshots_mask(value); | ||
| 170 | else if (!strcmp(name, "enable-index-links")) | ||
| 171 | cgit_enable_index_links = atoi(value); | ||
| 172 | else if (!strcmp(name, "enable-log-filecount")) | ||
| 173 | cgit_enable_log_filecount = atoi(value); | ||
| 174 | else if (!strcmp(name, "enable-log-linecount")) | ||
| 175 | cgit_enable_log_linecount = atoi(value); | ||
| 176 | else if (!strcmp(name, "cache-root")) | ||
| 177 | cgit_cache_root = xstrdup(value); | ||
| 178 | else if (!strcmp(name, "cache-root-ttl")) | ||
| 179 | cgit_cache_root_ttl = atoi(value); | ||
| 180 | else if (!strcmp(name, "cache-repo-ttl")) | ||
| 181 | cgit_cache_repo_ttl = atoi(value); | ||
| 182 | else if (!strcmp(name, "cache-static-ttl")) | ||
| 183 | cgit_cache_static_ttl = atoi(value); | ||
| 184 | else if (!strcmp(name, "cache-dynamic-ttl")) | ||
| 185 | cgit_cache_dynamic_ttl = atoi(value); | ||
| 186 | else if (!strcmp(name, "max-message-length")) | ||
| 187 | cgit_max_msg_len = atoi(value); | ||
| 188 | else if (!strcmp(name, "max-repodesc-length")) | ||
| 189 | cgit_max_repodesc_len = atoi(value); | ||
| 190 | else if (!strcmp(name, "max-commit-count")) | ||
| 191 | cgit_max_commit_count = atoi(value); | ||
| 192 | else if (!strcmp(name, "summary-log")) | ||
| 193 | cgit_summary_log = atoi(value); | ||
| 194 | else if (!strcmp(name, "summary-branches")) | ||
| 195 | cgit_summary_branches = atoi(value); | ||
| 196 | else if (!strcmp(name, "summary-tags")) | ||
| 197 | cgit_summary_tags = atoi(value); | ||
| 198 | else if (!strcmp(name, "agefile")) | ||
| 199 | cgit_agefile = xstrdup(value); | ||
| 200 | else if (!strcmp(name, "renamelimit")) | ||
| 201 | cgit_renamelimit = atoi(value); | ||
| 202 | else if (!strcmp(name, "robots")) | ||
| 203 | cgit_robots = xstrdup(value); | ||
| 204 | else if (!strcmp(name, "clone-prefix")) | ||
| 205 | cgit_clone_prefix = xstrdup(value); | ||
| 206 | else if (!strcmp(name, "repo.group")) | ||
| 207 | cgit_repo_group = xstrdup(value); | ||
| 208 | else if (!strcmp(name, "repo.url")) | ||
| 209 | cgit_repo = add_repo(value); | ||
| 210 | else if (!strcmp(name, "repo.name")) | ||
| 211 | cgit_repo->name = xstrdup(value); | ||
| 212 | else if (cgit_repo && !strcmp(name, "repo.path")) | ||
| 213 | cgit_repo->path = trim_end(value, '/'); | ||
| 214 | else if (cgit_repo && !strcmp(name, "repo.clone-url")) | ||
| 215 | cgit_repo->clone_url = xstrdup(value); | ||
| 216 | else if (cgit_repo && !strcmp(name, "repo.desc")) | ||
| 217 | cgit_repo->desc = xstrdup(value); | ||
| 218 | else if (cgit_repo && !strcmp(name, "repo.owner")) | ||
| 219 | cgit_repo->owner = xstrdup(value); | ||
| 220 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) | ||
| 221 | cgit_repo->defbranch = xstrdup(value); | ||
| 222 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | ||
| 223 | cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | ||
| 224 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | ||
| 225 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); | ||
| 226 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | ||
| 227 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); | ||
| 228 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | ||
| 229 | cgit_repo->module_link= xstrdup(value); | ||
| 230 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { | ||
| 231 | if (*value == '/') | ||
| 232 | cgit_repo->readme = xstrdup(value); | ||
| 233 | else | ||
| 234 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); | ||
| 235 | } else if (!strcmp(name, "include")) | ||
| 236 | cgit_read_config(value, cgit_global_config_cb); | ||
| 237 | } | ||
| 238 | |||
| 239 | void cgit_querystring_cb(const char *name, const char *value) | ||
| 240 | { | ||
| 241 | if (!strcmp(name,"r")) { | ||
| 242 | cgit_query_repo = xstrdup(value); | ||
| 243 | cgit_repo = cgit_get_repoinfo(value); | ||
| 244 | } else if (!strcmp(name, "p")) { | ||
| 245 | cgit_query_page = xstrdup(value); | ||
| 246 | cgit_cmd = cgit_get_cmd_index(value); | ||
| 247 | } else if (!strcmp(name, "url")) { | ||
| 248 | cgit_parse_url(value); | ||
| 249 | } else if (!strcmp(name, "qt")) { | ||
| 250 | cgit_query_grep = xstrdup(value); | ||
| 251 | } else if (!strcmp(name, "q")) { | ||
| 252 | cgit_query_search = xstrdup(value); | ||
| 253 | } else if (!strcmp(name, "h")) { | ||
| 254 | cgit_query_head = xstrdup(value); | ||
| 255 | cgit_query_has_symref = 1; | ||
| 256 | } else if (!strcmp(name, "id")) { | ||
| 257 | cgit_query_sha1 = xstrdup(value); | ||
| 258 | cgit_query_has_sha1 = 1; | ||
| 259 | } else if (!strcmp(name, "id2")) { | ||
| 260 | cgit_query_sha2 = xstrdup(value); | ||
| 261 | cgit_query_has_sha1 = 1; | ||
| 262 | } else if (!strcmp(name, "ofs")) { | ||
| 263 | cgit_query_ofs = atoi(value); | ||
| 264 | } else if (!strcmp(name, "path")) { | ||
| 265 | cgit_query_path = trim_end(value, '/'); | ||
| 266 | } else if (!strcmp(name, "name")) { | ||
| 267 | cgit_query_name = xstrdup(value); | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 271 | void *cgit_free_commitinfo(struct commitinfo *info) | 79 | void *cgit_free_commitinfo(struct commitinfo *info) |
| 272 | { | 80 | { |
| 273 | free(info->author); | 81 | free(info->author); |
| @@ -281,18 +89,6 @@ void *cgit_free_commitinfo(struct commitinfo *info) | |||
| 281 | return NULL; | 89 | return NULL; |
| 282 | } | 90 | } |
| 283 | 91 | ||
| 284 | int hextoint(char c) | ||
| 285 | { | ||
| 286 | if (c >= 'a' && c <= 'f') | ||
| 287 | return 10 + c - 'a'; | ||
| 288 | else if (c >= 'A' && c <= 'F') | ||
| 289 | return 10 + c - 'A'; | ||
| 290 | else if (c >= '0' && c <= '9') | ||
| 291 | return c - '0'; | ||
| 292 | else | ||
| 293 | return -1; | ||
| 294 | } | ||
| 295 | |||
| 296 | char *trim_end(const char *str, char c) | 92 | char *trim_end(const char *str, char c) |
| 297 | { | 93 | { |
| 298 | int len; | 94 | int len; |
| @@ -491,7 +287,7 @@ void cgit_diff_tree(const unsigned char *old_sha1, | |||
| 491 | diff_setup(&opt); | 287 | diff_setup(&opt); |
| 492 | opt.output_format = DIFF_FORMAT_CALLBACK; | 288 | opt.output_format = DIFF_FORMAT_CALLBACK; |
| 493 | opt.detect_rename = 1; | 289 | opt.detect_rename = 1; |
| 494 | opt.rename_limit = cgit_renamelimit; | 290 | opt.rename_limit = ctx.cfg.renamelimit; |
| 495 | DIFF_OPT_SET(&opt, RECURSIVE); | 291 | DIFF_OPT_SET(&opt, RECURSIVE); |
| 496 | opt.format_callback = cgit_diff_tree_cb; | 292 | opt.format_callback = cgit_diff_tree_cb; |
| 497 | opt.format_callback_data = fn; | 293 | opt.format_callback_data = fn; |
| @@ -519,3 +315,30 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn) | |||
| 519 | old_sha1 = commit->parents->item->object.sha1; | 315 | old_sha1 = commit->parents->item->object.sha1; |
| 520 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); | 316 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); |
| 521 | } | 317 | } |
| 318 | |||
| 319 | int cgit_parse_snapshots_mask(const char *str) | ||
| 320 | { | ||
| 321 | const struct cgit_snapshot_format *f; | ||
| 322 | static const char *delim = " \t,:/|;"; | ||
| 323 | int tl, sl, rv = 0; | ||
| 324 | |||
| 325 | /* favor legacy setting */ | ||
| 326 | if(atoi(str)) | ||
| 327 | return 1; | ||
| 328 | for(;;) { | ||
| 329 | str += strspn(str,delim); | ||
| 330 | tl = strcspn(str,delim); | ||
| 331 | if (!tl) | ||
| 332 | break; | ||
| 333 | for (f = cgit_snapshot_formats; f->suffix; f++) { | ||
| 334 | sl = strlen(f->suffix); | ||
| 335 | if((tl == sl && !strncmp(f->suffix, str, tl)) || | ||
| 336 | (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) { | ||
| 337 | rv |= f->bit; | ||
| 338 | break; | ||
| 339 | } | ||
| 340 | } | ||
| 341 | str += tl; | ||
| 342 | } | ||
| 343 | return rv; | ||
| 344 | } | ||
| @@ -1,6 +1,16 @@ | |||
| 1 | /* ui-blob.c: show blob content | ||
| 2 | * | ||
| 3 | * Copyright (C) 2008 Lars Hjemli | ||
| 4 | * | ||
| 5 | * Licensed under GNU General Public License v2 | ||
| 6 | * (see COPYING for full license text) | ||
| 7 | */ | ||
| 8 | |||
| 1 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 2 | 12 | ||
| 3 | void cgit_print_blob(struct cacheitem *item, const char *hex, char *path) | 13 | void cgit_print_blob(const char *hex, char *path) |
| 4 | { | 14 | { |
| 5 | 15 | ||
| 6 | unsigned char sha1[20]; | 16 | unsigned char sha1[20]; |
| @@ -26,6 +36,8 @@ void cgit_print_blob(struct cacheitem *item, const char *hex, char *path) | |||
| 26 | } | 36 | } |
| 27 | 37 | ||
| 28 | buf[size] = '\0'; | 38 | buf[size] = '\0'; |
| 29 | cgit_print_snapshot_start("text/plain", path, item); | 39 | ctx.page.mimetype = "text/plain"; |
| 40 | ctx.page.filename = path; | ||
| 41 | cgit_print_http_headers(&ctx); | ||
| 30 | write(htmlfd, buf, size); | 42 | write(htmlfd, buf, size); |
| 31 | } | 43 | } |
diff --git a/ui-blob.h b/ui-blob.h new file mode 100644 index 0000000..5a920a8 --- /dev/null +++ b/ui-blob.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_BLOB_H | ||
| 2 | #define UI_BLOB_H | ||
| 3 | |||
| 4 | extern void cgit_print_blob(const char *hex, char *path); | ||
| 5 | |||
| 6 | #endif /* UI_BLOB_H */ | ||
diff --git a/ui-commit.c b/ui-commit.c index bd55a33..8019e36 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 10 | 12 | ||
| 11 | static int files, slots; | 13 | static int files, slots; |
| 12 | static int total_adds, total_rems, max_changes; | 14 | static int total_adds, total_rems, max_changes; |
| @@ -62,20 +64,20 @@ void print_fileinfo(struct fileinfo *info) | |||
| 62 | html("<tr>"); | 64 | html("<tr>"); |
| 63 | htmlf("<td class='mode'>"); | 65 | htmlf("<td class='mode'>"); |
| 64 | if (is_null_sha1(info->new_sha1)) { | 66 | if (is_null_sha1(info->new_sha1)) { |
| 65 | html_filemode(info->old_mode); | 67 | cgit_print_filemode(info->old_mode); |
| 66 | } else { | 68 | } else { |
| 67 | html_filemode(info->new_mode); | 69 | cgit_print_filemode(info->new_mode); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | if (info->old_mode != info->new_mode && | 72 | if (info->old_mode != info->new_mode && |
| 71 | !is_null_sha1(info->old_sha1) && | 73 | !is_null_sha1(info->old_sha1) && |
| 72 | !is_null_sha1(info->new_sha1)) { | 74 | !is_null_sha1(info->new_sha1)) { |
| 73 | html("<span class='modechange'>["); | 75 | html("<span class='modechange'>["); |
| 74 | html_filemode(info->old_mode); | 76 | cgit_print_filemode(info->old_mode); |
| 75 | html("]</span>"); | 77 | html("]</span>"); |
| 76 | } | 78 | } |
| 77 | htmlf("</td><td class='%s'>", class); | 79 | htmlf("</td><td class='%s'>", class); |
| 78 | cgit_diff_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev, | 80 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, curr_rev, |
| 79 | NULL, info->new_path); | 81 | NULL, info->new_path); |
| 80 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 82 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
| 81 | htmlf(" (%s from %s)", | 83 | htmlf(" (%s from %s)", |
| @@ -143,7 +145,7 @@ void cgit_print_commit(char *hex) | |||
| 143 | int i; | 145 | int i; |
| 144 | 146 | ||
| 145 | if (!hex) | 147 | if (!hex) |
| 146 | hex = cgit_query_head; | 148 | hex = ctx.qry.head; |
| 147 | curr_rev = hex; | 149 | curr_rev = hex; |
| 148 | 150 | ||
| 149 | if (get_sha1(hex, sha1)) { | 151 | if (get_sha1(hex, sha1)) { |
| @@ -175,7 +177,7 @@ void cgit_print_commit(char *hex) | |||
| 175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 177 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
| 176 | tmp = xstrdup(hex); | 178 | tmp = xstrdup(hex); |
| 177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 179 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
| 178 | cgit_query_head, tmp, NULL); | 180 | ctx.qry.head, tmp, NULL); |
| 179 | html("</td></tr>\n"); | 181 | html("</td></tr>\n"); |
| 180 | for (p = commit->parents; p ; p = p->next) { | 182 | for (p = commit->parents; p ; p = p->next) { |
| 181 | parent = lookup_commit_reference(p->item->object.sha1); | 183 | parent = lookup_commit_reference(p->item->object.sha1); |
| @@ -188,16 +190,16 @@ void cgit_print_commit(char *hex) | |||
| 188 | html("<tr><th>parent</th>" | 190 | html("<tr><th>parent</th>" |
| 189 | "<td colspan='2' class='sha1'>"); | 191 | "<td colspan='2' class='sha1'>"); |
| 190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 192 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
| 191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); | 193 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); |
| 192 | html(" ("); | 194 | html(" ("); |
| 193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, | 195 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, |
| 194 | sha1_to_hex(p->item->object.sha1), NULL); | 196 | sha1_to_hex(p->item->object.sha1), NULL); |
| 195 | html(")</td></tr>"); | 197 | html(")</td></tr>"); |
| 196 | } | 198 | } |
| 197 | if (cgit_repo->snapshots) { | 199 | if (ctx.repo->snapshots) { |
| 198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 200 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
| 199 | cgit_print_snapshot_links(cgit_query_repo, cgit_query_head, | 201 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, |
| 200 | hex, cgit_repo->snapshots); | 202 | hex, ctx.repo->snapshots); |
| 201 | html("</td></tr>"); | 203 | html("</td></tr>"); |
| 202 | } | 204 | } |
| 203 | html("</table>\n"); | 205 | html("</table>\n"); |
| @@ -218,7 +220,7 @@ void cgit_print_commit(char *hex) | |||
| 218 | html("<div class='diffstat-summary'>"); | 220 | html("<div class='diffstat-summary'>"); |
| 219 | htmlf("%d files changed, %d insertions, %d deletions (", | 221 | htmlf("%d files changed, %d insertions, %d deletions (", |
| 220 | files, total_adds, total_rems); | 222 | files, total_adds, total_rems); |
| 221 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, | 223 | cgit_diff_link("show diff", NULL, NULL, ctx.qry.head, hex, |
| 222 | NULL, NULL); | 224 | NULL, NULL); |
| 223 | html(")</div>"); | 225 | html(")</div>"); |
| 224 | } | 226 | } |
diff --git a/ui-commit.h b/ui-commit.h new file mode 100644 index 0000000..40bcb31 --- /dev/null +++ b/ui-commit.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_COMMIT_H | ||
| 2 | #define UI_COMMIT_H | ||
| 3 | |||
| 4 | extern void cgit_print_commit(char *hex); | ||
| 5 | |||
| 6 | #endif /* UI_COMMIT_H */ | ||
| @@ -7,7 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | 10 | #include "html.h" | |
| 11 | #include "ui-shared.h" | ||
| 11 | 12 | ||
| 12 | unsigned char old_rev_sha1[20]; | 13 | unsigned char old_rev_sha1[20]; |
| 13 | unsigned char new_rev_sha1[20]; | 14 | unsigned char new_rev_sha1[20]; |
| @@ -71,13 +72,13 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
| 71 | } | 72 | } |
| 72 | html("<br/>--- a/"); | 73 | html("<br/>--- a/"); |
| 73 | if (mode1 != 0) | 74 | if (mode1 != 0) |
| 74 | cgit_tree_link(path1, NULL, NULL, cgit_query_head, | 75 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
| 75 | sha1_to_hex(old_rev_sha1), path1); | 76 | sha1_to_hex(old_rev_sha1), path1); |
| 76 | else | 77 | else |
| 77 | html_txt(path1); | 78 | html_txt(path1); |
| 78 | html("<br/>+++ b/"); | 79 | html("<br/>+++ b/"); |
| 79 | if (mode2 != 0) | 80 | if (mode2 != 0) |
| 80 | cgit_tree_link(path2, NULL, NULL, cgit_query_head, | 81 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
| 81 | sha1_to_hex(new_rev_sha1), path2); | 82 | sha1_to_hex(new_rev_sha1), path2); |
| 82 | else | 83 | else |
| 83 | html_txt(path2); | 84 | html_txt(path2); |
| @@ -107,7 +108,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
| 107 | struct commit *commit, *commit2; | 108 | struct commit *commit, *commit2; |
| 108 | 109 | ||
| 109 | if (!new_rev) | 110 | if (!new_rev) |
| 110 | new_rev = cgit_query_head; | 111 | new_rev = ctx.qry.head; |
| 111 | get_sha1(new_rev, new_rev_sha1); | 112 | get_sha1(new_rev, new_rev_sha1); |
| 112 | type = sha1_object_info(new_rev_sha1, &size); | 113 | type = sha1_object_info(new_rev_sha1, &size); |
| 113 | if (type == OBJ_BAD) { | 114 | if (type == OBJ_BAD) { |
diff --git a/ui-diff.h b/ui-diff.h new file mode 100644 index 0000000..2307322 --- /dev/null +++ b/ui-diff.h | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #ifndef UI_DIFF_H | ||
| 2 | #define UI_DIFF_H | ||
| 3 | |||
| 4 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, | ||
| 5 | const char *prefix); | ||
| 6 | |||
| 7 | #endif /* UI_DIFF_H */ | ||
| @@ -7,6 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 10 | 12 | ||
| 11 | int files, add_lines, rem_lines; | 13 | int files, add_lines, rem_lines; |
| 12 | 14 | ||
| @@ -25,7 +27,7 @@ void count_lines(char *line, int size) | |||
| 25 | void inspect_files(struct diff_filepair *pair) | 27 | void inspect_files(struct diff_filepair *pair) |
| 26 | { | 28 | { |
| 27 | files++; | 29 | files++; |
| 28 | if (cgit_repo->enable_log_linecount) | 30 | if (ctx.repo->enable_log_linecount) |
| 29 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| @@ -37,16 +39,16 @@ void print_commit(struct commit *commit) | |||
| 37 | html("<tr><td>"); | 39 | html("<tr><td>"); |
| 38 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 40 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
| 39 | html("</td><td>"); | 41 | html("</td><td>"); |
| 40 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, | 42 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
| 41 | sha1_to_hex(commit->object.sha1)); | 43 | sha1_to_hex(commit->object.sha1)); |
| 42 | if (cgit_repo->enable_log_filecount) { | 44 | if (ctx.repo->enable_log_filecount) { |
| 43 | files = 0; | 45 | files = 0; |
| 44 | add_lines = 0; | 46 | add_lines = 0; |
| 45 | rem_lines = 0; | 47 | rem_lines = 0; |
| 46 | cgit_diff_commit(commit, inspect_files); | 48 | cgit_diff_commit(commit, inspect_files); |
| 47 | html("</td><td class='right'>"); | 49 | html("</td><td class='right'>"); |
| 48 | htmlf("%d", files); | 50 | htmlf("%d", files); |
| 49 | if (cgit_repo->enable_log_linecount) { | 51 | if (ctx.repo->enable_log_linecount) { |
| 50 | html("</td><td class='right'>"); | 52 | html("</td><td class='right'>"); |
| 51 | htmlf("-%d/+%d", rem_lines, add_lines); | 53 | htmlf("-%d/+%d", rem_lines, add_lines); |
| 52 | } | 54 | } |
| @@ -67,7 +69,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern | |||
| 67 | int i; | 69 | int i; |
| 68 | 70 | ||
| 69 | if (!tip) | 71 | if (!tip) |
| 70 | argv[1] = cgit_query_head; | 72 | argv[1] = ctx.qry.head; |
| 71 | 73 | ||
| 72 | if (grep && pattern && (!strcmp(grep, "grep") || | 74 | if (grep && pattern && (!strcmp(grep, "grep") || |
| 73 | !strcmp(grep, "author") || | 75 | !strcmp(grep, "author") || |
| @@ -94,9 +96,9 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern | |||
| 94 | html("<tr class='nohover'><th class='left'>Age</th>" | 96 | html("<tr class='nohover'><th class='left'>Age</th>" |
| 95 | "<th class='left'>Message</th>"); | 97 | "<th class='left'>Message</th>"); |
| 96 | 98 | ||
| 97 | if (cgit_repo->enable_log_filecount) { | 99 | if (ctx.repo->enable_log_filecount) { |
| 98 | html("<th class='right'>Files</th>"); | 100 | html("<th class='right'>Files</th>"); |
| 99 | if (cgit_repo->enable_log_linecount) | 101 | if (ctx.repo->enable_log_linecount) |
| 100 | html("<th class='right'>Lines</th>"); | 102 | html("<th class='right'>Lines</th>"); |
| 101 | } | 103 | } |
| 102 | html("<th class='left'>Author</th></tr>\n"); | 104 | html("<th class='left'>Author</th></tr>\n"); |
| @@ -123,17 +125,17 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern | |||
| 123 | if (pager) { | 125 | if (pager) { |
| 124 | html("<div class='pager'>"); | 126 | html("<div class='pager'>"); |
| 125 | if (ofs > 0) { | 127 | if (ofs > 0) { |
| 126 | cgit_log_link("[prev]", NULL, NULL, cgit_query_head, | 128 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
| 127 | cgit_query_sha1, cgit_query_path, | 129 | ctx.qry.sha1, ctx.qry.path, |
| 128 | ofs - cnt, cgit_query_grep, | 130 | ofs - cnt, ctx.qry.grep, |
| 129 | cgit_query_search); | 131 | ctx.qry.search); |
| 130 | html(" "); | 132 | html(" "); |
| 131 | } | 133 | } |
| 132 | if ((commit = get_revision(&rev)) != NULL) { | 134 | if ((commit = get_revision(&rev)) != NULL) { |
| 133 | cgit_log_link("[next]", NULL, NULL, cgit_query_head, | 135 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
| 134 | cgit_query_sha1, cgit_query_path, | 136 | ctx.qry.sha1, ctx.qry.path, |
| 135 | ofs + cnt, cgit_query_grep, | 137 | ofs + cnt, ctx.qry.grep, |
| 136 | cgit_query_search); | 138 | ctx.qry.search); |
| 137 | } | 139 | } |
| 138 | html("</div>"); | 140 | html("</div>"); |
| 139 | } | 141 | } |
diff --git a/ui-log.h b/ui-log.h new file mode 100644 index 0000000..877e40e --- /dev/null +++ b/ui-log.h | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #ifndef UI_LOG_H | ||
| 2 | #define UI_LOG_H | ||
| 3 | |||
| 4 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, | ||
| 5 | char *pattern, char *path, int pager); | ||
| 6 | |||
| 7 | #endif /* UI_LOG_H */ | ||
| @@ -7,6 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 10 | 12 | ||
| 11 | static void print_line(char *line, int len) | 13 | static void print_line(char *line, int len) |
| 12 | { | 14 | { |
| @@ -68,7 +70,7 @@ static void filepair_cb(struct diff_filepair *pair) | |||
| 68 | html("Error running diff"); | 70 | html("Error running diff"); |
| 69 | } | 71 | } |
| 70 | 72 | ||
| 71 | void cgit_print_patch(char *hex, struct cacheitem *item) | 73 | void cgit_print_patch(char *hex) |
| 72 | { | 74 | { |
| 73 | struct commit *commit; | 75 | struct commit *commit; |
| 74 | struct commitinfo *info; | 76 | struct commitinfo *info; |
| @@ -76,7 +78,7 @@ void cgit_print_patch(char *hex, struct cacheitem *item) | |||
| 76 | char *patchname; | 78 | char *patchname; |
| 77 | 79 | ||
| 78 | if (!hex) | 80 | if (!hex) |
| 79 | hex = cgit_query_head; | 81 | hex = ctx.qry.head; |
| 80 | 82 | ||
| 81 | if (get_sha1(hex, sha1)) { | 83 | if (get_sha1(hex, sha1)) { |
| 82 | cgit_print_error(fmt("Bad object id: %s", hex)); | 84 | cgit_print_error(fmt("Bad object id: %s", hex)); |
| @@ -95,7 +97,9 @@ void cgit_print_patch(char *hex, struct cacheitem *item) | |||
| 95 | hashclr(old_sha1); | 97 | hashclr(old_sha1); |
| 96 | 98 | ||
| 97 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); | 99 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); |
| 98 | cgit_print_snapshot_start("text/plain", patchname, item); | 100 | ctx.page.mimetype = "text/plain"; |
| 101 | ctx.page.filename = patchname; | ||
| 102 | cgit_print_http_headers(&ctx); | ||
| 99 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); | 103 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); |
| 100 | htmlf("From: %s%s\n", info->author, info->author_email); | 104 | htmlf("From: %s%s\n", info->author, info->author_email); |
| 101 | html("Date: "); | 105 | html("Date: "); |
diff --git a/ui-patch.h b/ui-patch.h new file mode 100644 index 0000000..9f68212 --- /dev/null +++ b/ui-patch.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_PATCH_H | ||
| 2 | #define UI_PATCH_H | ||
| 3 | |||
| 4 | extern void cgit_print_patch(char *hex); | ||
| 5 | |||
| 6 | #endif /* UI_PATCH_H */ | ||
| @@ -7,18 +7,189 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 10 | 12 | ||
| 13 | static int header; | ||
| 11 | 14 | ||
| 15 | static int cmp_age(int age1, int age2) | ||
| 16 | { | ||
| 17 | if (age1 != 0 && age2 != 0) | ||
| 18 | return age2 - age1; | ||
| 19 | |||
| 20 | if (age1 == 0 && age2 == 0) | ||
| 21 | return 0; | ||
| 22 | |||
| 23 | if (age1 == 0) | ||
| 24 | return +1; | ||
| 25 | |||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | |||
| 29 | static int cmp_ref_name(const void *a, const void *b) | ||
| 30 | { | ||
| 31 | struct refinfo *r1 = *(struct refinfo **)a; | ||
| 32 | struct refinfo *r2 = *(struct refinfo **)b; | ||
| 33 | |||
| 34 | return strcmp(r1->refname, r2->refname); | ||
| 35 | } | ||
| 36 | |||
| 37 | static int cmp_branch_age(const void *a, const void *b) | ||
| 38 | { | ||
| 39 | struct refinfo *r1 = *(struct refinfo **)a; | ||
| 40 | struct refinfo *r2 = *(struct refinfo **)b; | ||
| 41 | |||
| 42 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | ||
| 43 | } | ||
| 44 | |||
| 45 | static int cmp_tag_age(const void *a, const void *b) | ||
| 46 | { | ||
| 47 | struct refinfo *r1 = *(struct refinfo **)a; | ||
| 48 | struct refinfo *r2 = *(struct refinfo **)b; | ||
| 49 | |||
| 50 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | ||
| 51 | } | ||
| 52 | |||
| 53 | static int print_branch(struct refinfo *ref) | ||
| 54 | { | ||
| 55 | struct commitinfo *info = ref->commit; | ||
| 56 | char *name = (char *)ref->refname; | ||
| 57 | |||
| 58 | if (!info) | ||
| 59 | return 1; | ||
| 60 | html("<tr><td>"); | ||
| 61 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL); | ||
| 62 | html("</td><td>"); | ||
| 63 | |||
| 64 | if (ref->object->type == OBJ_COMMIT) { | ||
| 65 | cgit_print_age(info->commit->date, -1, NULL); | ||
| 66 | html("</td><td>"); | ||
| 67 | html_txt(info->author); | ||
| 68 | html("</td><td>"); | ||
| 69 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | ||
| 70 | } else { | ||
| 71 | html("</td><td></td><td>"); | ||
| 72 | cgit_object_link(ref->object); | ||
| 73 | } | ||
| 74 | html("</td></tr>\n"); | ||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | static void print_tag_header() | ||
| 79 | { | ||
| 80 | html("<tr class='nohover'><th class='left'>Tag</th>" | ||
| 81 | "<th class='left'>Age</th>" | ||
| 82 | "<th class='left'>Author</th>" | ||
| 83 | "<th class='left'>Reference</th></tr>\n"); | ||
| 84 | header = 1; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int print_tag(struct refinfo *ref) | ||
| 88 | { | ||
| 89 | struct tag *tag; | ||
| 90 | struct taginfo *info; | ||
| 91 | char *url, *name = (char *)ref->refname; | ||
| 92 | |||
| 93 | if (ref->object->type == OBJ_TAG) { | ||
| 94 | tag = (struct tag *)ref->object; | ||
| 95 | info = ref->tag; | ||
| 96 | if (!tag || !info) | ||
| 97 | return 1; | ||
| 98 | html("<tr><td>"); | ||
| 99 | url = cgit_pageurl(ctx.qry.repo, "tag", | ||
| 100 | fmt("id=%s", name)); | ||
| 101 | html_link_open(url, NULL, NULL); | ||
| 102 | html_txt(name); | ||
| 103 | html_link_close(); | ||
| 104 | html("</td><td>"); | ||
| 105 | if (info->tagger_date > 0) | ||
| 106 | cgit_print_age(info->tagger_date, -1, NULL); | ||
| 107 | html("</td><td>"); | ||
| 108 | if (info->tagger) | ||
| 109 | html(info->tagger); | ||
| 110 | html("</td><td>"); | ||
| 111 | cgit_object_link(tag->tagged); | ||
| 112 | html("</td></tr>\n"); | ||
| 113 | } else { | ||
| 114 | if (!header) | ||
| 115 | print_tag_header(); | ||
| 116 | html("<tr><td>"); | ||
| 117 | html_txt(name); | ||
| 118 | html("</td><td colspan='2'/><td>"); | ||
| 119 | cgit_object_link(ref->object); | ||
| 120 | html("</td></tr>\n"); | ||
| 121 | } | ||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | |||
| 125 | static void print_refs_link(char *path) | ||
| 126 | { | ||
| 127 | html("<tr class='nohover'><td colspan='4'>"); | ||
| 128 | cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); | ||
| 129 | html("</td></tr>"); | ||
| 130 | } | ||
| 131 | |||
| 132 | void cgit_print_branches(int maxcount) | ||
| 133 | { | ||
| 134 | struct reflist list; | ||
| 135 | int i; | ||
| 12 | 136 | ||
| 137 | html("<tr class='nohover'><th class='left'>Branch</th>" | ||
| 138 | "<th class='left'>Idle</th>" | ||
| 139 | "<th class='left'>Author</th>" | ||
| 140 | "<th class='left'>Head commit</th></tr>\n"); | ||
| 141 | |||
| 142 | list.refs = NULL; | ||
| 143 | list.alloc = list.count = 0; | ||
| 144 | for_each_branch_ref(cgit_refs_cb, &list); | ||
| 145 | |||
| 146 | if (maxcount == 0 || maxcount > list.count) | ||
| 147 | maxcount = list.count; | ||
| 148 | |||
| 149 | if (maxcount < list.count) { | ||
| 150 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | ||
| 151 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | ||
| 152 | } | ||
| 153 | |||
| 154 | for(i=0; i<maxcount; i++) | ||
| 155 | print_branch(list.refs[i]); | ||
| 156 | |||
| 157 | if (maxcount < list.count) | ||
| 158 | print_refs_link("heads"); | ||
| 159 | } | ||
| 160 | |||
| 161 | void cgit_print_tags(int maxcount) | ||
| 162 | { | ||
| 163 | struct reflist list; | ||
| 164 | int i; | ||
| 165 | |||
| 166 | header = 0; | ||
| 167 | list.refs = NULL; | ||
| 168 | list.alloc = list.count = 0; | ||
| 169 | for_each_tag_ref(cgit_refs_cb, &list); | ||
| 170 | if (list.count == 0) | ||
| 171 | return; | ||
| 172 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | ||
| 173 | if (!maxcount) | ||
| 174 | maxcount = list.count; | ||
| 175 | else if (maxcount > list.count) | ||
| 176 | maxcount = list.count; | ||
| 177 | print_tag_header(); | ||
| 178 | for(i=0; i<maxcount; i++) | ||
| 179 | print_tag(list.refs[i]); | ||
| 180 | |||
| 181 | if (maxcount < list.count) | ||
| 182 | print_refs_link("tags"); | ||
| 183 | } | ||
| 13 | 184 | ||
| 14 | void cgit_print_refs() | 185 | void cgit_print_refs() |
| 15 | { | 186 | { |
| 16 | 187 | ||
| 17 | html("<table class='list nowrap'>"); | 188 | html("<table class='list nowrap'>"); |
| 18 | 189 | ||
| 19 | if (cgit_query_path && !strncmp(cgit_query_path, "heads", 5)) | 190 | if (ctx.qry.path && !strncmp(ctx.qry.path, "heads", 5)) |
| 20 | cgit_print_branches(0); | 191 | cgit_print_branches(0); |
| 21 | else if (cgit_query_path && !strncmp(cgit_query_path, "tags", 4)) | 192 | else if (ctx.qry.path && !strncmp(ctx.qry.path, "tags", 4)) |
| 22 | cgit_print_tags(0); | 193 | cgit_print_tags(0); |
| 23 | else { | 194 | else { |
| 24 | cgit_print_branches(0); | 195 | cgit_print_branches(0); |
diff --git a/ui-refs.h b/ui-refs.h new file mode 100644 index 0000000..b35c04a --- /dev/null +++ b/ui-refs.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #ifndef UI_REFS_H | ||
| 2 | #define UI_REFS_H | ||
| 3 | |||
| 4 | extern void cgit_print_branches(int maxcount); | ||
| 5 | extern void cgit_print_tags(int maxcount); | ||
| 6 | extern void cgit_print_refs(); | ||
| 7 | |||
| 8 | #endif /* UI_REFS_H */ | ||
diff --git a/ui-repolist.c b/ui-repolist.c index 3e97ca9..eeeaf3d 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
| @@ -6,9 +6,11 @@ | |||
| 6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | ||
| 10 | #include <time.h> | 9 | #include <time.h> |
| 11 | 10 | ||
| 11 | #include "cgit.h" | ||
| 12 | #include "html.h" | ||
| 13 | #include "ui-shared.h" | ||
| 12 | 14 | ||
| 13 | time_t read_agefile(char *path) | 15 | time_t read_agefile(char *path) |
| 14 | { | 16 | { |
| @@ -25,12 +27,12 @@ time_t read_agefile(char *path) | |||
| 25 | return 0; | 27 | return 0; |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | static void print_modtime(struct repoinfo *repo) | 30 | static void print_modtime(struct cgit_repo *repo) |
| 29 | { | 31 | { |
| 30 | char *path; | 32 | char *path; |
| 31 | struct stat s; | 33 | struct stat s; |
| 32 | 34 | ||
| 33 | path = fmt("%s/%s", repo->path, cgit_agefile); | 35 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
| 34 | if (stat(path, &s) == 0) { | 36 | if (stat(path, &s) == 0) { |
| 35 | cgit_print_age(read_agefile(path), -1, NULL); | 37 | cgit_print_age(read_agefile(path), -1, NULL); |
| 36 | return; | 38 | return; |
| @@ -42,22 +44,24 @@ static void print_modtime(struct repoinfo *repo) | |||
| 42 | cgit_print_age(s.st_mtime, -1, NULL); | 44 | cgit_print_age(s.st_mtime, -1, NULL); |
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | void cgit_print_repolist(struct cacheitem *item) | 47 | void cgit_print_repolist() |
| 46 | { | 48 | { |
| 47 | int i, columns = 4; | 49 | int i, columns = 4; |
| 48 | char *last_group = NULL; | 50 | char *last_group = NULL; |
| 49 | 51 | ||
| 50 | if (cgit_enable_index_links) | 52 | if (ctx.cfg.enable_index_links) |
| 51 | columns++; | 53 | columns++; |
| 52 | 54 | ||
| 53 | cgit_print_docstart(cgit_root_title, item); | 55 | ctx.page.title = ctx.cfg.root_title; |
| 54 | cgit_print_pageheader(cgit_root_title, 0); | 56 | cgit_print_http_headers(&ctx); |
| 57 | cgit_print_docstart(&ctx); | ||
| 58 | cgit_print_pageheader(&ctx); | ||
| 55 | 59 | ||
| 56 | html("<table summary='repository list' class='list nowrap'>"); | 60 | html("<table summary='repository list' class='list nowrap'>"); |
| 57 | if (cgit_index_header) { | 61 | if (ctx.cfg.index_header) { |
| 58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", | 62 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
| 59 | columns); | 63 | columns); |
| 60 | html_include(cgit_index_header); | 64 | html_include(ctx.cfg.index_header); |
| 61 | html("</td></tr>"); | 65 | html("</td></tr>"); |
| 62 | } | 66 | } |
| 63 | html("<tr class='nohover'>" | 67 | html("<tr class='nohover'>" |
| @@ -65,37 +69,37 @@ void cgit_print_repolist(struct cacheitem *item) | |||
| 65 | "<th class='left'>Description</th>" | 69 | "<th class='left'>Description</th>" |
| 66 | "<th class='left'>Owner</th>" | 70 | "<th class='left'>Owner</th>" |
| 67 | "<th class='left'>Idle</th>"); | 71 | "<th class='left'>Idle</th>"); |
| 68 | if (cgit_enable_index_links) | 72 | if (ctx.cfg.enable_index_links) |
| 69 | html("<th>Links</th>"); | 73 | html("<th>Links</th>"); |
| 70 | html("</tr>\n"); | 74 | html("</tr>\n"); |
| 71 | 75 | ||
| 72 | for (i=0; i<cgit_repolist.count; i++) { | 76 | for (i=0; i<cgit_repolist.count; i++) { |
| 73 | cgit_repo = &cgit_repolist.repos[i]; | 77 | ctx.repo = &cgit_repolist.repos[i]; |
| 74 | if ((last_group == NULL && cgit_repo->group != NULL) || | 78 | if ((last_group == NULL && ctx.repo->group != NULL) || |
| 75 | (last_group != NULL && cgit_repo->group == NULL) || | 79 | (last_group != NULL && ctx.repo->group == NULL) || |
| 76 | (last_group != NULL && cgit_repo->group != NULL && | 80 | (last_group != NULL && ctx.repo->group != NULL && |
| 77 | strcmp(cgit_repo->group, last_group))) { | 81 | strcmp(ctx.repo->group, last_group))) { |
| 78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 82 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
| 79 | columns); | 83 | columns); |
| 80 | html_txt(cgit_repo->group); | 84 | html_txt(ctx.repo->group); |
| 81 | html("</td></tr>"); | 85 | html("</td></tr>"); |
| 82 | last_group = cgit_repo->group; | 86 | last_group = ctx.repo->group; |
| 83 | } | 87 | } |
| 84 | htmlf("<tr><td class='%s'>", | 88 | htmlf("<tr><td class='%s'>", |
| 85 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); | 89 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); |
| 86 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); | 90 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); |
| 87 | html_txt(cgit_repo->name); | 91 | html_txt(ctx.repo->name); |
| 88 | html_link_close(); | 92 | html_link_close(); |
| 89 | html("</td><td>"); | 93 | html("</td><td>"); |
| 90 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); | 94 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); |
| 91 | html("</td><td>"); | 95 | html("</td><td>"); |
| 92 | html_txt(cgit_repo->owner); | 96 | html_txt(ctx.repo->owner); |
| 93 | html("</td><td>"); | 97 | html("</td><td>"); |
| 94 | print_modtime(cgit_repo); | 98 | print_modtime(ctx.repo); |
| 95 | html("</td>"); | 99 | html("</td>"); |
| 96 | if (cgit_enable_index_links) { | 100 | if (ctx.cfg.enable_index_links) { |
| 97 | html("<td>"); | 101 | html("<td>"); |
| 98 | html_link_open(cgit_repourl(cgit_repo->url), | 102 | html_link_open(cgit_repourl(ctx.repo->url), |
| 99 | NULL, "button"); | 103 | NULL, "button"); |
| 100 | html("summary</a>"); | 104 | html("summary</a>"); |
| 101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, | 105 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, |
diff --git a/ui-repolist.h b/ui-repolist.h new file mode 100644 index 0000000..c23e5d2 --- /dev/null +++ b/ui-repolist.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_REPOLIST_H | ||
| 2 | #define UI_REPOLIST_H | ||
| 3 | |||
| 4 | extern void cgit_print_repolist(); | ||
| 5 | |||
| 6 | #endif /* UI_REPOLIST_H */ | ||
diff --git a/ui-shared.c b/ui-shared.c index 60aa2e3..aa65988 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 10 | 11 | ||
| 11 | const char cgit_doctype[] = | 12 | const char cgit_doctype[] = |
| 12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 13 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
| @@ -25,14 +26,6 @@ static char *http_date(time_t t) | |||
| 25 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 26 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | static long ttl_seconds(long ttl) | ||
| 29 | { | ||
| 30 | if (ttl<0) | ||
| 31 | return 60 * 60 * 24 * 365; | ||
| 32 | else | ||
| 33 | return ttl * 60; | ||
| 34 | } | ||
| 35 | |||
| 36 | void cgit_print_error(char *msg) | 29 | void cgit_print_error(char *msg) |
| 37 | { | 30 | { |
| 38 | html("<div class='error'>"); | 31 | html("<div class='error'>"); |
| @@ -42,16 +35,16 @@ void cgit_print_error(char *msg) | |||
| 42 | 35 | ||
| 43 | char *cgit_rooturl() | 36 | char *cgit_rooturl() |
| 44 | { | 37 | { |
| 45 | if (cgit_virtual_root) | 38 | if (ctx.cfg.virtual_root) |
| 46 | return fmt("%s/", cgit_virtual_root); | 39 | return fmt("%s/", ctx.cfg.virtual_root); |
| 47 | else | 40 | else |
| 48 | return cgit_script_name; | 41 | return ctx.cfg.script_name; |
| 49 | } | 42 | } |
| 50 | 43 | ||
| 51 | char *cgit_repourl(const char *reponame) | 44 | char *cgit_repourl(const char *reponame) |
| 52 | { | 45 | { |
| 53 | if (cgit_virtual_root) { | 46 | if (ctx.cfg.virtual_root) { |
| 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 47 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
| 55 | } else { | 48 | } else { |
| 56 | return fmt("?r=%s", reponame); | 49 | return fmt("?r=%s", reponame); |
| 57 | } | 50 | } |
| @@ -63,8 +56,8 @@ char *cgit_fileurl(const char *reponame, const char *pagename, | |||
| 63 | char *tmp; | 56 | char *tmp; |
| 64 | char *delim; | 57 | char *delim; |
| 65 | 58 | ||
| 66 | if (cgit_virtual_root) { | 59 | if (ctx.cfg.virtual_root) { |
| 67 | tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame, | 60 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
| 68 | pagename, (filename ? filename:"")); | 61 | pagename, (filename ? filename:"")); |
| 69 | delim = "?"; | 62 | delim = "?"; |
| 70 | } else { | 63 | } else { |
| @@ -110,14 +103,14 @@ const char *cgit_repobasename(const char *reponame) | |||
| 110 | 103 | ||
| 111 | char *cgit_currurl() | 104 | char *cgit_currurl() |
| 112 | { | 105 | { |
| 113 | if (!cgit_virtual_root) | 106 | if (!ctx.cfg.virtual_root) |
| 114 | return cgit_script_name; | 107 | return ctx.cfg.script_name; |
| 115 | else if (cgit_query_page) | 108 | else if (ctx.qry.page) |
| 116 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 109 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
| 117 | else if (cgit_query_repo) | 110 | else if (ctx.qry.repo) |
| 118 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 111 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
| 119 | else | 112 | else |
| 120 | return fmt("%s/", cgit_virtual_root); | 113 | return fmt("%s/", ctx.cfg.virtual_root); |
| 121 | } | 114 | } |
| 122 | 115 | ||
| 123 | static char *repolink(char *title, char *class, char *page, char *head, | 116 | static char *repolink(char *title, char *class, char *page, char *head, |
| @@ -137,12 +130,12 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
| 137 | html("'"); | 130 | html("'"); |
| 138 | } | 131 | } |
| 139 | html(" href='"); | 132 | html(" href='"); |
| 140 | if (cgit_virtual_root) { | 133 | if (ctx.cfg.virtual_root) { |
| 141 | html_attr(cgit_virtual_root); | 134 | html_attr(ctx.cfg.virtual_root); |
| 142 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 135 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
| 143 | html("/"); | 136 | html("/"); |
| 144 | html_attr(cgit_repo->url); | 137 | html_attr(ctx.repo->url); |
| 145 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 138 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
| 146 | html("/"); | 139 | html("/"); |
| 147 | if (page) { | 140 | if (page) { |
| 148 | html(page); | 141 | html(page); |
| @@ -151,10 +144,10 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
| 151 | html_attr(path); | 144 | html_attr(path); |
| 152 | } | 145 | } |
| 153 | } else { | 146 | } else { |
| 154 | html(cgit_script_name); | 147 | html(ctx.cfg.script_name); |
| 155 | html("?url="); | 148 | html("?url="); |
| 156 | html_attr(cgit_repo->url); | 149 | html_attr(ctx.repo->url); |
| 157 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 150 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
| 158 | html("/"); | 151 | html("/"); |
| 159 | if (page) { | 152 | if (page) { |
| 160 | html(page); | 153 | html(page); |
| @@ -164,7 +157,7 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
| 164 | } | 157 | } |
| 165 | delim = "&"; | 158 | delim = "&"; |
| 166 | } | 159 | } |
| 167 | if (head && strcmp(head, cgit_repo->defbranch)) { | 160 | if (head && strcmp(head, ctx.repo->defbranch)) { |
| 168 | html(delim); | 161 | html(delim); |
| 169 | html("h="); | 162 | html("h="); |
| 170 | html_attr(head); | 163 | html_attr(head); |
| @@ -179,7 +172,7 @@ static void reporevlink(char *page, char *name, char *title, char *class, | |||
| 179 | char *delim; | 172 | char *delim; |
| 180 | 173 | ||
| 181 | delim = repolink(title, class, page, head, path); | 174 | delim = repolink(title, class, page, head, path); |
| 182 | if (rev && strcmp(rev, cgit_query_head)) { | 175 | if (rev && strcmp(rev, ctx.qry.head)) { |
| 183 | html(delim); | 176 | html(delim); |
| 184 | html("id="); | 177 | html("id="); |
| 185 | html_attr(rev); | 178 | html_attr(rev); |
| @@ -201,7 +194,7 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
| 201 | char *delim; | 194 | char *delim; |
| 202 | 195 | ||
| 203 | delim = repolink(title, class, "log", head, path); | 196 | delim = repolink(title, class, "log", head, path); |
| 204 | if (rev && strcmp(rev, cgit_query_head)) { | 197 | if (rev && strcmp(rev, ctx.qry.head)) { |
| 205 | html(delim); | 198 | html(delim); |
| 206 | html("id="); | 199 | html("id="); |
| 207 | html_attr(rev); | 200 | html_attr(rev); |
| @@ -229,11 +222,11 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
| 229 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 222 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
| 230 | char *rev) | 223 | char *rev) |
| 231 | { | 224 | { |
| 232 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 225 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
| 233 | name[cgit_max_msg_len] = '\0'; | 226 | name[ctx.cfg.max_msg_len] = '\0'; |
| 234 | name[cgit_max_msg_len - 1] = '.'; | 227 | name[ctx.cfg.max_msg_len - 1] = '.'; |
| 235 | name[cgit_max_msg_len - 2] = '.'; | 228 | name[ctx.cfg.max_msg_len - 2] = '.'; |
| 236 | name[cgit_max_msg_len - 3] = '.'; | 229 | name[ctx.cfg.max_msg_len - 3] = '.'; |
| 237 | } | 230 | } |
| 238 | reporevlink("commit", name, title, class, head, rev, NULL); | 231 | reporevlink("commit", name, title, class, head, rev, NULL); |
| 239 | } | 232 | } |
| @@ -256,7 +249,7 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
| 256 | char *delim; | 249 | char *delim; |
| 257 | 250 | ||
| 258 | delim = repolink(title, class, "diff", head, path); | 251 | delim = repolink(title, class, "diff", head, path); |
| 259 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 252 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
| 260 | html(delim); | 253 | html(delim); |
| 261 | html("id="); | 254 | html("id="); |
| 262 | html_attr(new_rev); | 255 | html_attr(new_rev); |
| @@ -284,7 +277,7 @@ void cgit_object_link(struct object *obj) | |||
| 284 | 277 | ||
| 285 | if (obj->type == OBJ_COMMIT) { | 278 | if (obj->type == OBJ_COMMIT) { |
| 286 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 279 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
| 287 | cgit_query_head, sha1_to_hex(obj->sha1)); | 280 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
| 288 | return; | 281 | return; |
| 289 | } else if (obj->type == OBJ_TREE) { | 282 | } else if (obj->type == OBJ_TREE) { |
| 290 | page = "tree"; | 283 | page = "tree"; |
| @@ -297,7 +290,7 @@ void cgit_object_link(struct object *obj) | |||
| 297 | arg = "id"; | 290 | arg = "id"; |
| 298 | } | 291 | } |
| 299 | 292 | ||
| 300 | url = cgit_pageurl(cgit_query_repo, page, | 293 | url = cgit_pageurl(ctx.qry.repo, page, |
| 301 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 294 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
| 302 | html_link_open(url, NULL, NULL); | 295 | html_link_open(url, NULL, NULL); |
| 303 | htmlf("%s %s", typename(obj->type), | 296 | htmlf("%s %s", typename(obj->type), |
| @@ -360,24 +353,34 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
| 360 | secs * 1.0 / TM_YEAR); | 353 | secs * 1.0 / TM_YEAR); |
| 361 | } | 354 | } |
| 362 | 355 | ||
| 363 | void cgit_print_docstart(char *title, struct cacheitem *item) | 356 | void cgit_print_http_headers(struct cgit_context *ctx) |
| 364 | { | 357 | { |
| 365 | html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); | 358 | if (ctx->page.mimetype && ctx->page.charset) |
| 366 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 359 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
| 367 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 360 | ctx->page.charset); |
| 368 | ttl_seconds(item->ttl))); | 361 | else if (ctx->page.mimetype) |
| 362 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | ||
| 363 | if (ctx->page.filename) | ||
| 364 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | ||
| 365 | ctx->page.filename); | ||
| 366 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | ||
| 367 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | ||
| 369 | html("\n"); | 368 | html("\n"); |
| 369 | } | ||
| 370 | |||
| 371 | void cgit_print_docstart(struct cgit_context *ctx) | ||
| 372 | { | ||
| 370 | html(cgit_doctype); | 373 | html(cgit_doctype); |
| 371 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 374 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
| 372 | html("<head>\n"); | 375 | html("<head>\n"); |
| 373 | html("<title>"); | 376 | html("<title>"); |
| 374 | html_txt(title); | 377 | html_txt(ctx->page.title); |
| 375 | html("</title>\n"); | 378 | html("</title>\n"); |
| 376 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 379 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
| 377 | if (cgit_robots && *cgit_robots) | 380 | if (ctx->cfg.robots && *ctx->cfg.robots) |
| 378 | htmlf("<meta name='robots' content='%s'/>\n", cgit_robots); | 381 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
| 379 | html("<link rel='stylesheet' type='text/css' href='"); | 382 | html("<link rel='stylesheet' type='text/css' href='"); |
| 380 | html_attr(cgit_css); | 383 | html_attr(ctx->cfg.css); |
| 381 | html("'/>\n"); | 384 | html("'/>\n"); |
| 382 | html("</head>\n"); | 385 | html("</head>\n"); |
| 383 | html("<body>\n"); | 386 | html("<body>\n"); |
| @@ -392,7 +395,7 @@ int print_branch_option(const char *refname, const unsigned char *sha1, | |||
| 392 | int flags, void *cb_data) | 395 | int flags, void *cb_data) |
| 393 | { | 396 | { |
| 394 | char *name = (char *)refname; | 397 | char *name = (char *)refname; |
| 395 | html_option(name, name, cgit_query_head); | 398 | html_option(name, name, ctx.qry.head); |
| 396 | return 0; | 399 | return 0; |
| 397 | } | 400 | } |
| 398 | 401 | ||
| @@ -426,7 +429,7 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, | |||
| 426 | html("<h1>download</h1>\n"); | 429 | html("<h1>download</h1>\n"); |
| 427 | *header = 1; | 430 | *header = 1; |
| 428 | } | 431 | } |
| 429 | url = cgit_pageurl(cgit_query_repo, "blob", | 432 | url = cgit_pageurl(ctx.qry.repo, "blob", |
| 430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 433 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
| 431 | buf)); | 434 | buf)); |
| 432 | html_link_open(url, NULL, "menu"); | 435 | html_link_open(url, NULL, "menu"); |
| @@ -439,30 +442,30 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page) | |||
| 439 | { | 442 | { |
| 440 | char *url; | 443 | char *url; |
| 441 | 444 | ||
| 442 | if (!cgit_virtual_root) { | 445 | if (!ctx.cfg.virtual_root) { |
| 443 | url = fmt("%s/%s", cgit_query_repo, page); | 446 | url = fmt("%s/%s", ctx.qry.repo, page); |
| 444 | if (cgit_query_path) | 447 | if (ctx.qry.path) |
| 445 | url = fmt("%s/%s", url, cgit_query_path); | 448 | url = fmt("%s/%s", url, ctx.qry.path); |
| 446 | html_hidden("url", url); | 449 | html_hidden("url", url); |
| 447 | } | 450 | } |
| 448 | 451 | ||
| 449 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) | 452 | if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) |
| 450 | html_hidden("h", cgit_query_head); | 453 | html_hidden("h", ctx.qry.head); |
| 451 | 454 | ||
| 452 | if (cgit_query_sha1) | 455 | if (ctx.qry.sha1) |
| 453 | html_hidden("id", cgit_query_sha1); | 456 | html_hidden("id", ctx.qry.sha1); |
| 454 | if (cgit_query_sha2) | 457 | if (ctx.qry.sha2) |
| 455 | html_hidden("id2", cgit_query_sha2); | 458 | html_hidden("id2", ctx.qry.sha2); |
| 456 | 459 | ||
| 457 | if (incl_search) { | 460 | if (incl_search) { |
| 458 | if (cgit_query_grep) | 461 | if (ctx.qry.grep) |
| 459 | html_hidden("qt", cgit_query_grep); | 462 | html_hidden("qt", ctx.qry.grep); |
| 460 | if (cgit_query_search) | 463 | if (ctx.qry.search) |
| 461 | html_hidden("q", cgit_query_search); | 464 | html_hidden("q", ctx.qry.search); |
| 462 | } | 465 | } |
| 463 | } | 466 | } |
| 464 | 467 | ||
| 465 | void cgit_print_pageheader(char *title, int show_search) | 468 | void cgit_print_pageheader(struct cgit_context *ctx) |
| 466 | { | 469 | { |
| 467 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | 470 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; |
| 468 | int header = 0; | 471 | int header = 0; |
| @@ -474,40 +477,40 @@ void cgit_print_pageheader(char *title, int show_search) | |||
| 474 | html("<tr><td class='sidebar'>\n<a href='"); | 477 | html("<tr><td class='sidebar'>\n<a href='"); |
| 475 | html_attr(cgit_rooturl()); | 478 | html_attr(cgit_rooturl()); |
| 476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", | 479 | htmlf("'><img src='%s' alt='cgit'/></a>\n", |
| 477 | cgit_logo); | 480 | ctx->cfg.logo); |
| 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 481 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
| 479 | if (cgit_query_repo) { | 482 | if (ctx->repo) { |
| 480 | html("<h1 class='first'>"); | 483 | html("<h1 class='first'>"); |
| 481 | html_txt(strrpart(cgit_repo->name, 20)); | 484 | html_txt(strrpart(ctx->repo->name, 20)); |
| 482 | html("</h1>\n"); | 485 | html("</h1>\n"); |
| 483 | html_txt(cgit_repo->desc); | 486 | html_txt(ctx->repo->desc); |
| 484 | if (cgit_repo->owner) { | 487 | if (ctx->repo->owner) { |
| 485 | html("<h1>owner</h1>\n"); | 488 | html("<h1>owner</h1>\n"); |
| 486 | html_txt(cgit_repo->owner); | 489 | html_txt(ctx->repo->owner); |
| 487 | } | 490 | } |
| 488 | html("<h1>navigate</h1>\n"); | 491 | html("<h1>navigate</h1>\n"); |
| 489 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, | 492 | reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head, |
| 490 | NULL, NULL); | 493 | NULL, NULL); |
| 491 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, | 494 | cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL, |
| 492 | 0, NULL, NULL); | 495 | 0, NULL, NULL); |
| 493 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, | 496 | cgit_tree_link("tree", NULL, "menu", ctx->qry.head, |
| 494 | cgit_query_sha1, NULL); | 497 | ctx->qry.sha1, NULL); |
| 495 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, | 498 | cgit_commit_link("commit", NULL, "menu", ctx->qry.head, |
| 496 | cgit_query_sha1); | 499 | ctx->qry.sha1); |
| 497 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, | 500 | cgit_diff_link("diff", NULL, "menu", ctx->qry.head, |
| 498 | cgit_query_sha1, cgit_query_sha2, NULL); | 501 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
| 499 | cgit_patch_link("patch", NULL, "menu", cgit_query_head, | 502 | cgit_patch_link("patch", NULL, "menu", ctx->qry.head, |
| 500 | cgit_query_sha1); | 503 | ctx->qry.sha1); |
| 501 | 504 | ||
| 502 | for_each_ref(print_archive_ref, &header); | 505 | for_each_ref(print_archive_ref, &header); |
| 503 | 506 | ||
| 504 | if (cgit_repo->clone_url || cgit_clone_prefix) { | 507 | if (ctx->repo->clone_url || ctx->cfg.clone_prefix) { |
| 505 | html("<h1>clone</h1>\n"); | 508 | html("<h1>clone</h1>\n"); |
| 506 | if (cgit_repo->clone_url) | 509 | if (ctx->repo->clone_url) |
| 507 | url = cgit_repo->clone_url; | 510 | url = ctx->repo->clone_url; |
| 508 | else | 511 | else |
| 509 | url = fmt("%s%s", cgit_clone_prefix, | 512 | url = fmt("%s%s", ctx->cfg.clone_prefix, |
| 510 | cgit_repo->url); | 513 | ctx->repo->url); |
| 511 | html("<a class='menu' href='"); | 514 | html("<a class='menu' href='"); |
| 512 | html_attr(url); | 515 | html_attr(url); |
| 513 | html("' title='"); | 516 | html("' title='"); |
| @@ -519,10 +522,10 @@ void cgit_print_pageheader(char *title, int show_search) | |||
| 519 | 522 | ||
| 520 | html("<h1>branch</h1>\n"); | 523 | html("<h1>branch</h1>\n"); |
| 521 | html("<form method='get' action=''>\n"); | 524 | html("<form method='get' action=''>\n"); |
| 522 | add_hidden_formfields(0, 1, cgit_query_page); | 525 | add_hidden_formfields(0, 1, ctx->qry.page); |
| 523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); | 526 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); |
| 524 | html("<select name='h' onchange='this.form.submit();'>\n"); | 527 | html("<select name='h' onchange='this.form.submit();'>\n"); |
| 525 | for_each_branch_ref(print_branch_option, cgit_query_head); | 528 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
| 526 | html("</select>\n"); | 529 | html("</select>\n"); |
| 527 | // html("</td><td>"); | 530 | // html("</td><td>"); |
| 528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); | 531 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); |
| @@ -531,22 +534,22 @@ void cgit_print_pageheader(char *title, int show_search) | |||
| 531 | 534 | ||
| 532 | html("<h1>search</h1>\n"); | 535 | html("<h1>search</h1>\n"); |
| 533 | html("<form method='get' action='"); | 536 | html("<form method='get' action='"); |
| 534 | if (cgit_virtual_root) | 537 | if (ctx->cfg.virtual_root) |
| 535 | html_attr(cgit_fileurl(cgit_query_repo, "log", | 538 | html_attr(cgit_fileurl(ctx->qry.repo, "log", |
| 536 | cgit_query_path, NULL)); | 539 | ctx->qry.path, NULL)); |
| 537 | html("'>\n"); | 540 | html("'>\n"); |
| 538 | add_hidden_formfields(1, 0, "log"); | 541 | add_hidden_formfields(1, 0, "log"); |
| 539 | html("<select name='qt'>\n"); | 542 | html("<select name='qt'>\n"); |
| 540 | html_option("grep", "log msg", cgit_query_grep); | 543 | html_option("grep", "log msg", ctx->qry.grep); |
| 541 | html_option("author", "author", cgit_query_grep); | 544 | html_option("author", "author", ctx->qry.grep); |
| 542 | html_option("committer", "committer", cgit_query_grep); | 545 | html_option("committer", "committer", ctx->qry.grep); |
| 543 | html("</select>\n"); | 546 | html("</select>\n"); |
| 544 | html("<input class='txt' type='text' name='q' value='"); | 547 | html("<input class='txt' type='text' name='q' value='"); |
| 545 | html_attr(cgit_query_search); | 548 | html_attr(ctx->qry.search); |
| 546 | html("'/>\n"); | 549 | html("'/>\n"); |
| 547 | html("</form>\n"); | 550 | html("</form>\n"); |
| 548 | } else { | 551 | } else { |
| 549 | if (!cgit_index_info || html_include(cgit_index_info)) | 552 | if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info)) |
| 550 | html(default_info); | 553 | html(default_info); |
| 551 | } | 554 | } |
| 552 | 555 | ||
| @@ -555,16 +558,34 @@ void cgit_print_pageheader(char *title, int show_search) | |||
| 555 | html("<td id='content'>\n"); | 558 | html("<td id='content'>\n"); |
| 556 | } | 559 | } |
| 557 | 560 | ||
| 558 | 561 | void cgit_print_filemode(unsigned short mode) | |
| 559 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | ||
| 560 | struct cacheitem *item) | ||
| 561 | { | 562 | { |
| 562 | htmlf("Content-Type: %s\n", mimetype); | 563 | if (S_ISDIR(mode)) |
| 563 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 564 | html("d"); |
| 564 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 565 | else if (S_ISLNK(mode)) |
| 565 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 566 | html("l"); |
| 566 | ttl_seconds(item->ttl))); | 567 | else if (S_ISGITLINK(mode)) |
| 567 | html("\n"); | 568 | html("m"); |
| 569 | else | ||
| 570 | html("-"); | ||
| 571 | html_fileperm(mode >> 6); | ||
| 572 | html_fileperm(mode >> 3); | ||
| 573 | html_fileperm(mode); | ||
| 568 | } | 574 | } |
| 569 | 575 | ||
| 570 | /* vim:set sw=8: */ | 576 | void cgit_print_snapshot_links(const char *repo, const char *head, |
| 577 | const char *hex, int snapshots) | ||
| 578 | { | ||
| 579 | const struct cgit_snapshot_format* f; | ||
| 580 | char *filename; | ||
| 581 | |||
| 582 | for (f = cgit_snapshot_formats; f->suffix; f++) { | ||
| 583 | if (!(snapshots & f->bit)) | ||
| 584 | continue; | ||
| 585 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | ||
| 586 | f->suffix); | ||
| 587 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | ||
| 588 | (char *)hex, filename); | ||
| 589 | html("<br/>"); | ||
| 590 | } | ||
| 591 | } | ||
diff --git a/ui-shared.h b/ui-shared.h new file mode 100644 index 0000000..94de884 --- /dev/null +++ b/ui-shared.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #ifndef UI_SHARED_H | ||
| 2 | #define UI_SHARED_H | ||
| 3 | |||
| 4 | extern char *cgit_repourl(const char *reponame); | ||
| 5 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | ||
| 6 | const char *filename, const char *query); | ||
| 7 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | ||
| 8 | const char *query); | ||
| 9 | |||
| 10 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | ||
| 11 | char *rev, char *path); | ||
| 12 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | ||
| 13 | char *rev, char *path, int ofs, char *grep, | ||
| 14 | char *pattern); | ||
| 15 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
| 16 | char *rev); | ||
| 17 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | ||
| 18 | char *rev, char *path); | ||
| 19 | extern void cgit_snapshot_link(char *name, char *title, char *class, | ||
| 20 | char *head, char *rev, char *archivename); | ||
| 21 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | ||
| 22 | char *new_rev, char *old_rev, char *path); | ||
| 23 | extern void cgit_object_link(struct object *obj); | ||
| 24 | |||
| 25 | extern void cgit_print_error(char *msg); | ||
| 26 | extern void cgit_print_date(time_t secs, char *format); | ||
| 27 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | ||
| 28 | extern void cgit_print_http_headers(struct cgit_context *ctx); | ||
| 29 | extern void cgit_print_docstart(struct cgit_context *ctx); | ||
| 30 | extern void cgit_print_docend(); | ||
| 31 | extern void cgit_print_pageheader(struct cgit_context *ctx); | ||
| 32 | extern void cgit_print_filemode(unsigned short mode); | ||
| 33 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | ||
| 34 | const char *hex, int snapshots); | ||
| 35 | |||
| 36 | #endif /* UI_SHARED_H */ | ||
diff --git a/ui-snapshot.c b/ui-snapshot.c index dfedd8f..966a140 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 10 | 12 | ||
| 11 | static int write_compressed_tar_archive(struct archiver_args *args,const char *filter) | 13 | static int write_compressed_tar_archive(struct archiver_args *args,const char *filter) |
| 12 | { | 14 | { |
| @@ -54,104 +56,59 @@ static int write_tar_bzip2_archive(struct archiver_args *args) | |||
| 54 | return write_compressed_tar_archive(args,"bzip2"); | 56 | return write_compressed_tar_archive(args,"bzip2"); |
| 55 | } | 57 | } |
| 56 | 58 | ||
| 57 | static const struct snapshot_archive_t { | 59 | const struct cgit_snapshot_format cgit_snapshot_formats[] = { |
| 58 | const char *suffix; | ||
| 59 | const char *mimetype; | ||
| 60 | write_archive_fn_t write_func; | ||
| 61 | int bit; | ||
| 62 | } snapshot_archives[] = { | ||
| 63 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, | 60 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, |
| 64 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, | 61 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, |
| 65 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, | 62 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, |
| 66 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } | 63 | { ".tar", "application/x-tar", write_tar_archive, 0x8 }, |
| 64 | {} | ||
| 67 | }; | 65 | }; |
| 68 | 66 | ||
| 69 | #define snapshot_archives_len (sizeof(snapshot_archives) / sizeof(*snapshot_archives)) | 67 | static int make_snapshot(const struct cgit_snapshot_format *format, |
| 70 | |||
| 71 | void cgit_print_snapshot(struct cacheitem *item, const char *head, | ||
| 72 | const char *hex, const char *prefix, | 68 | const char *hex, const char *prefix, |
| 73 | const char *filename, int snapshots) | 69 | const char *filename) |
| 74 | { | 70 | { |
| 75 | const struct snapshot_archive_t* sat; | ||
| 76 | struct archiver_args args; | 71 | struct archiver_args args; |
| 77 | struct commit *commit; | 72 | struct commit *commit; |
| 78 | unsigned char sha1[20]; | 73 | unsigned char sha1[20]; |
| 79 | int f, sl, fnl = strlen(filename); | ||
| 80 | 74 | ||
| 81 | for(f=0; f<snapshot_archives_len; f++) { | 75 | if(get_sha1(hex, sha1)) { |
| 82 | sat = &snapshot_archives[f]; | 76 | cgit_print_error(fmt("Bad object id: %s", hex)); |
| 83 | if(!(snapshots & sat->bit)) | 77 | return 1; |
| 84 | continue; | ||
| 85 | sl = strlen(sat->suffix); | ||
| 86 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | ||
| 87 | continue; | ||
| 88 | if (!hex) | ||
| 89 | hex = head; | ||
| 90 | if(get_sha1(hex, sha1)) { | ||
| 91 | cgit_print_error(fmt("Bad object id: %s", hex)); | ||
| 92 | return; | ||
| 93 | } | ||
| 94 | commit = lookup_commit_reference(sha1); | ||
| 95 | if(!commit) { | ||
| 96 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | ||
| 97 | return;; | ||
| 98 | } | ||
| 99 | memset(&args,0,sizeof(args)); | ||
| 100 | args.base = fmt("%s/", prefix); | ||
| 101 | args.tree = commit->tree; | ||
| 102 | args.time = commit->date; | ||
| 103 | cgit_print_snapshot_start(sat->mimetype, filename, item); | ||
| 104 | (*sat->write_func)(&args); | ||
| 105 | return; | ||
| 106 | } | 78 | } |
| 107 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 79 | commit = lookup_commit_reference(sha1); |
| 108 | } | 80 | if(!commit) { |
| 109 | 81 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | |
| 110 | void cgit_print_snapshot_links(const char *repo, const char *head, | 82 | return 1; |
| 111 | const char *hex, int snapshots) | ||
| 112 | { | ||
| 113 | const struct snapshot_archive_t* sat; | ||
| 114 | char *filename; | ||
| 115 | int f; | ||
| 116 | |||
| 117 | for(f=0; f<snapshot_archives_len; f++) { | ||
| 118 | sat = &snapshot_archives[f]; | ||
| 119 | if(!(snapshots & sat->bit)) | ||
| 120 | continue; | ||
| 121 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | ||
| 122 | sat->suffix); | ||
| 123 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | ||
| 124 | (char *)hex, filename); | ||
| 125 | html("<br/>"); | ||
| 126 | } | 83 | } |
| 84 | memset(&args, 0, sizeof(args)); | ||
| 85 | args.base = fmt("%s/", prefix); | ||
| 86 | args.tree = commit->tree; | ||
| 87 | args.time = commit->date; | ||
| 88 | ctx.page.mimetype = xstrdup(format->mimetype); | ||
| 89 | ctx.page.filename = xstrdup(filename); | ||
| 90 | cgit_print_http_headers(&ctx); | ||
| 91 | format->write_func(&args); | ||
| 92 | return 0; | ||
| 127 | } | 93 | } |
| 128 | 94 | ||
| 129 | int cgit_parse_snapshots_mask(const char *str) | 95 | void cgit_print_snapshot(const char *head, const char *hex, const char *prefix, |
| 96 | const char *filename, int snapshots) | ||
| 130 | { | 97 | { |
| 131 | const struct snapshot_archive_t* sat; | 98 | const struct cgit_snapshot_format* f; |
| 132 | static const char *delim = " \t,:/|;"; | 99 | int sl, fnl; |
| 133 | int f, tl, sl, rv = 0; | 100 | |
| 134 | 101 | fnl = strlen(filename); | |
| 135 | /* favor legacy setting */ | 102 | if (!hex) |
| 136 | if(atoi(str)) | 103 | hex = head; |
| 137 | return 1; | 104 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
| 138 | for(;;) { | 105 | if (!(snapshots & f->bit)) |
| 139 | str += strspn(str,delim); | 106 | continue; |
| 140 | tl = strcspn(str,delim); | 107 | sl = strlen(f->suffix); |
| 141 | if(!tl) | 108 | if(fnl < sl || strcmp(&filename[fnl-sl], f->suffix)) |
| 142 | break; | 109 | continue; |
| 143 | for(f=0; f<snapshot_archives_len; f++) { | 110 | make_snapshot(f, hex, prefix, filename); |
| 144 | sat = &snapshot_archives[f]; | 111 | return; |
| 145 | sl = strlen(sat->suffix); | ||
| 146 | if((tl == sl && !strncmp(sat->suffix, str, tl)) || | ||
| 147 | (tl == sl-1 && !strncmp(sat->suffix+1, str, tl-1))) { | ||
| 148 | rv |= sat->bit; | ||
| 149 | break; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | str += tl; | ||
| 153 | } | 112 | } |
| 154 | return rv; | 113 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
| 155 | } | 114 | } |
| 156 | |||
| 157 | /* vim:set sw=8: */ | ||
diff --git a/ui-snapshot.h b/ui-snapshot.h new file mode 100644 index 0000000..6e03761 --- /dev/null +++ b/ui-snapshot.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #ifndef UI_SNAPSHOT_H | ||
| 2 | #define UI_SNAPSHOT_H | ||
| 3 | |||
| 4 | extern void cgit_print_snapshot(const char *head, const char *hex, | ||
| 5 | const char *prefix, const char *filename, | ||
| 6 | int snapshot); | ||
| 7 | |||
| 8 | #endif /* UI_SNAPSHOT_H */ | ||
diff --git a/ui-summary.c b/ui-summary.c index b96414e..0b66b52 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
| @@ -7,194 +7,25 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | 10 | #include "html.h" | |
| 11 | static int header; | 11 | #include "ui-log.h" |
| 12 | 12 | #include "ui-refs.h" | |
| 13 | static int cmp_age(int age1, int age2) | ||
| 14 | { | ||
| 15 | if (age1 != 0 && age2 != 0) | ||
| 16 | return age2 - age1; | ||
| 17 | |||
| 18 | if (age1 == 0 && age2 == 0) | ||
| 19 | return 0; | ||
| 20 | |||
| 21 | if (age1 == 0) | ||
| 22 | return +1; | ||
| 23 | |||
| 24 | return -1; | ||
| 25 | } | ||
| 26 | |||
| 27 | static int cmp_ref_name(const void *a, const void *b) | ||
| 28 | { | ||
| 29 | struct refinfo *r1 = *(struct refinfo **)a; | ||
| 30 | struct refinfo *r2 = *(struct refinfo **)b; | ||
| 31 | |||
| 32 | return strcmp(r1->refname, r2->refname); | ||
| 33 | } | ||
| 34 | |||
| 35 | static int cmp_branch_age(const void *a, const void *b) | ||
| 36 | { | ||
| 37 | struct refinfo *r1 = *(struct refinfo **)a; | ||
| 38 | struct refinfo *r2 = *(struct refinfo **)b; | ||
| 39 | |||
| 40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | ||
| 41 | } | ||
| 42 | |||
| 43 | static int cmp_tag_age(const void *a, const void *b) | ||
| 44 | { | ||
| 45 | struct refinfo *r1 = *(struct refinfo **)a; | ||
| 46 | struct refinfo *r2 = *(struct refinfo **)b; | ||
| 47 | |||
| 48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | ||
| 49 | } | ||
| 50 | |||
| 51 | static int print_branch(struct refinfo *ref) | ||
| 52 | { | ||
| 53 | struct commitinfo *info = ref->commit; | ||
| 54 | char *name = (char *)ref->refname; | ||
| 55 | |||
| 56 | if (!info) | ||
| 57 | return 1; | ||
| 58 | html("<tr><td>"); | ||
| 59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL); | ||
| 60 | html("</td><td>"); | ||
| 61 | |||
| 62 | if (ref->object->type == OBJ_COMMIT) { | ||
| 63 | cgit_print_age(info->commit->date, -1, NULL); | ||
| 64 | html("</td><td>"); | ||
| 65 | html_txt(info->author); | ||
| 66 | html("</td><td>"); | ||
| 67 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | ||
| 68 | } else { | ||
| 69 | html("</td><td></td><td>"); | ||
| 70 | cgit_object_link(ref->object); | ||
| 71 | } | ||
| 72 | html("</td></tr>\n"); | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | static void print_tag_header() | ||
| 77 | { | ||
| 78 | html("<tr class='nohover'><th class='left'>Tag</th>" | ||
| 79 | "<th class='left'>Age</th>" | ||
| 80 | "<th class='left'>Author</th>" | ||
| 81 | "<th class='left'>Reference</th></tr>\n"); | ||
| 82 | header = 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | static int print_tag(struct refinfo *ref) | ||
| 86 | { | ||
| 87 | struct tag *tag; | ||
| 88 | struct taginfo *info; | ||
| 89 | char *url, *name = (char *)ref->refname; | ||
| 90 | |||
| 91 | if (ref->object->type == OBJ_TAG) { | ||
| 92 | tag = (struct tag *)ref->object; | ||
| 93 | info = ref->tag; | ||
| 94 | if (!tag || !info) | ||
| 95 | return 1; | ||
| 96 | html("<tr><td>"); | ||
| 97 | url = cgit_pageurl(cgit_query_repo, "tag", | ||
| 98 | fmt("id=%s", name)); | ||
| 99 | html_link_open(url, NULL, NULL); | ||
| 100 | html_txt(name); | ||
| 101 | html_link_close(); | ||
| 102 | html("</td><td>"); | ||
| 103 | if (info->tagger_date > 0) | ||
| 104 | cgit_print_age(info->tagger_date, -1, NULL); | ||
| 105 | html("</td><td>"); | ||
| 106 | if (info->tagger) | ||
| 107 | html(info->tagger); | ||
| 108 | html("</td><td>"); | ||
| 109 | cgit_object_link(tag->tagged); | ||
| 110 | html("</td></tr>\n"); | ||
| 111 | } else { | ||
| 112 | if (!header) | ||
| 113 | print_tag_header(); | ||
| 114 | html("<tr><td>"); | ||
| 115 | html_txt(name); | ||
| 116 | html("</td><td colspan='2'/><td>"); | ||
| 117 | cgit_object_link(ref->object); | ||
| 118 | html("</td></tr>\n"); | ||
| 119 | } | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | |||
| 123 | static void print_refs_link(char *path) | ||
| 124 | { | ||
| 125 | html("<tr class='nohover'><td colspan='4'>"); | ||
| 126 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); | ||
| 127 | html("</td></tr>"); | ||
| 128 | } | ||
| 129 | |||
| 130 | void cgit_print_branches(int maxcount) | ||
| 131 | { | ||
| 132 | struct reflist list; | ||
| 133 | int i; | ||
| 134 | |||
| 135 | html("<tr class='nohover'><th class='left'>Branch</th>" | ||
| 136 | "<th class='left'>Idle</th>" | ||
| 137 | "<th class='left'>Author</th>" | ||
| 138 | "<th class='left'>Head commit</th></tr>\n"); | ||
| 139 | |||
| 140 | list.refs = NULL; | ||
| 141 | list.alloc = list.count = 0; | ||
| 142 | for_each_branch_ref(cgit_refs_cb, &list); | ||
| 143 | |||
| 144 | if (maxcount == 0 || maxcount > list.count) | ||
| 145 | maxcount = list.count; | ||
| 146 | |||
| 147 | if (maxcount < list.count) { | ||
| 148 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | ||
| 149 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | ||
| 150 | } | ||
| 151 | |||
| 152 | for(i=0; i<maxcount; i++) | ||
| 153 | print_branch(list.refs[i]); | ||
| 154 | |||
| 155 | if (maxcount < list.count) | ||
| 156 | print_refs_link("heads"); | ||
| 157 | } | ||
| 158 | |||
| 159 | void cgit_print_tags(int maxcount) | ||
| 160 | { | ||
| 161 | struct reflist list; | ||
| 162 | int i; | ||
| 163 | |||
| 164 | header = 0; | ||
| 165 | list.refs = NULL; | ||
| 166 | list.alloc = list.count = 0; | ||
| 167 | for_each_tag_ref(cgit_refs_cb, &list); | ||
| 168 | if (list.count == 0) | ||
| 169 | return; | ||
| 170 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | ||
| 171 | if (!maxcount) | ||
| 172 | maxcount = list.count; | ||
| 173 | else if (maxcount > list.count) | ||
| 174 | maxcount = list.count; | ||
| 175 | print_tag_header(); | ||
| 176 | for(i=0; i<maxcount; i++) | ||
| 177 | print_tag(list.refs[i]); | ||
| 178 | |||
| 179 | if (maxcount < list.count) | ||
| 180 | print_refs_link("tags"); | ||
| 181 | } | ||
| 182 | 13 | ||
| 183 | void cgit_print_summary() | 14 | void cgit_print_summary() |
| 184 | { | 15 | { |
| 185 | if (cgit_repo->readme) { | 16 | if (ctx.repo->readme) { |
| 186 | html("<div id='summary'>"); | 17 | html("<div id='summary'>"); |
| 187 | html_include(cgit_repo->readme); | 18 | html_include(ctx.repo->readme); |
| 188 | html("</div>"); | 19 | html("</div>"); |
| 189 | } | 20 | } |
| 190 | if (cgit_summary_log > 0) | 21 | if (ctx.cfg.summary_log > 0) |
| 191 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, | 22 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, |
| 192 | NULL, NULL, 0); | 23 | NULL, NULL, 0); |
| 193 | html("<table summary='repository info' class='list nowrap'>"); | 24 | html("<table summary='repository info' class='list nowrap'>"); |
| 194 | if (cgit_summary_log > 0) | 25 | if (ctx.cfg.summary_log > 0) |
| 195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 26 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
| 196 | cgit_print_branches(cgit_summary_branches); | 27 | cgit_print_branches(ctx.cfg.summary_branches); |
| 197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 28 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
| 198 | cgit_print_tags(cgit_summary_tags); | 29 | cgit_print_tags(ctx.cfg.summary_tags); |
| 199 | html("</table>"); | 30 | html("</table>"); |
| 200 | } | 31 | } |
diff --git a/ui-summary.h b/ui-summary.h new file mode 100644 index 0000000..37aedd2 --- /dev/null +++ b/ui-summary.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_SUMMARY_H | ||
| 2 | #define UI_SUMMARY_H | ||
| 3 | |||
| 4 | extern void cgit_print_summary(); | ||
| 5 | |||
| 6 | #endif /* UI_SUMMARY_H */ | ||
| @@ -7,7 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | 10 | #include "html.h" | |
| 11 | #include "ui-shared.h" | ||
| 11 | 12 | ||
| 12 | static void print_tag_content(char *buf) | 13 | static void print_tag_content(char *buf) |
| 13 | { | 14 | { |
diff --git a/ui-tag.h b/ui-tag.h new file mode 100644 index 0000000..d295cdc --- /dev/null +++ b/ui-tag.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_TAG_H | ||
| 2 | #define UI_TAG_H | ||
| 3 | |||
| 4 | extern void cgit_print_tag(char *revname); | ||
| 5 | |||
| 6 | #endif /* UI_TAG_H */ | ||
| @@ -7,6 +7,8 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | #include "html.h" | ||
| 11 | #include "ui-shared.h" | ||
| 10 | 12 | ||
| 11 | char *curr_rev; | 13 | char *curr_rev; |
| 12 | char *match_path; | 14 | char *match_path; |
| @@ -34,7 +36,7 @@ static void print_object(const unsigned char *sha1, char *path) | |||
| 34 | } | 36 | } |
| 35 | 37 | ||
| 36 | html(" blob: <a href='"); | 38 | html(" blob: <a href='"); |
| 37 | html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); | 39 | html_attr(cgit_pageurl(ctx.qry.repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); |
| 38 | htmlf("'>%s</a>",sha1_to_hex(sha1)); | 40 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
| 39 | 41 | ||
| 40 | html("<table summary='blob content' class='blob'>\n"); | 42 | html("<table summary='blob content' class='blob'>\n"); |
| @@ -67,8 +69,8 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
| 67 | unsigned long size = 0; | 69 | unsigned long size = 0; |
| 68 | 70 | ||
| 69 | name = xstrdup(pathname); | 71 | name = xstrdup(pathname); |
| 70 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", | 72 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
| 71 | cgit_query_path ? "/" : "", name); | 73 | ctx.qry.path ? "/" : "", name); |
| 72 | 74 | ||
| 73 | type = sha1_object_info(sha1, &size); | 75 | type = sha1_object_info(sha1, &size); |
| 74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { | 76 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
| @@ -79,27 +81,27 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | html("<tr><td class='ls-mode'>"); | 83 | html("<tr><td class='ls-mode'>"); |
| 82 | html_filemode(mode); | 84 | cgit_print_filemode(mode); |
| 83 | html("</td><td>"); | 85 | html("</td><td>"); |
| 84 | if (S_ISGITLINK(mode)) { | 86 | if (S_ISGITLINK(mode)) { |
| 85 | htmlf("<a class='ls-mod' href='"); | 87 | htmlf("<a class='ls-mod' href='"); |
| 86 | html_attr(fmt(cgit_repo->module_link, | 88 | html_attr(fmt(ctx.repo->module_link, |
| 87 | name, | 89 | name, |
| 88 | sha1_to_hex(sha1))); | 90 | sha1_to_hex(sha1))); |
| 89 | html("'>"); | 91 | html("'>"); |
| 90 | html_txt(name); | 92 | html_txt(name); |
| 91 | html("</a>"); | 93 | html("</a>"); |
| 92 | } else if (S_ISDIR(mode)) { | 94 | } else if (S_ISDIR(mode)) { |
| 93 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, | 95 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
| 94 | curr_rev, fullpath); | 96 | curr_rev, fullpath); |
| 95 | } else { | 97 | } else { |
| 96 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, | 98 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
| 97 | curr_rev, fullpath); | 99 | curr_rev, fullpath); |
| 98 | } | 100 | } |
| 99 | htmlf("</td><td class='ls-size'>%li</td>", size); | 101 | htmlf("</td><td class='ls-size'>%li</td>", size); |
| 100 | 102 | ||
| 101 | html("<td>"); | 103 | html("<td>"); |
| 102 | cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, | 104 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
| 103 | fullpath, 0, NULL, NULL); | 105 | fullpath, 0, NULL, NULL); |
| 104 | html("</td></tr>\n"); | 106 | html("</td></tr>\n"); |
| 105 | free(name); | 107 | free(name); |
| @@ -153,10 +155,10 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | |||
| 153 | if (state == 0) { | 155 | if (state == 0) { |
| 154 | memcpy(buffer, base, baselen); | 156 | memcpy(buffer, base, baselen); |
| 155 | strcpy(buffer+baselen, pathname); | 157 | strcpy(buffer+baselen, pathname); |
| 156 | url = cgit_pageurl(cgit_query_repo, "tree", | 158 | url = cgit_pageurl(ctx.qry.repo, "tree", |
| 157 | fmt("h=%s&path=%s", curr_rev, buffer)); | 159 | fmt("h=%s&path=%s", curr_rev, buffer)); |
| 158 | html("/"); | 160 | html("/"); |
| 159 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, | 161 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, |
| 160 | curr_rev, buffer); | 162 | curr_rev, buffer); |
| 161 | 163 | ||
| 162 | if (strcmp(match_path, buffer)) | 164 | if (strcmp(match_path, buffer)) |
| @@ -188,7 +190,7 @@ void cgit_print_tree(const char *rev, char *path) | |||
| 188 | const char *paths[] = {path, NULL}; | 190 | const char *paths[] = {path, NULL}; |
| 189 | 191 | ||
| 190 | if (!rev) | 192 | if (!rev) |
| 191 | rev = cgit_query_head; | 193 | rev = ctx.qry.head; |
| 192 | 194 | ||
| 193 | curr_rev = xstrdup(rev); | 195 | curr_rev = xstrdup(rev); |
| 194 | if (get_sha1(rev, sha1)) { | 196 | if (get_sha1(rev, sha1)) { |
| @@ -202,7 +204,7 @@ void cgit_print_tree(const char *rev, char *path) | |||
| 202 | } | 204 | } |
| 203 | 205 | ||
| 204 | html("path: <a href='"); | 206 | html("path: <a href='"); |
| 205 | html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); | 207 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); |
| 206 | html("'>root</a>"); | 208 | html("'>root</a>"); |
| 207 | 209 | ||
| 208 | if (path == NULL) { | 210 | if (path == NULL) { |
diff --git a/ui-tree.h b/ui-tree.h new file mode 100644 index 0000000..bbd34e3 --- /dev/null +++ b/ui-tree.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef UI_TREE_H | ||
| 2 | #define UI_TREE_H | ||
| 3 | |||
| 4 | extern void cgit_print_tree(const char *rev, char *path); | ||
| 5 | |||
| 6 | #endif /* UI_TREE_H */ | ||
