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 | |||