aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--cgit.c67
-rw-r--r--cgit.css64
-rw-r--r--cgit.h12
-rw-r--r--cgit.pngbin3790 -> 5406 bytes
-rw-r--r--cgitrc12
m---------git0
-rw-r--r--html.c2
-rw-r--r--parsing.c25
-rw-r--r--shared.c14
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile13
-rwxr-xr-xtests/setup.sh108
-rwxr-xr-xtests/t0010-validate-html.sh31
-rwxr-xr-xtests/t0101-index.sh13
-rwxr-xr-xtests/t0102-summary.sh20
-rwxr-xr-xtests/t0103-log.sh15
-rwxr-xr-xtests/t0104-tree.sh21
-rwxr-xr-xtests/t0105-commit.sh22
-rwxr-xr-xtests/t0106-diff.sh20
-rwxr-xr-xtests/t0107-snapshot.sh36
-rw-r--r--ui-commit.c6
-rw-r--r--ui-diff.c2
-rw-r--r--ui-log.c23
-rw-r--r--ui-patch.c110
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c67
-rw-r--r--ui-summary.c2
-rw-r--r--ui-tree.c6
29 files changed, 653 insertions, 76 deletions
diff --git a/Makefile b/Makefile
index 68d617e..7102908 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CGIT_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.8 7GIT_VER = 1.5.4.1
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#
@@ -16,10 +16,15 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
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 ui-refs.o 19 ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o
20 20
21 21
22.PHONY: all git install clean distclean emptycache force-version get-git 22ifdef NEEDS_LIBICONV
23 EXTLIBS += -liconv
24endif
25
26
27.PHONY: all git test install clean distclean emptycache force-version get-git
23 28
24all: cgit git 29all: cgit git
25 30
@@ -49,6 +54,9 @@ git:
49 cd git && $(MAKE) xdiff/lib.a 54 cd git && $(MAKE) xdiff/lib.a
50 cd git && $(MAKE) libgit.a 55 cd git && $(MAKE) libgit.a
51 56
57test: all
58 $(MAKE) -C tests
59
52install: all 60install: all
53 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) 61 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
54 install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 62 install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
diff --git a/cgit.c b/cgit.c
index 142e416..e8acc03 100644
--- a/cgit.c
+++ b/cgit.c
@@ -45,13 +45,44 @@ static int cgit_prepare_cache(struct cacheitem *item)
45 return 1; 45 return 1;
46} 46}
47 47
48struct refmatch {
49 char *req_ref;
50 char *first_ref;
51 int match;
52};
53
54int find_current_ref(const char *refname, const unsigned char *sha1,
55 int flags, void *cb_data)
56{
57 struct refmatch *info;
58
59 info = (struct refmatch *)cb_data;
60 if (!strcmp(refname, info->req_ref))
61 info->match = 1;
62 if (!info->first_ref)
63 info->first_ref = xstrdup(refname);
64 return info->match;
65}
66
67char *find_default_branch(struct repoinfo *repo)
68{
69 struct refmatch info;
70
71 info.req_ref = repo->defbranch;
72 info.first_ref = NULL;
73 info.match = 0;
74 for_each_branch_ref(find_current_ref, &info);
75 if (info.match)
76 return info.req_ref;
77 else
78 return info.first_ref;
79}
80
48static void cgit_print_repo_page(struct cacheitem *item) 81static void cgit_print_repo_page(struct cacheitem *item)
49{ 82{
50 char *title; 83 char *title, *tmp;
51 int show_search; 84 int show_search;
52 85 unsigned char sha1[20];
53 if (!cgit_query_head)
54 cgit_query_head = cgit_repo->defbranch;
55 86
56 if (chdir(cgit_repo->path)) { 87 if (chdir(cgit_repo->path)) {
57 title = fmt("%s - %s", cgit_root_title, "Bad request"); 88 title = fmt("%s - %s", cgit_root_title, "Bad request");
@@ -67,6 +98,29 @@ static void cgit_print_repo_page(struct cacheitem *item)
67 show_search = 0; 98 show_search = 0;
68 setenv("GIT_DIR", cgit_repo->path, 1); 99 setenv("GIT_DIR", cgit_repo->path, 1);
69 100
101 if (!cgit_query_head) {
102 cgit_query_head = xstrdup(find_default_branch(cgit_repo));
103 cgit_repo->defbranch = cgit_query_head;
104 }
105
106 if (!cgit_query_head) {
107 cgit_print_docstart(title, item);
108 cgit_print_pageheader(title, 0);
109 cgit_print_error("Repository seems to be empty");
110 cgit_print_docend();
111 return;
112 }
113
114 if (get_sha1(cgit_query_head, sha1)) {
115 tmp = xstrdup(cgit_query_head);
116 cgit_query_head = cgit_repo->defbranch;
117 cgit_print_docstart(title, item);
118 cgit_print_pageheader(title, 0);
119 cgit_print_error(fmt("Invalid branch: %s", tmp));
120 cgit_print_docend();
121 return;
122 }
123
70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { 124 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
71 cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, 125 cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1,
72 cgit_repobasename(cgit_repo->url), 126 cgit_repobasename(cgit_repo->url),
@@ -75,6 +129,11 @@ static void cgit_print_repo_page(struct cacheitem *item)
75 return; 129 return;
76 } 130 }
77 131
132 if (cgit_cmd == CMD_PATCH) {
133 cgit_print_patch(cgit_query_sha1, item);
134 return;
135 }
136
78 if (cgit_cmd == CMD_BLOB) { 137 if (cgit_cmd == CMD_BLOB) {
79 cgit_print_blob(item, cgit_query_sha1, cgit_query_path); 138 cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
80 return; 139 return;
diff --git a/cgit.css b/cgit.css
index 1b2e9d6..17c2712 100644
--- a/cgit.css
+++ b/cgit.css
@@ -8,7 +8,7 @@ body {
8 font-size: 10pt; 8 font-size: 10pt;
9 color: #333; 9 color: #333;
10 background: white; 10 background: white;
11 padding-left: 4px; 11 padding: 4px;
12} 12}
13 13
14table { 14table {
@@ -78,29 +78,39 @@ img {
78 border: none; 78 border: none;
79} 79}
80 80
81div#sidebar { 81table#layout {
82 border-collapse: collapse;
83 border: none;
84 margin: 0px;
85}
86
87td#sidebar {
82 vertical-align: top; 88 vertical-align: top;
83 width: 162px; 89 width: 162px;
84 padding: 0px 0px 0px 0px; 90 padding: 0px 0px 0px 0px;
85 margin: 4px; 91 margin: 0px;
86 float: left;
87} 92}
88 93
89div#logo { 94td#sidebar table {
95 border-collapse: separate;
96 border-spacing: 0px;
90 margin: 0px; 97 margin: 0px;
91 padding: 4px 0px 4px 0px; 98 padding: 0px;
92 text-align: center;
93 background-color: #ccc; 99 background-color: #ccc;
100}
101
102td#sidebar table.sidebar td.sidebar {
103 padding: 4px;
94 border-top: solid 1px #eee; 104 border-top: solid 1px #eee;
95 border-left: solid 1px #eee; 105 border-left: solid 1px #eee;
96 border-right: solid 1px #aaa; 106 border-right: solid 1px #aaa;
97 border-bottom: solid 1px #aaa; 107 border-bottom: solid 1px #aaa;
98} 108}
99 109
100div#sidebar div.infobox { 110div#logo {
101 margin: 0px 0px 0px 0px; 111 margin: 0px;
102 padding: 0.5em; 112 padding: 4px 0px 4px 0px;
103 text-align: left; 113 text-align: center;
104 background-color: #ccc; 114 background-color: #ccc;
105 border-top: solid 1px #eee; 115 border-top: solid 1px #eee;
106 border-left: solid 1px #eee; 116 border-left: solid 1px #eee;
@@ -108,50 +118,44 @@ div#sidebar div.infobox {
108 border-bottom: solid 1px #aaa; 118 border-bottom: solid 1px #aaa;
109} 119}
110 120
111div#sidebar div.infobox h1 { 121td#sidebar h1 {
112 font-size: 11pt; 122 font-size: 10pt;
113 font-weight: bold; 123 font-weight: bold;
114 margin: 0px; 124 margin: 8px 0px 0px 0px;
115} 125}
116 126
117div#sidebar div.infobox a.menu { 127td#sidebar h1.first {
128 margin-top: 0px;
129}
130
131td#sidebar a.menu {
118 display: block; 132 display: block;
119 background-color: #ccc; 133 background-color: #ccc;
120 padding: 0.1em 0.5em; 134 padding: 0.1em 0.5em;
121 text-decoration: none; 135 text-decoration: none;
122} 136}
123 137
124div#sidebar div.infobox a.menu:hover { 138td#sidebar a.menu:hover {
125 background-color: #bbb; 139 background-color: #bbb;
126 text-decoration: none; 140 text-decoration: none;
127} 141}
128 142
129div#sidebar div.infobox select { 143td#sidebar select {
130 width: 100%; 144 width: 100%;
131 border: solid 1px #aaa;
132 background-color: #bbb;
133 margin: 2px 0px 0px 0px; 145 margin: 2px 0px 0px 0px;
134 padding: 0px;
135} 146}
136 147
137td#branch-dropdown-cell { 148td#sidebar form {
138 width: 99%; 149 text-align: right;
139} 150}
140 151
141input#switch-btn { 152input#switch-btn {
142 width: 20px;