diff options
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | cgit.c | 67 | ||||
| -rw-r--r-- | cgit.css | 64 | ||||
| -rw-r--r-- | cgit.h | 12 | ||||
| -rw-r--r-- | cgit.png | bin | 3790 -> 5406 bytes | |||
| -rw-r--r-- | cgitrc | 12 | ||||
| -rw-r--r-- | html.c | 2 | ||||
| -rw-r--r-- | parsing.c | 25 | ||||
| -rw-r--r-- | shared.c | 12 | ||||
| -rw-r--r-- | tests/.gitignore | 2 | ||||
| -rw-r--r-- | tests/Makefile | 13 | ||||
| -rwxr-xr-x | tests/setup.sh | 108 | ||||
| -rwxr-xr-x | tests/t0010-validate-html.sh | 31 | ||||
| -rwxr-xr-x | tests/t0101-index.sh | 13 | ||||
| -rwxr-xr-x | tests/t0102-summary.sh | 20 | ||||
| -rwxr-xr-x | tests/t0103-log.sh | 15 | ||||
| -rwxr-xr-x | tests/t0104-tree.sh | 21 | ||||
| -rwxr-xr-x | tests/t0105-commit.sh | 22 | ||||
| -rwxr-xr-x | tests/t0106-diff.sh | 20 | ||||
| -rwxr-xr-x | tests/t0107-snapshot.sh | 36 | ||||
| -rw-r--r-- | ui-commit.c | 6 | ||||
| -rw-r--r-- | ui-diff.c | 2 | ||||
| -rw-r--r-- | ui-log.c | 23 | ||||
| -rw-r--r-- | ui-patch.c | 110 | ||||
| -rw-r--r-- | ui-repolist.c | 2 | ||||
| -rw-r--r-- | ui-shared.c | 67 | ||||
| -rw-r--r-- | ui-summary.c | 2 | ||||
| -rw-r--r-- | ui-tree.c | 6 |
28 files changed, 651 insertions, 74 deletions
| @@ -16,10 +16,15 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | |||
| 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 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 | 22 | ifdef NEEDS_LIBICONV |
| 23 | EXTLIBS += -liconv | ||
| 24 | endif | ||
| 25 | |||
| 26 | |||
| 27 | .PHONY: all git test install clean distclean emptycache force-version get-git | ||
| 23 | 28 | ||
| 24 | all: cgit git | 29 | all: 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 | ||
| 57 | test: all | ||
| 58 | $(MAKE) -C tests | ||
| 59 | |||
| 52 | install: all | 60 | install: 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) |
| @@ -45,13 +45,44 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
| 45 | return 1; | 45 | return 1; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | struct refmatch { | ||
| 49 | char *req_ref; | ||
| 50 | char *first_ref; | ||
| 51 | int match; | ||
| 52 | }; | ||
| 53 | |||
| 54 | int 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 | |||
| 67 | char *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 | |||
| 48 | static void cgit_print_repo_page(struct cacheitem *item) | 81 | static 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; |
| @@ -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 | ||
| 14 | table { | 14 | table { |
| @@ -78,29 +78,39 @@ img { | |||
| 78 | border: none; | 78 | border: none; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | div#sidebar { | 81 | table#layout { |
| 82 | border-collapse: collapse; | ||
| 83 | border: none; | ||
| 84 | margin: 0px; | ||
| 85 | } | ||
| 86 | |||
| 87 | td#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 | ||
| 89 | div#logo { | 94 | td#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 | |||
| 102 | td#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 | ||
| 100 | div#sidebar div.infobox { | 110 | div#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 | ||
| 111 | div#sidebar div.infobox h1 { | 121 | td#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 | ||
| 117 | div#sidebar div.infobox a.menu { | 127 | td#sidebar h1.first { |
| 128 | margin-top: 0px; | ||
| 129 | } | ||
| 130 | |||
| 131 | td#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 | ||
| 124 | div#sidebar div.infobox a.menu:hover { | 138 | td#sidebar a.menu:hover { |
| 125 | background-color: #bbb; | 139 | background-color: #bbb; |
| 126 | text-decoration: none; | 140 | text-decoration: none; |
| 127 | } | 141 | } |
| 128 | 142 | ||
| 129 | div#sidebar div.infobox select { | 143 | td#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 | ||
| 137 | td#branch-dropdown-cell { | 148 | td#sidebar form { |
| 138 | width: 99%; | 149 | text-align: right; |
| 139 | } | 150 | } |
| 140 | 151 | ||
| 141 | input#switch-btn { | 152 | input#switch-btn { |
| 142 | width: 20px; | ||
| 143 | border: solid 1px #aaa; | ||
| 144 | background-color: #bbb; | ||
| 145 | margin: 2px 0px 0px 0px; | 153 | margin: 2px 0px 0px 0px; |
| 146 | padding: 0px; | ||
| 147 | } | 154 | } |
| 148 | 155 | ||
| 149 | div#sidebar div.infobox input.txt { | 156 | td#sidebar input.txt { |
| 150 | width: 100%; | 157 | width: 100%; |
| 151 | border: solid 1px #aaa; | ||
| 152 | background-color: #bbb; | ||
| 153 | margin: 2px 0px 0px 0px; | 158 | margin: 2px 0px 0px 0px; |
| 154 | padding: 0; | ||
| 155 | } | 159 | } |
| 156 | 160 | ||
| 157 | table#grid { | 161 | table#grid { |
| @@ -16,6 +16,7 @@ | |||
| 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 | #include <utf8.h> | ||
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | /* | 22 | /* |
| @@ -29,6 +30,7 @@ | |||
| 29 | #define CMD_SNAPSHOT 6 | 30 | #define CMD_SNAPSHOT 6 |
| 30 | #define CMD_TAG 7 | 31 | #define CMD_TAG 7 |
| 31 | #define CMD_REFS 8 | 32 | #define CMD_REFS 8 |
| 33 | #define CMD_PATCH 9 | ||
| 32 | 34 | ||
| 33 | /* | 35 | /* |
| 34 | * Dateformats used on misc. pages | 36 | * Dateformats used on misc. pages |
| @@ -48,6 +50,11 @@ | |||
| 48 | #define TM_MONTH (TM_YEAR / 12.0) | 50 | #define TM_MONTH (TM_YEAR / 12.0) |
| 49 | 51 | ||
| 50 | 52 | ||
| 53 | /* | ||
| 54 | * Default encoding | ||
| 55 | */ | ||
| 56 | #define PAGE_ENCODING "UTF-8" | ||
| 57 | |||
| 51 | typedef void (*configfn)(const char *name, const char *value); | 58 | typedef void (*configfn)(const char *name, const char *value); |
| 52 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 59 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
| 53 | typedef void (*linediff_fn)(char *line, int len); | 60 | typedef void (*linediff_fn)(char *line, int len); |
| @@ -69,6 +76,7 @@ struct repoinfo { | |||
| 69 | char *group; | 76 | char *group; |
| 70 | char *module_link; | 77 | char *module_link; |
| 71 | char *readme; | 78 | char *readme; |
| 79 | char *clone_url; | ||
| 72 | int snapshots; | 80 | int snapshots; |
| 73 | int enable_log_filecount; | 81 | int enable_log_filecount; |
| 74 | int enable_log_linecount; | 82 | int enable_log_linecount; |
| @@ -90,6 +98,7 @@ struct commitinfo { | |||
| 90 | unsigned long committer_date; | 98 | unsigned long committer_date; |
| 91 | char *subject; | 99 | char *subject; |
| 92 | char *msg; | 100 | char *msg; |
| 101 | char *msg_encoding; | ||
| 93 | }; | 102 | }; |
| 94 | 103 | ||
| 95 | struct taginfo { | 104 | struct taginfo { |
| @@ -132,6 +141,8 @@ extern char *cgit_virtual_root; | |||
| 132 | extern char *cgit_script_name; | 141 | extern char *cgit_script_name; |
| 133 | extern char *cgit_cache_root; | 142 | extern char *cgit_cache_root; |
| 134 | extern char *cgit_repo_group; | 143 | extern char *cgit_repo_group; |
| 144 | extern char *cgit_robots; | ||
| 145 | extern char *cgit_clone_prefix; | ||
| 135 | 146 | ||
| 136 | extern int cgit_nocache; | 147 | extern int cgit_nocache; |
| 137 | extern int cgit_snapshots; | 148 | extern int cgit_snapshots; |
| @@ -273,6 +284,7 @@ extern void cgit_print_commit(char *hex); | |||
| 273 | extern void cgit_print_refs(); | 284 | extern void cgit_print_refs(); |
| 274 | extern void cgit_print_tag(char *revname); | 285 | extern void cgit_print_tag(char *revname); |
| 275 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | 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); | ||
| 276 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 288 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
| 277 | const char *hex, const char *prefix, | 289 | const char *hex, const char *prefix, |
| 278 | const char *filename, int snapshot); | 290 | const char *filename, int snapshot); |
| Binary files differ | |||
| @@ -8,6 +8,11 @@ | |||
| 8 | #nocache=0 | 8 | #nocache=0 |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | ## This variable can be used to override the default value for "robots" | ||
| 12 | ## meta-tag. If unset, the meta-tag isn't generated. | ||
| 13 | #robots=index, nofollow | ||
| 14 | |||
| 15 | |||
| 11 | ## Set allowed snapshot types by default. Can be overridden per repo | 16 | ## Set allowed snapshot types by default. Can be overridden per repo |
| 12 | # can be any combination of zip/tar.gz/tar.bz2/tar | 17 | # can be any combination of zip/tar.gz/tar.bz2/tar |
| 13 | #snapshots=0 | 18 | #snapshots=0 |
| @@ -111,6 +116,11 @@ | |||
| 111 | #module-link=./?repo=%s&page=commit&id=%s | 116 | #module-link=./?repo=%s&page=commit&id=%s |
| 112 | 117 | ||
| 113 | 118 | ||
| 119 | ## Shared prefix which, when combined with repo url, becomes the url used | ||
| 120 | ## to clone the repo | ||
| 121 | #clone-prefix= | ||
| 122 | |||
| 123 | |||
| 114 | ## Number of chars shown of repo description (in repolist view) | 124 | ## Number of chars shown of repo description (in repolist view) |
| 115 | #max-repodesc-length=60 | 125 | #max-repodesc-length=60 |
| 116 | 126 | ||
| @@ -162,12 +172,14 @@ | |||
| 162 | #repo.enable-log-linecount=0 ## override the default linecount setting | 172 | #repo.enable-log-linecount=0 ## override the default linecount setting |
| 163 | #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link | 173 | #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link |
| 164 | #repo.readme=info/web/readme ## specify a file to include on summary page | 174 | #repo.readme=info/web/readme ## specify a file to include on summary page |
| 175 | #repo.clone-url=git://hjemli.net/pub/git/cgit | ||
| 165 | 176 | ||
| 166 | ## Additional repositories grouped under "mirrors" | 177 | ## Additional repositories grouped under "mirrors" |
| 167 | #repo.group=mirrors | 178 | #repo.group=mirrors |
| 168 | 179 | ||
| 169 | #repo.url=git | 180 | #repo.url=git |
| 170 | #repo.path=/pub/git/git | 181 | #repo.path=/pub/git/git |
| 182 | #repo.clone-url=git://hjemli.net/pub/git/git | ||
| 171 | # | 183 | # |
| 172 | #repo.url=linux | 184 | #repo.url=linux |
| 173 | #repo.path=/pub/git/linux | 185 | #repo.path=/pub/git/linux |
| @@ -132,7 +132,7 @@ void html_option(char *value, char *text, char *selected_value) | |||
| 132 | html_attr(value); | 132 | html_attr(value); |
| 133 | html("'"); | 133 | html("'"); |
| 134 | if (selected_value && !strcmp(selected_value, value)) | 134 | if (selected_value && !strcmp(selected_value, value)) |
| 135 | html(" selected"); | 135 | html(" selected='selected'"); |
| 136 | html(">"); | 136 | html(">"); |
| 137 | html_txt(text); | 137 | html_txt(text); |
| 138 | html("</option>\n"); | 138 | html("</option>\n"); |
| @@ -199,6 +199,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) | |||
| 199 | ret->committer_email = NULL; | 199 | ret->committer_email = NULL; |
| 200 | ret->subject = NULL; | 200 | ret->subject = NULL; |
| 201 | ret->msg = NULL; | 201 | ret->msg = NULL; |
| 202 | ret->msg_encoding = NULL; | ||
| 202 | 203 | ||
| 203 | if (p == NULL) | 204 | if (p == NULL) |
| 204 | return ret; | 205 | return ret; |
| @@ -233,6 +234,14 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) | |||
| 233 | p = strchr(t, '\n') + 1; | 234 | p = strchr(t, '\n') + 1; |
| 234 | } | 235 | } |
| 235 | 236 | ||
| 237 | if (!strncmp(p, "encoding ", 9)) { | ||
| 238 | p += 9; | ||
| 239 | t = strchr(p, '\n') + 1; | ||
| 240 | ret->msg_encoding = substr(p, t); | ||
| 241 | p = t; | ||
| 242 | } else | ||
| 243 | ret->msg_encoding = xstrdup(PAGE_ENCODING); | ||
| 244 | |||
| 236 | while (*p && (*p != '\n')) | 245 | while (*p && (*p != '\n')) |
| 237 | p = strchr(p, '\n') + 1; // skip unknown header fields | 246 | p = strchr(p, '\n') + 1; // skip unknown header fields |
| 238 | 247 | ||
| @@ -253,6 +262,22 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) | |||
| 253 | } else | 262 | } else |
| 254 | ret->subject = substr(p, p+strlen(p)); | 263 | ret->subject = substr(p, p+strlen(p)); |
| 255 | 264 | ||
| 265 | if(strcmp(ret->msg_encoding, PAGE_ENCODING)) { | ||
| 266 | t = reencode_string(ret->subject, PAGE_ENCODING, | ||
| 267 | ret->msg_encoding); | ||
| 268 | if(t) { | ||
| 269 | free(ret->subject); | ||
| 270 | ret->subject = t; | ||
| 271 | } | ||
| 272 | |||
| 273 | t = reencode_string(ret->msg, PAGE_ENCODING, | ||
| 274 | ret->msg_encoding); | ||
| 275 | if(t) { | ||
| 276 | free(ret->msg); | ||
| 277 | ret->msg = t; | ||
| 278 | } | ||
| 279 | } | ||
| 280 | |||
| 256 | return ret; | 281 | return ret; |
| 257 | } | 282 | } |
| 258 | 283 | ||
| @@ -26,6 +26,8 @@ char *cgit_virtual_root = NULL; | |||
| 26 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 26 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
| 27 | char *cgit_cache_root = CGIT_CACHE_ROOT; | 27 | char *cgit_cache_root = CGIT_CACHE_ROOT; |
| 28 | char *cgit_repo_group = NULL; | 28 | char *cgit_repo_group = NULL; |
| 29 | char *cgit_robots = "index, nofollow"; | ||
| 30 | char *cgit_clone_prefix = NULL; | ||
| 29 | 31 | ||
| 30 | int cgit_nocache = 0; | 32 | int cgit_nocache = 0; |
| 31 | int cgit_snapshots = 0; | 33 | int cgit_snapshots = 0; |
| @@ -68,7 +70,7 @@ int htmlfd = 0; | |||
| 68 | int cgit_get_cmd_index(const char *cmd) | 70 | int cgit_get_cmd_index(const char *cmd) |
| 69 | { | 71 | { |
| 70 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 72 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
| 71 | "snapshot", "tag", "refs", NULL}; | 73 | "snapshot", "tag", "refs", "patch", NULL}; |
| 72 | int i; | 74 | int i; |
| 73 | 75 | ||
| 74 | for(i = 0; cmds[i]; i++) | 76 | for(i = 0; cmds[i]; i++) |
| @@ -197,6 +199,10 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
| 197 | cgit_agefile = xstrdup(value); | 199 | cgit_agefile = xstrdup(value); |
| 198 | else if (!strcmp(name, "renamelimit")) | 200 | else if (!strcmp(name, "renamelimit")) |
| 199 | cgit_renamelimit = atoi(value); | 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); | ||
| 200 | else if (!strcmp(name, "repo.group")) | 206 | else if (!strcmp(name, "repo.group")) |
| 201 | cgit_repo_group = xstrdup(value); | 207 | cgit_repo_group = xstrdup(value); |
| 202 | else if (!strcmp(name, "repo.url")) | 208 | else if (!strcmp(name, "repo.url")) |
| @@ -205,6 +211,8 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
| 205 | cgit_repo->name = xstrdup(value); | 211 | cgit_repo->name = xstrdup(value); |
| 206 | else if (cgit_repo && !strcmp(name, "repo.path")) | 212 | else if (cgit_repo && !strcmp(name, "repo.path")) |
| 207 | cgit_repo->path = trim_end(value, '/'); | 213 | cgit_repo->path = trim_end(value, '/'); |
| 214 | else if (cgit_repo && !strcmp(name, "repo.clone-url")) | ||
| 215 | cgit_repo->clone_url = xstrdup(value); | ||
| 208 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 216 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
| 209 | cgit_repo->desc = xstrdup(value); | 217 | cgit_repo->desc = xstrdup(value); |
| 210 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 218 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
| @@ -267,6 +275,8 @@ void *cgit_free_commitinfo(struct commitinfo *info) | |||
| 267 | free(info->committer); | 275 | free(info->committer); |
| 268 | free(info->committer_email); | 276 | free(info->committer_email); |
| 269 | free(info->subject); | 277 | free(info->subject); |
| 278 | free(info->msg); | ||
| 279 | free(info->msg_encoding); | ||
| 270 | free(info); | 280 | free(info); |
| 271 | return NULL; | 281 | return NULL; |
| 272 | } | 282 | } |
diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..c1c1c0b --- /dev/null +++ b/tests/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | trash | ||
| 2 | test-output.log | ||
diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..697e5a1 --- /dev/null +++ b/tests/Makefile | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | |||
| 2 | |||
| 3 | T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) | ||
| 4 | |||
| 5 | all: $(T) | ||
| 6 | |||
| 7 | $(T): | ||
| 8 | @$@ | ||
| 9 | |||
| 10 | clean: | ||
| 11 | $(RM) -rf trash | ||
| 12 | |||
| 13 | .PHONY: $(T) clean | ||
diff --git a/tests/setup.sh b/tests/setup.sh new file mode 100755 index 0000000..51d5a75 --- /dev/null +++ b/tests/setup.sh | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | # This file should be sourced by all test-scripts | ||
| 2 | # | ||
| 3 | # Main functions: | ||
| 4 | # prepare_tests(description) - setup for testing, i.e. create repos+config | ||
| 5 | # run_test(description, script) - run one test, i.e. eval script | ||
| 6 | # | ||
| 7 | # Helper functions | ||
| 8 | # cgit_query(querystring) - call cgit with the specified querystring | ||
| 9 | # cgit_url(url) - call cgit with the specified virtual url | ||
| 10 | # | ||
| 11 | # Example script: | ||
| 12 | # | ||
| 13 | # . setup.sh | ||
| 14 | # prepare_tests "html validation" | ||
| 15 | # run_test 'repo index' 'cgit_url "/" | tidy -e' | ||
| 16 | # run_test 'repo summary' 'cgit_url "/foo" | tidy -e' | ||
| 17 | |||
| 18 | |||
| 19 | mkrepo() { | ||
| 20 | name=$1 | ||
| 21 | count=$2 | ||
| 22 | dir=$PWD | ||
| 23 | test -d $name && return | ||
| 24 | printf "Creating testrepo %s\n" $name | ||
| 25 | mkdir -p $name | ||
| 26 | cd $name | ||
| 27 | git init | ||
| 28 | for ((n=1; n<=count; n++)) | ||
| 29 | do | ||
| 30 | echo $n >file-$n | ||
| 31 | git add file-$n | ||
| 32 | git commit -m "commit $n" | ||
| 33 | done | ||
| 34 | cd $dir | ||
| 35 | } | ||
| 36 | |||
| 37 | setup_repos() | ||
| 38 | { | ||
| 39 | rm -rf trash/cache | ||
| 40 | mkdir -p trash/cache | ||
| 41 | mkrepo trash/repos/foo 5 >/dev/null | ||
| 42 | mkrepo trash/repos/bar 50 >/dev/null | ||
| 43 | cat >trash/cgitrc <<EOF | ||
| 44 | virtual-root=/ | ||
| 45 | cache-root=$PWD/trash/cache | ||
| 46 | |||
| 47 | nocache=0 | ||
| 48 | snapshots=tar.gz tar.bz zip | ||
| 49 | enable-log-filecount=1 | ||
| 50 | enable-log-linecount=1 | ||
| 51 | summary-log=5 | ||
| 52 | summary-branches=5 | ||
| 53 | summary-tags=5 | ||
| 54 | |||
| 55 | repo.url=foo | ||
| 56 | repo.path=$PWD/trash/repos/foo/.git | ||
| 57 | repo.desc=the foo repo | ||
| 58 | |||
| 59 | repo.url=bar | ||
| 60 | repo.path=$PWD/trash/repos/bar/.git | ||
| 61 | repo.desc=the bar repo | ||
| 62 | EOF | ||
| 63 | } | ||
| 64 | |||
| 65 | prepare_tests() | ||
| 66 | { | ||
| 67 | setup_repos | ||
| 68 | test_count=0 | ||
| 69 | test_failed=0 | ||
| 70 | echo "$@" "($0)" | ||
| 71 | } | ||
| 72 | |||
| 73 | tests_done() | ||
| 74 | { | ||
| 75 | printf "\n" | ||
| 76 | if test $test_failed -gt 0 | ||
| 77 | then | ||
| 78 | printf "[%s of %s tests failed]\n" $test_failed $test_count | ||
| 79 | false | ||
| 80 | fi | ||
| 81 | } | ||
| 82 | |||
| 83 | run_test() | ||
| 84 | { | ||
| 85 | desc=$1 | ||
| 86 | script=$2 | ||
| 87 | ((test_count++)) | ||
| 88 | eval "$2" >test-output.log | ||
| 89 | res=$? | ||
| 90 | if test $res = 0 | ||
| 91 | then | ||
| 92 | printf " %s: ok - %s\n" $test_count "$desc" | ||
| 93 | else | ||
| 94 | ((test_failed++)) | ||
| 95 | printf " %s: fail - %s\n" $test_count "$desc" | ||
| 96 | fi | ||
| 97 | } | ||
| 98 | |||
| 99 | cgit_query() | ||
| 100 | { | ||
| 101 | CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit" | ||
| 102 | } | ||
| 103 | |||
| 104 | cgit_url() | ||
| 105 | { | ||
| 106 | CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit" | ||
| 107 | } | ||
| 108 | |||
diff --git a/tests/t0010-validate-html.sh b/tests/t0010-validate-html.sh new file mode 100755 index 0000000..907a415 --- /dev/null +++ b/tests/t0010-validate-html.sh | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | . ./setup.sh | ||
| 4 | |||
| 5 | |||
| 6 | test_url() | ||
| 7 | { | ||
| 8 | tidy_opt="-eq" | ||
| 9 | test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no" | ||
| 10 | cgit_url "$1" | sed -e "1,4d" >trash/tidy-$test_count | ||
| 11 | tidy $tidy_opt trash/tidy-$test_count | ||
| 12 | rc=$? | ||
| 13 | if test $rc = 2 | ||
| 14 | then | ||
| 15 | false | ||
| 16 | else | ||
| 17 | : | ||
| 18 | fi | ||
| 19 | } | ||
| 20 | |||
| 21 | prepare_tests 'Validate html with tidy' | ||
| 22 | |||
| 23 | run_test 'index page' 'test_url ""' | ||
| 24 | run_test 'foo' 'test_url "foo"' | ||
| 25 | run_test 'foo/log' 'test_url "foo/log"' | ||
| 26 | run_test 'foo/tree' 'test_url "foo/tree"' | ||
| 27 | run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"' | ||
| 28 | run_test 'foo/commit' 'test_url "foo/commit"' | ||
| 29 | run_test 'foo/diff' 'test_url "foo/diff"' | ||
| 30 | |||
| 31 | tests_done | ||
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh new file mode 100755 index 0000000..12ed00c --- /dev/null +++ b/tests/t0101-index.sh | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | . ./setup.sh | ||
| 4 | |||
| 5 | prepare_tests "Check content on index page" | ||
| 6 | |||
| 7 | run_test 'generate index page' 'cgit_url "" >trash/tmp' | ||
| 8 | run_test 'find foo repo' 'grep -e "foo" trash/tmp' | ||
| 9 | run_test 'find bar repo' 'grep -e "bar" trash/tmp' | ||
| 10 | run_test 'no tree-link' 'grep -ve "foo/tree" trash/tmp' | ||
| 11 | run_test 'no log-link' 'grep -ve "foo/log" trash/tmp' | ||
| 12 | |||
| 13 | tests_done | ||
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh new file mode 100755 index 0000000..7edd675 --- /dev/null +++ b/tests/t0102-summary.sh | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | . ./setup.sh | ||
| 4 | |||
| 5 | prepare_tests "Check content on summary page" | ||
| 6 | |||
| 7 | run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp' | ||
| 8 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
| 9 | run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' | ||
| 10 | run_test 'find branch master' 'grep -e "master" trash/tmp' | ||
| 11 | run_test 'no tags' 'grep -ve "tags" trash/tmp' | ||
| 12 | |||
| 13 | run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp' | ||
| 14 | run_test 'no commit 45' 'grep -ve "commit 45" trash/tmp' | ||
| 15 | run_test 'find commit 46' 'grep -e "commit 46" trash/tmp' | ||
| 16 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | ||
| 17 | run_test 'find branch master' 'grep -e "master" trash/tmp' | ||
| 18 | run_test 'no tags' 'grep -ve "tags" trash/tmp' | ||
| 19 | |||
| 20 | tests_done | ||
diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh new file mode 100755 index 0000000..b08cd29 --- /dev/null +++ b/tests/t0103-log.sh | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | . ./setup.sh | ||
| 4 | |||
| 5 | prepare_tests "Check content on log page" | ||
| 6 | |||
| 7 | run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp' | ||
| 8 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
| 9 | run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' | ||
| 10 | |||
| 11 | run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp' | ||
| 12 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
| 13 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | ||
