-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-refs.c | 30 |
5 files changed, 37 insertions, 2 deletions
@@ -1,72 +1,72 @@ | |||
1 | CGIT_VERSION = v0.6.3 | 1 | CGIT_VERSION = v0.6.3 |
2 | CGIT_SCRIPT_NAME = cgit.cgi | 2 | CGIT_SCRIPT_NAME = cgit.cgi |
3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit | 3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit |
4 | CGIT_CONFIG = /etc/cgitrc | 4 | CGIT_CONFIG = /etc/cgitrc |
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | SHA1_HEADER = <openssl/sha.h> | 6 | SHA1_HEADER = <openssl/sha.h> |
7 | GIT_VER = 1.5.3.3 | 7 | GIT_VER = 1.5.3.3 |
8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
9 | 9 | ||
10 | # | 10 | # |
11 | # Let the user override the above settings. | 11 | # Let the user override the above settings. |
12 | # | 12 | # |
13 | -include cgit.conf | 13 | -include cgit.conf |
14 | 14 | ||
15 | 15 | ||
16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
19 | ui-snapshot.o ui-blob.o ui-tag.o | 19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o |
20 | 20 | ||
21 | 21 | ||
22 | .PHONY: all git install clean distclean force-version get-git | 22 | .PHONY: all git install clean distclean force-version get-git |
23 | 23 | ||
24 | all: cgit git | 24 | all: cgit git |
25 | 25 | ||
26 | VERSION: force-version | 26 | VERSION: force-version |
27 | @./gen-version.sh "$(CGIT_VERSION)" | 27 | @./gen-version.sh "$(CGIT_VERSION)" |
28 | -include VERSION | 28 | -include VERSION |
29 | 29 | ||
30 | 30 | ||
31 | CFLAGS += -g -Wall -Igit | 31 | CFLAGS += -g -Wall -Igit |
32 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 32 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
33 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 33 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
34 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 34 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
35 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 35 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
36 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 36 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
37 | 37 | ||
38 | 38 | ||
39 | cgit: cgit.c $(OBJECTS) | 39 | cgit: cgit.c $(OBJECTS) |
40 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 40 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) |
41 | 41 | ||
42 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 42 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION |
43 | 43 | ||
44 | git/xdiff/lib.a: | git | 44 | git/xdiff/lib.a: | git |
45 | 45 | ||
46 | git/libgit.a: | git | 46 | git/libgit.a: | git |
47 | 47 | ||
48 | git: | 48 | git: |
49 | cd git && $(MAKE) xdiff/lib.a | 49 | cd git && $(MAKE) xdiff/lib.a |
50 | cd git && $(MAKE) libgit.a | 50 | cd git && $(MAKE) libgit.a |
51 | 51 | ||
52 | install: all | 52 | install: all |
53 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 53 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
54 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 54 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
55 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css | 55 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css |
56 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* | 56 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* |
57 | 57 | ||
58 | uninstall: | 58 | uninstall: |
59 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 59 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
60 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css | 60 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css |
61 | rm -rf $(CACHE_ROOT) | 61 | rm -rf $(CACHE_ROOT) |
62 | 62 | ||
63 | clean: | 63 | clean: |
64 | rm -f cgit VERSION *.o | 64 | rm -f cgit VERSION *.o |
65 | cd git && $(MAKE) clean | 65 | cd git && $(MAKE) clean |
66 | 66 | ||
67 | distclean: clean | 67 | distclean: clean |
68 | git clean -d -x | 68 | git clean -d -x |
69 | cd git && git clean -d -x | 69 | cd git && git clean -d -x |
70 | 70 | ||
71 | get-git: | 71 | get-git: |
72 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git | 72 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git |
@@ -42,128 +42,131 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
42 | else | 42 | else |
43 | item->ttl = cgit_cache_repo_ttl; | 43 | item->ttl = cgit_cache_repo_ttl; |
44 | } | 44 | } |
45 | return 1; | 45 | return 1; |
46 | } | 46 | } |
47 | 47 | ||
48 | static void cgit_print_repo_page(struct cacheitem *item) | 48 | static void cgit_print_repo_page(struct cacheitem *item) |
49 | { | 49 | { |
50 | char *title; | 50 | char *title; |
51 | int show_search; | 51 | int show_search; |
52 | 52 | ||
53 | if (!cgit_query_head) | 53 | if (!cgit_query_head) |
54 | cgit_query_head = cgit_repo->defbranch; | 54 | cgit_query_head = cgit_repo->defbranch; |
55 | 55 | ||
56 | if (chdir(cgit_repo->path)) { | 56 | if (chdir(cgit_repo->path)) { |
57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
58 | cgit_print_docstart(title, item); | 58 | cgit_print_docstart(title, item); |
59 | cgit_print_pageheader(title, 0); | 59 | cgit_print_pageheader(title, 0); |
60 | cgit_print_error(fmt("Unable to scan repository: %s", | 60 | cgit_print_error(fmt("Unable to scan repository: %s", |
61 | strerror(errno))); | 61 | strerror(errno))); |
62 | cgit_print_docend(); | 62 | cgit_print_docend(); |
63 | return; | 63 | return; |
64 | } | 64 | } |
65 | 65 | ||
66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
67 | show_search = 0; | 67 | show_search = 0; |
68 | setenv("GIT_DIR", cgit_repo->path, 1); | 68 | setenv("GIT_DIR", cgit_repo->path, 1); |
69 | 69 | ||
70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, | 71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 72 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_path, | 73 | cgit_query_path, |
74 | cgit_repo->snapshots ); | 74 | cgit_repo->snapshots ); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (cgit_cmd == CMD_BLOB) { | 78 | if (cgit_cmd == CMD_BLOB) { |
79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | 82 | ||
83 | show_search = (cgit_cmd == CMD_LOG); | 83 | show_search = (cgit_cmd == CMD_LOG); |
84 | cgit_print_docstart(title, item); | 84 | cgit_print_docstart(title, item); |
85 | if (!cgit_cmd) { | 85 | if (!cgit_cmd) { |
86 | cgit_print_pageheader("summary", show_search); | 86 | cgit_print_pageheader("summary", show_search); |
87 | cgit_print_summary(); | 87 | cgit_print_summary(); |
88 | cgit_print_docend(); | 88 | cgit_print_docend(); |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | 91 | ||
92 | cgit_print_pageheader(cgit_query_page, show_search); | 92 | cgit_print_pageheader(cgit_query_page, show_search); |
93 | 93 | ||
94 | switch(cgit_cmd) { | 94 | switch(cgit_cmd) { |
95 | case CMD_LOG: | 95 | case CMD_LOG: |
96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
97 | cgit_max_commit_count, cgit_query_search, | 97 | cgit_max_commit_count, cgit_query_search, |
98 | cgit_query_path, 1); | 98 | cgit_query_path, 1); |
99 | break; | 99 | break; |
100 | case CMD_TREE: | 100 | case CMD_TREE: |
101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
102 | break; | 102 | break; |
103 | case CMD_COMMIT: | 103 | case CMD_COMMIT: |
104 | cgit_print_commit(cgit_query_sha1); | 104 | cgit_print_commit(cgit_query_sha1); |
105 | break; | 105 | break; |
106 | case CMD_REFS: | ||
107 | cgit_print_refs(); | ||
108 | break; | ||
106 | case CMD_TAG: | 109 | case CMD_TAG: |
107 | cgit_print_tag(cgit_query_sha1); | 110 | cgit_print_tag(cgit_query_sha1); |
108 | break; | 111 | break; |
109 | case CMD_DIFF: | 112 | case CMD_DIFF: |
110 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); | 113 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
111 | break; | 114 | break; |
112 | default: | 115 | default: |
113 | cgit_print_error("Invalid request"); | 116 | cgit_print_error("Invalid request"); |
114 | } | 117 | } |
115 | cgit_print_docend(); | 118 | cgit_print_docend(); |
116 | } | 119 | } |
117 | 120 | ||
118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 121 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
119 | { | 122 | { |
120 | static char buf[PATH_MAX]; | 123 | static char buf[PATH_MAX]; |
121 | int stdout2; | 124 | int stdout2; |
122 | 125 | ||
123 | getcwd(buf, sizeof(buf)); | 126 | getcwd(buf, sizeof(buf)); |
124 | item->st.st_mtime = time(NULL); | 127 | item->st.st_mtime = time(NULL); |
125 | 128 | ||
126 | if (use_cache) { | 129 | if (use_cache) { |
127 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 130 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
128 | "Preserving STDOUT"); | 131 | "Preserving STDOUT"); |
129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 132 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 133 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
131 | } | 134 | } |
132 | 135 | ||
133 | if (cgit_repo) | 136 | if (cgit_repo) |
134 | cgit_print_repo_page(item); | 137 | cgit_print_repo_page(item); |
135 | else | 138 | else |
136 | cgit_print_repolist(item); | 139 | cgit_print_repolist(item); |
137 | 140 | ||
138 | if (use_cache) { | 141 | if (use_cache) { |
139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 142 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
140 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 143 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
141 | "Restoring original STDOUT"); | 144 | "Restoring original STDOUT"); |
142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 145 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
143 | } | 146 | } |
144 | 147 | ||
145 | chdir(buf); | 148 | chdir(buf); |
146 | } | 149 | } |
147 | 150 | ||
148 | static void cgit_check_cache(struct cacheitem *item) | 151 | static void cgit_check_cache(struct cacheitem *item) |
149 | { | 152 | { |
150 | int i = 0; | 153 | int i = 0; |
151 | 154 | ||
152 | top: | 155 | top: |
153 | if (++i > cgit_max_lock_attempts) { | 156 | if (++i > cgit_max_lock_attempts) { |
154 | die("cgit_refresh_cache: unable to lock %s: %s", | 157 | die("cgit_refresh_cache: unable to lock %s: %s", |
155 | item->name, strerror(errno)); | 158 | item->name, strerror(errno)); |
156 | } | 159 | } |
157 | if (!cache_exist(item)) { | 160 | if (!cache_exist(item)) { |
158 | if (!cache_lock(item)) { | 161 | if (!cache_lock(item)) { |
159 | sleep(1); | 162 | sleep(1); |
160 | goto top; | 163 | goto top; |
161 | } | 164 | } |
162 | if (!cache_exist(item)) { | 165 | if (!cache_exist(item)) { |
163 | cgit_fill_cache(item, 1); | 166 | cgit_fill_cache(item, 1); |
164 | cache_unlock(item); | 167 | cache_unlock(item); |
165 | } else { | 168 | } else { |
166 | cache_cancel_lock(item); | 169 | cache_cancel_lock(item); |
167 | } | 170 | } |
168 | } else if (cache_expired(item) && cache_lock(item)) { | 171 | } else if (cache_expired(item) && cache_lock(item)) { |
169 | if (cache_expired(item)) { | 172 | if (cache_expired(item)) { |
@@ -1,94 +1,95 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | 4 | ||
5 | #include <git-compat-util.h> | 5 | #include <git-compat-util.h> |
6 | #include <cache.h> | 6 | #include <cache.h> |
7 | #include <grep.h> | 7 | #include <grep.h> |
8 | #include <object.h> | 8 | #include <object.h> |
9 | #include <tree.h> | 9 | #include <tree.h> |
10 | #include <commit.h> | 10 | #include <commit.h> |
11 | #include <tag.h> | 11 | #include <tag.h> |
12 | #include <diff.h> | 12 | #include <diff.h> |
13 | #include <diffcore.h> | 13 | #include <diffcore.h> |
14 | #include <refs.h> | 14 | #include <refs.h> |
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> | 18 | #include <xdiff/xdiff.h> |
19 | 19 | ||
20 | 20 | ||
21 | /* | 21 | /* |
22 | * The valid cgit repo-commands | 22 | * The valid cgit repo-commands |
23 | */ | 23 | */ |
24 | #define CMD_LOG 1 | 24 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT 2 | 25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 | 26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 | 27 | #define CMD_TREE 4 |
28 | #define CMD_BLOB 5 | 28 | #define CMD_BLOB 5 |
29 | #define CMD_SNAPSHOT 6 | 29 | #define CMD_SNAPSHOT 6 |
30 | #define CMD_TAG 7 | 30 | #define CMD_TAG 7 |
31 | #define CMD_REFS 8 | ||
31 | 32 | ||
32 | /* | 33 | /* |
33 | * Dateformats used on misc. pages | 34 | * Dateformats used on misc. pages |
34 | */ | 35 | */ |
35 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 36 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
36 | #define FMT_SHORTDATE "%Y-%m-%d" | 37 | #define FMT_SHORTDATE "%Y-%m-%d" |
37 | 38 | ||
38 | 39 | ||
39 | /* | 40 | /* |
40 | * Limits used for relative dates | 41 | * Limits used for relative dates |
41 | */ | 42 | */ |
42 | #define TM_MIN 60 | 43 | #define TM_MIN 60 |
43 | #define TM_HOUR (TM_MIN * 60) | 44 | #define TM_HOUR (TM_MIN * 60) |
44 | #define TM_DAY (TM_HOUR * 24) | 45 | #define TM_DAY (TM_HOUR * 24) |
45 | #define TM_WEEK (TM_DAY * 7) | 46 | #define TM_WEEK (TM_DAY * 7) |
46 | #define TM_YEAR (TM_DAY * 365) | 47 | #define TM_YEAR (TM_DAY * 365) |
47 | #define TM_MONTH (TM_YEAR / 12.0) | 48 | #define TM_MONTH (TM_YEAR / 12.0) |
48 | 49 | ||
49 | 50 | ||
50 | typedef void (*configfn)(const char *name, const char *value); | 51 | typedef void (*configfn)(const char *name, const char *value); |
51 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 52 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
52 | typedef void (*linediff_fn)(char *line, int len); | 53 | typedef void (*linediff_fn)(char *line, int len); |
53 | 54 | ||
54 | struct cacheitem { | 55 | struct cacheitem { |
55 | char *name; | 56 | char *name; |
56 | struct stat st; | 57 | struct stat st; |
57 | int ttl; | 58 | int ttl; |
58 | int fd; | 59 | int fd; |
59 | }; | 60 | }; |
60 | 61 | ||
61 | struct repoinfo { | 62 | struct repoinfo { |
62 | char *url; | 63 | char *url; |
63 | char *name; | 64 | char *name; |
64 | char *path; | 65 | char *path; |
65 | char *desc; | 66 | char *desc; |
66 | char *owner; | 67 | char *owner; |
67 | char *defbranch; | 68 | char *defbranch; |
68 | char *group; | 69 | char *group; |
69 | char *module_link; | 70 | char *module_link; |
70 | char *readme; | 71 | char *readme; |
71 | int snapshots; | 72 | int snapshots; |
72 | int enable_log_filecount; | 73 | int enable_log_filecount; |
73 | int enable_log_linecount; | 74 | int enable_log_linecount; |
74 | }; | 75 | }; |
75 | 76 | ||
76 | struct repolist { | 77 | struct repolist { |
77 | int length; | 78 | int length; |
78 | int count; | 79 | int count; |
79 | struct repoinfo *repos; | 80 | struct repoinfo *repos; |
80 | }; | 81 | }; |
81 | 82 | ||
82 | struct commitinfo { | 83 | struct commitinfo { |
83 | struct commit *commit; | 84 | struct commit *commit; |
84 | char *author; | 85 | char *author; |
85 | char *author_email; | 86 | char *author_email; |
86 | unsigned long author_date; | 87 | unsigned long author_date; |
87 | char *committer; | 88 | char *committer; |
88 | char *committer_email; | 89 | char *committer_email; |
89 | unsigned long committer_date; | 90 | unsigned long committer_date; |
90 | char *subject; | 91 | char *subject; |
91 | char *msg; | 92 | char *msg; |
92 | }; | 93 | }; |
93 | 94 | ||
94 | struct taginfo { | 95 | struct taginfo { |
@@ -199,74 +200,75 @@ extern char *fmt(const char *format,...); | |||
199 | 200 | ||
200 | extern void html(const char *txt); | 201 | extern void html(const char *txt); |
201 | extern void htmlf(const char *format,...); | 202 | extern void htmlf(const char *format,...); |
202 | extern void html_txt(char *txt); | 203 | extern void html_txt(char *txt); |
203 | extern void html_ntxt(int len, char *txt); | 204 | extern void html_ntxt(int len, char *txt); |
204 | extern void html_attr(char *txt); | 205 | extern void html_attr(char *txt); |
205 | extern void html_hidden(char *name, char *value); | 206 | extern void html_hidden(char *name, char *value); |
206 | extern void html_link_open(char *url, char *title, char *class); | 207 | extern void html_link_open(char *url, char *title, char *class); |
207 | extern void html_link_close(void); | 208 | extern void html_link_close(void); |
208 | extern void html_filemode(unsigned short mode); | 209 | extern void html_filemode(unsigned short mode); |
209 | extern int html_include(const char *filename); | 210 | extern int html_include(const char *filename); |
210 | 211 | ||
211 | extern int cgit_read_config(const char *filename, configfn fn); | 212 | extern int cgit_read_config(const char *filename, configfn fn); |
212 | extern int cgit_parse_query(char *txt, configfn fn); | 213 | extern int cgit_parse_query(char *txt, configfn fn); |
213 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
214 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
215 | extern void cgit_parse_url(const char *url); | 216 | extern void cgit_parse_url(const char *url); |
216 | 217 | ||
217 | extern char *cache_safe_filename(const char *unsafe); | 218 | extern char *cache_safe_filename(const char *unsafe); |
218 | extern int cache_lock(struct cacheitem *item); | 219 | extern int cache_lock(struct cacheitem *item); |
219 | extern int cache_unlock(struct cacheitem *item); | 220 | extern int cache_unlock(struct cacheitem *item); |
220 | extern int cache_cancel_lock(struct cacheitem *item); | 221 | extern int cache_cancel_lock(struct cacheitem *item); |
221 | extern int cache_exist(struct cacheitem *item); | 222 | extern int cache_exist(struct cacheitem *item); |
222 | extern int cache_expired(struct cacheitem *item); | 223 | extern int cache_expired(struct cacheitem *item); |
223 | 224 | ||
224 | extern char *cgit_repourl(const char *reponame); | 225 | extern char *cgit_repourl(const char *reponame); |
225 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
226 | const char *filename, const char *query); | 227 | const char *filename, const char *query); |
227 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
228 | const char *query); | 229 | const char *query); |
229 | 230 | ||
230 | extern const char *cgit_repobasename(const char *reponame); | 231 | extern const char *cgit_repobasename(const char *reponame); |
231 | 232 | ||
232 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 233 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
233 | char *rev, char *path); | 234 | char *rev, char *path); |
234 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 235 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
235 | char *rev, char *path, int ofs); | 236 | char *rev, char *path, int ofs); |
236 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 237 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
237 | char *rev); | 238 | char *rev); |
238 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 239 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
239 | char *head, char *rev, char *archivename); | 240 | char *head, char *rev, char *archivename); |
240 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 241 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
241 | char *new_rev, char *old_rev, char *path); | 242 | char *new_rev, char *old_rev, char *path); |
242 | 243 | ||
243 | extern void cgit_object_link(struct object *obj); | 244 | extern void cgit_object_link(struct object *obj); |
244 | 245 | ||
245 | extern void cgit_print_error(char *msg); | 246 | extern void cgit_print_error(char *msg); |
246 | extern void cgit_print_date(time_t secs, char *format); | 247 | extern void cgit_print_date(time_t secs, char *format); |
247 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 248 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
248 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 249 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
249 | extern void cgit_print_docend(); | 250 | extern void cgit_print_docend(); |
250 | extern void cgit_print_pageheader(char *title, int show_search); | 251 | extern void cgit_print_pageheader(char *title, int show_search); |
251 | extern void cgit_print_snapshot_start(const char *mimetype, | 252 | extern void cgit_print_snapshot_start(const char *mimetype, |
252 | const char *filename, | 253 | const char *filename, |
253 | struct cacheitem *item); | 254 | struct cacheitem *item); |
254 | extern void cgit_print_branches(int maxcount); | 255 | extern void cgit_print_branches(int maxcount); |
255 | extern void cgit_print_tags(int maxcount); | 256 | extern void cgit_print_tags(int maxcount); |
256 | 257 | ||
257 | extern void cgit_print_repolist(struct cacheitem *item); | 258 | extern void cgit_print_repolist(struct cacheitem *item); |
258 | extern void cgit_print_summary(); | 259 | extern void cgit_print_summary(); |
259 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 260 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
260 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 261 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
261 | extern void cgit_print_tree(const char *rev, char *path); | 262 | extern void cgit_print_tree(const char *rev, char *path); |
262 | extern void cgit_print_commit(char *hex); | 263 | extern void cgit_print_commit(char *hex); |
264 | extern void cgit_print_refs(); | ||
263 | extern void cgit_print_tag(char *revname); | 265 | extern void cgit_print_tag(char *revname); |
264 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | 266 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
265 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 267 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
266 | const char *hex, const char *prefix, | 268 | const char *hex, const char *prefix, |
267 | const char *filename, int snapshot); | 269 | const char *filename, int snapshot); |
268 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 270 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
269 | const char *hex, int snapshots); | 271 | const char *hex, int snapshots); |
270 | extern int cgit_parse_snapshots_mask(const char *str); | 272 | extern int cgit_parse_snapshots_mask(const char *str); |
271 | 273 | ||
272 | #endif /* CGIT_H */ | 274 | #endif /* CGIT_H */ |
@@ -5,129 +5,129 @@ | |||
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | struct repolist cgit_repolist; | 11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | 12 | struct repoinfo *cgit_repo; |
13 | int cgit_cmd; | 13 | int cgit_cmd; |
14 | 14 | ||
15 | const char *cgit_version = CGIT_VERSION; | 15 | const char *cgit_version = CGIT_VERSION; |
16 | 16 | ||
17 | char *cgit_root_title = "Git repository browser"; | 17 | char *cgit_root_title = "Git repository browser"; |
18 | char *cgit_css = "/cgit.css"; | 18 | char *cgit_css = "/cgit.css"; |
19 | char *cgit_logo = "/git-logo.png"; | 19 | char *cgit_logo = "/git-logo.png"; |
20 | char *cgit_index_header = NULL; | 20 | char *cgit_index_header = NULL; |
21 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 21 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
22 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | 22 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
23 | char *cgit_agefile = "info/web/last-modified"; | 23 | char *cgit_agefile = "info/web/last-modified"; |
24 | char *cgit_virtual_root = NULL; | 24 | char *cgit_virtual_root = NULL; |
25 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 25 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
26 | char *cgit_cache_root = CGIT_CACHE_ROOT; | 26 | char *cgit_cache_root = CGIT_CACHE_ROOT; |
27 | char *cgit_repo_group = NULL; | 27 | char *cgit_repo_group = NULL; |
28 | 28 | ||
29 | int cgit_nocache = 0; | 29 | int cgit_nocache = 0; |
30 | int cgit_snapshots = 0; | 30 | int cgit_snapshots = 0; |
31 | int cgit_enable_index_links = 0; | 31 | int cgit_enable_index_links = 0; |
32 | int cgit_enable_log_filecount = 0; | 32 | int cgit_enable_log_filecount = 0; |
33 | int cgit_enable_log_linecount = 0; | 33 | int cgit_enable_log_linecount = 0; |
34 | int cgit_max_lock_attempts = 5; | 34 | int cgit_max_lock_attempts = 5; |
35 | int cgit_cache_root_ttl = 5; | 35 | int cgit_cache_root_ttl = 5; |
36 | int cgit_cache_repo_ttl = 5; | 36 | int cgit_cache_repo_ttl = 5; |
37 | int cgit_cache_dynamic_ttl = 5; | 37 | int cgit_cache_dynamic_ttl = 5; |
38 | int cgit_cache_static_ttl = -1; | 38 | int cgit_cache_static_ttl = -1; |
39 | int cgit_cache_max_create_time = 5; | 39 | int cgit_cache_max_create_time = 5; |
40 | int cgit_summary_log = 0; | 40 | int cgit_summary_log = 0; |
41 | int cgit_summary_tags = 0; | 41 | int cgit_summary_tags = 0; |
42 | int cgit_summary_branches = 0; | 42 | int cgit_summary_branches = 0; |
43 | int cgit_renamelimit = -1; | 43 | int cgit_renamelimit = -1; |
44 | 44 | ||
45 | int cgit_max_msg_len = 60; | 45 | int cgit_max_msg_len = 60; |
46 | int cgit_max_repodesc_len = 60; | 46 | int cgit_max_repodesc_len = 60; |
47 | int cgit_max_commit_count = 50; | 47 | int cgit_max_commit_count = 50; |
48 | 48 | ||
49 | int cgit_query_has_symref = 0; | 49 | int cgit_query_has_symref = 0; |
50 | int cgit_query_has_sha1 = 0; | 50 | int cgit_query_has_sha1 = 0; |
51 | 51 | ||
52 | char *cgit_querystring = NULL; | 52 | char *cgit_querystring = NULL; |
53 | char *cgit_query_repo = NULL; | 53 | char *cgit_query_repo = NULL; |
54 | char *cgit_query_page = NULL; | 54 | char *cgit_query_page = NULL; |
55 | char *cgit_query_head = NULL; | 55 | char *cgit_query_head = NULL; |
56 | char *cgit_query_search = NULL; | 56 | char *cgit_query_search = NULL; |
57 | char *cgit_query_sha1 = NULL; | 57 | char *cgit_query_sha1 = NULL; |
58 | char *cgit_query_sha2 = NULL; | 58 | char *cgit_query_sha2 = NULL; |
59 | char *cgit_query_path = NULL; | 59 | char *cgit_query_path = NULL; |
60 | char *cgit_query_name = NULL; | 60 | char *cgit_query_name = NULL; |
61 | int cgit_query_ofs = 0; | 61 | int cgit_query_ofs = 0; |
62 | 62 | ||
63 | int htmlfd = 0; | 63 | int htmlfd = 0; |
64 | 64 | ||
65 | 65 | ||
66 | int cgit_get_cmd_index(const char *cmd) | 66 | int cgit_get_cmd_index(const char *cmd) |
67 | { | 67 | { |
68 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 68 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
69 | "snapshot", "tag", NULL}; | 69 | "snapshot", "tag", "refs", NULL}; |
70 | int i; | 70 | int i; |
71 | 71 | ||
72 | for(i = 0; cmds[i]; i++) | 72 | for(i = 0; cmds[i]; i++) |
73 | if (!strcmp(cmd, cmds[i])) | 73 | if (!strcmp(cmd, cmds[i])) |
74 | return i + 1; | 74 | return i + 1; |
75 | return 0; | 75 | return 0; |
76 | } | 76 | } |
77 | 77 | ||
78 | int chk_zero(int result, char *msg) | 78 | int chk_zero(int result, char *msg) |
79 | { | 79 | { |
80 | if (result != 0) | 80 | if (result != 0) |
81 | die("%s: %s", msg, strerror(errno)); | 81 | die("%s: %s", msg, strerror(errno)); |
82 | return result; | 82 | return result; |
83 | } | 83 | } |
84 | 84 | ||
85 | int chk_positive(int result, char *msg) | 85 | int chk_positive(int result, char *msg) |
86 | { | 86 | { |
87 | if (result <= 0) | 87 | if (result <= 0) |
88 | die("%s: %s", msg, strerror(errno)); | 88 | die("%s: %s", msg, strerror(errno)); |
89 | return result; | 89 | return result; |
90 | } | 90 | } |
91 | 91 | ||
92 | int chk_non_negative(int result, char *msg) | 92 | int chk_non_negative(int result, char *msg) |
93 | { | 93 | { |
94 | if (result < 0) | 94 | if (result < 0) |
95 | die("%s: %s",msg, strerror(errno)); | 95 | die("%s: %s",msg, strerror(errno)); |
96 | return result; | 96 | return result; |
97 | } | 97 | } |
98 | 98 | ||
99 | struct repoinfo *add_repo(const char *url) | 99 | struct repoinfo *add_repo(const char *url) |
100 | { | 100 | { |
101 | struct repoinfo *ret; | 101 | struct repoinfo *ret; |
102 | 102 | ||
103 | if (++cgit_repolist.count > cgit_repolist.length) { | 103 | if (++cgit_repolist.count > cgit_repolist.length) { |
104 | if (cgit_repolist.length == 0) | 104 | if (cgit_repolist.length == 0) |
105 | cgit_repolist.length = 8; | 105 | cgit_repolist.length = 8; |
106 | else | 106 | else |
107 | cgit_repolist.length *= 2; | 107 | cgit_repolist.length *= 2; |
108 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 108 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
109 | cgit_repolist.length * | 109 | cgit_repolist.length * |
110 | sizeof(struct repoinfo)); | 110 | sizeof(struct repoinfo)); |
111 | } | 111 | } |
112 | 112 | ||
113 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 113 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
114 | ret->url = trim_end(url, '/'); | 114 | ret->url = trim_end(url, '/'); |
115 | ret->name = ret->url; | 115 | ret->name = ret->url; |
116 | ret->path = NULL; | 116 | ret->path = NULL; |
117 | ret->desc = NULL; | 117 | ret->desc = NULL; |
118 | ret->owner = NULL; | 118 | ret->owner = NULL; |
119 | ret->group = cgit_repo_group; | 119 | ret->group = cgit_repo_group; |
120 | ret->defbranch = "master"; | 120 | ret->defbranch = "master"; |
121 | ret->snapshots = cgit_snapshots; | 121 | ret->snapshots = cgit_snapshots; |
122 | ret->enable_log_filecount = cgit_enable_log_filecount; | 122 | ret->enable_log_filecount = cgit_enable_log_filecount; |
123 | ret->enable_log_linecount = cgit_enable_log_linecount; | 123 | ret->enable_log_linecount = cgit_enable_log_linecount; |
124 | ret->module_link = cgit_module_link; | 124 | ret->module_link = cgit_module_link; |
125 | ret->readme = NULL; | 125 | ret->readme = NULL; |
126 | return ret; | 126 | return ret; |
127 | } | 127 | } |
128 | 128 | ||
129 | struct repoinfo *cgit_get_repoinfo(const char *url) | 129 | struct repoinfo *cgit_get_repoinfo(const char *url) |
130 | { | 130 | { |
131 | int i; | 131 | int i; |
132 | struct repoinfo *repo; | 132 | struct repoinfo *repo; |
133 | 133 | ||
diff --git a/ui-refs.c b/ui-refs.c new file mode 100644 index 0000000..295f5ba --- a/dev/null +++ b/ui-refs.c | |||
@@ -0,0 +1,30 @@ | |||
1 | /* ui-refs.c: browse symbolic refs | ||
2 | * | ||
3 | * Copyright (C) 2006 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 | |||
11 | |||
12 | |||
13 | |||
14 | void cgit_print_refs() | ||
15 | { | ||
16 | |||
17 | html("<table class='list nowrap'>"); | ||
18 | |||
19 | if (cgit_query_path && !strncmp(cgit_query_path, "heads", 5)) | ||
20 | cgit_print_branches(0); | ||
21 | else if (cgit_query_path && !strncmp(cgit_query_path, "tags", 4)) | ||
22 | cgit_print_tags(0); | ||
23 | else { | ||
24 | cgit_print_branches(0); | ||
25 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | ||
26 | cgit_print_tags(0); | ||
27 | } | ||
28 | |||
29 | html("</table>"); | ||
30 | } | ||