author | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:36:53 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:53:27 (UTC) |
commit | 7937d06090dd5e19145ec6fa8befc5770954b30c (patch) (unidiff) | |
tree | bb058aa0b5e54aabcad6a2ca6416bcac4b636615 | |
parent | 8efb05f98ad389d1b7f5aac17838401908622dad (diff) | |
download | cgit-7937d06090dd5e19145ec6fa8befc5770954b30c.zip cgit-7937d06090dd5e19145ec6fa8befc5770954b30c.tar.gz cgit-7937d06090dd5e19145ec6fa8befc5770954b30c.tar.bz2 |
Add support for refs view
This enables the new urls $repo/refs, $repo/refs/heads and $repo/refs/tags,
which can be used to print _all_ branches and/or tags.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-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,43 +1,43 @@ | |||
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 | ||
@@ -82,48 +82,51 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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"); |
@@ -7,48 +7,49 @@ | |||
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 { |
@@ -239,34 +240,35 @@ 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 */ |
@@ -45,49 +45,49 @@ int cgit_renamelimit = -1; | |||
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 | { |
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 | } | ||