summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-10-27 08:36:53 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-27 08:53:27 (UTC)
commit7937d06090dd5e19145ec6fa8befc5770954b30c (patch) (unidiff)
treebb058aa0b5e54aabcad6a2ca6416bcac4b636615
parent8efb05f98ad389d1b7f5aac17838401908622dad (diff)
downloadcgit-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile2
-rw-r--r--cgit.c3
-rw-r--r--cgit.h2
-rw-r--r--shared.c2
-rw-r--r--ui-refs.c30
5 files changed, 37 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 8e3da72..36b5ff6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,43 +1,43 @@
1CGIT_VERSION = v0.6.3 1CGIT_VERSION = v0.6.3
2CGIT_SCRIPT_NAME = cgit.cgi 2CGIT_SCRIPT_NAME = cgit.cgi
3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit 3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
4CGIT_CONFIG = /etc/cgitrc 4CGIT_CONFIG = /etc/cgitrc
5CACHE_ROOT = /var/cache/cgit 5CACHE_ROOT = /var/cache/cgit
6SHA1_HEADER = <openssl/sha.h> 6SHA1_HEADER = <openssl/sha.h>
7GIT_VER = 1.5.3.3 7GIT_VER = 1.5.3.3
8GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 8GIT_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
16EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto 16EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
17OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ 17OBJECTS = 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
24all: cgit git 24all: cgit git
25 25
26VERSION: force-version 26VERSION: force-version
27 @./gen-version.sh "$(CGIT_VERSION)" 27 @./gen-version.sh "$(CGIT_VERSION)"
28-include VERSION 28-include VERSION
29 29
30 30
31CFLAGS += -g -Wall -Igit 31CFLAGS += -g -Wall -Igit
32CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 32CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
33CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' 33CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
34CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' 34CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
35CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' 35CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
36CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' 36CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
37 37
38 38
39cgit: cgit.c $(OBJECTS) 39cgit: 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
diff --git a/cgit.c b/cgit.c
index 1b85b15..cc18ed4 100644
--- a/cgit.c
+++ b/cgit.c
@@ -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
118static void cgit_fill_cache(struct cacheitem *item, int use_cache) 121static 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");
diff --git a/cgit.h b/cgit.h
index a1fe527..d9a15f4 100644
--- a/cgit.h
+++ b/cgit.h
@@ -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
50typedef void (*configfn)(const char *name, const char *value); 51typedef void (*configfn)(const char *name, const char *value);
51typedef void (*filepair_fn)(struct diff_filepair *pair); 52typedef void (*filepair_fn)(struct diff_filepair *pair);
52typedef void (*linediff_fn)(char *line, int len); 53typedef void (*linediff_fn)(char *line, int len);
53 54
54struct cacheitem { 55struct 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);
240extern void cgit_diff_link(char *name, char *title, char *class, char *head, 241extern 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
243extern void cgit_object_link(struct object *obj); 244extern void cgit_object_link(struct object *obj);
244 245
245extern void cgit_print_error(char *msg); 246extern void cgit_print_error(char *msg);
246extern void cgit_print_date(time_t secs, char *format); 247extern void cgit_print_date(time_t secs, char *format);
247extern void cgit_print_age(time_t t, time_t max_relative, char *format); 248extern void cgit_print_age(time_t t, time_t max_relative, char *format);
248extern void cgit_print_docstart(char *title, struct cacheitem *item); 249extern void cgit_print_docstart(char *title, struct cacheitem *item);
249extern void cgit_print_docend(); 250extern void cgit_print_docend();
250extern void cgit_print_pageheader(char *title, int show_search); 251extern void cgit_print_pageheader(char *title, int show_search);
251extern void cgit_print_snapshot_start(const char *mimetype, 252extern void cgit_print_snapshot_start(const char *mimetype,
252 const char *filename, 253 const char *filename,
253 struct cacheitem *item); 254 struct cacheitem *item);
254extern void cgit_print_branches(int maxcount); 255extern void cgit_print_branches(int maxcount);
255extern void cgit_print_tags(int maxcount); 256extern void cgit_print_tags(int maxcount);
256 257
257extern void cgit_print_repolist(struct cacheitem *item); 258extern void cgit_print_repolist(struct cacheitem *item);
258extern void cgit_print_summary(); 259extern void cgit_print_summary();
259extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); 260extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
260extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 261extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
261extern void cgit_print_tree(const char *rev, char *path); 262extern void cgit_print_tree(const char *rev, char *path);
262extern void cgit_print_commit(char *hex); 263extern void cgit_print_commit(char *hex);
264extern void cgit_print_refs();
263extern void cgit_print_tag(char *revname); 265extern void cgit_print_tag(char *revname);
264extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); 266extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix);
265extern void cgit_print_snapshot(struct cacheitem *item, const char *head, 267extern 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);
268extern void cgit_print_snapshot_links(const char *repo, const char *head, 270extern void cgit_print_snapshot_links(const char *repo, const char *head,
269 const char *hex, int snapshots); 271 const char *hex, int snapshots);
270extern int cgit_parse_snapshots_mask(const char *str); 272extern int cgit_parse_snapshots_mask(const char *str);
271 273
272#endif /* CGIT_H */ 274#endif /* CGIT_H */
diff --git a/shared.c b/shared.c
index ff600db..7eb2b0e 100644
--- a/shared.c
+++ b/shared.c
@@ -45,49 +45,49 @@ int cgit_renamelimit = -1;
45int cgit_max_msg_len = 60; 45int cgit_max_msg_len = 60;
46int cgit_max_repodesc_len = 60; 46int cgit_max_repodesc_len = 60;
47int cgit_max_commit_count = 50; 47int cgit_max_commit_count = 50;
48 48
49int cgit_query_has_symref = 0; 49int cgit_query_has_symref = 0;
50int cgit_query_has_sha1 = 0; 50int cgit_query_has_sha1 = 0;
51 51
52char *cgit_querystring = NULL; 52char *cgit_querystring = NULL;
53char *cgit_query_repo = NULL; 53char *cgit_query_repo = NULL;
54char *cgit_query_page = NULL; 54char *cgit_query_page = NULL;
55char *cgit_query_head = NULL; 55char *cgit_query_head = NULL;
56char *cgit_query_search = NULL; 56char *cgit_query_search = NULL;
57char *cgit_query_sha1 = NULL; 57char *cgit_query_sha1 = NULL;
58char *cgit_query_sha2 = NULL; 58char *cgit_query_sha2 = NULL;
59char *cgit_query_path = NULL; 59char *cgit_query_path = NULL;
60char *cgit_query_name = NULL; 60char *cgit_query_name = NULL;
61int cgit_query_ofs = 0; 61int cgit_query_ofs = 0;
62 62
63int htmlfd = 0; 63int htmlfd = 0;
64 64
65 65
66int cgit_get_cmd_index(const char *cmd) 66int 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
78int chk_zero(int result, char *msg) 78int 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
85int chk_positive(int result, char *msg) 85int 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
92int chk_non_negative(int result, char *msg) 92int 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
14void 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'>&nbsp;</td></tr>");
26 cgit_print_tags(0);
27 }
28
29 html("</table>");
30}