-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | cgit.c | 9 | ||||
-rw-r--r-- | cgit.css | 5 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc.5.txt | 15 | ||||
-rwxr-xr-x | filters/syntax-highlighting.sh | 29 | ||||
-rw-r--r-- | shared.c | 17 | ||||
-rw-r--r-- | ui-repolist.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 11 | ||||
-rw-r--r-- | ui-shared.h | 1 | ||||
-rw-r--r-- | ui-tag.c | 24 | ||||
-rw-r--r-- | ui-tree.c | 6 |
12 files changed, 94 insertions, 41 deletions
@@ -13,2 +13,5 @@ INSTALL = install # +# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 +# implementation (slower). +# # Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). @@ -70,3 +73,3 @@ endif -EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto +EXTLIBS = git/libgit.a git/xdiff/lib.a -lz OBJECTS = @@ -126,2 +129,8 @@ ifdef NO_STRCASESTR endif +ifdef NO_OPENSSL + CFLAGS += -DNO_OPENSSL + GIT_OPTIONS += NO_OPENSSL=1 +else + EXTLIBS += -lcrypto +endif @@ -135,4 +144,4 @@ cgit.o: VERSION libgit: - $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a - $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a + $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a + $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a @@ -70,5 +70,5 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) if (*value == '/') - ctx.repo->readme = xstrdup(value); + repo->readme = xstrdup(value); else - ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); + repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); } else if (ctx.cfg.enable_filter_overrides) { @@ -167,2 +167,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.max_repodesc_len = atoi(value); + else if (!strcmp(name, "max-blob-size")) + ctx.cfg.max_blob_size = atoi(value); else if (!strcmp(name, "max-repo-count")) @@ -213,2 +215,4 @@ static void querystring_cb(const char *name, const char *value) } else if (!strcmp(name, "url")) { + if (*value == '/') + value++; ctx.qry.url = xstrdup(value); @@ -274,2 +278,3 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.max_repodesc_len = 80; + ctx->cfg.max_blob_size = 0; ctx->cfg.max_stats = 0; @@ -164,2 +164,7 @@ table.list td a { +table.list td a.ls-dir { + font-weight: bold; + color: #00f; +} + table.list td a:hover { @@ -188,2 +188,3 @@ struct cgit_config { int max_repodesc_len; + int max_blob_size; int max_stats; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 252d546..70e4c78 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -1 +1,4 @@ +:man source: cgit +:man manual: cgit + CGITRC(5) @@ -176,2 +179,6 @@ max-repodesc-length:: +max-blob-size:: + Specifies the maximum size of a blob to display HTML for in KBytes. + Default value: "0" (limit disabled). + max-stats:: @@ -427,4 +434,4 @@ mimetype.svg=image/svg+xml ## List of repositories. -## PS: Any repositories listed when repo.group is unset will not be -## displayed under a group heading +## PS: Any repositories listed when section is unset will not be +## displayed under a section heading ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') @@ -450,3 +457,3 @@ repo.readme=info/web/about.html # The next repositories will be displayed under the 'extras' heading -repo.group=extras +section=extras @@ -463,3 +470,3 @@ repo.desc=the wizard of foo # Add some mirrored repositories -repo.group=mirrors +section=mirrors diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh index 999ad0c..6b1c576 100755 --- a/filters/syntax-highlighting.sh +++ b/filters/syntax-highlighting.sh @@ -5,2 +5,6 @@ # +# This script requires a shell supporting the ${var##pattern} syntax. +# It is supported by at least dash and bash, however busybox environments +# might have to use an external call to sed instead. +# # Note: the highlight command (http://www.andre-simon.de/) uses css for syntax @@ -22,18 +26,9 @@ -case "$1" in - *.c) - highlight -f -I -X -S c - ;; - *.h) - highlight -f -I -X -S c - ;; - *.sh) - highlight -f -I -X -S sh - ;; - *.css) - highlight -f -I -X -S css - ;; - *) - highlight -f -I -X -S txt - ;; -esac +# store filename and extension in local vars +BASENAME="$1" +EXTENSION="${BASENAME##*.}" + +# map Makefile and Makefile.* to .mk +[ "${BASENAME%%.*}" == "Makefile" ] && EXTENSION=mk + +exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null @@ -402,3 +402,3 @@ int readfile(const char *path, char **buf, size_t *size) { - int fd; + int fd, e; struct stat st; @@ -408,10 +408,17 @@ int readfile(const char *path, char **buf, size_t *size) return errno; - if (fstat(fd, &st)) - return errno; - if (!S_ISREG(st.st_mode)) + if (fstat(fd, &st)) { + e = errno; + close(fd); + return e; + } + if (!S_ISREG(st.st_mode)) { + close(fd); return EISDIR; + } *buf = xmalloc(st.st_size + 1); *size = read_in_full(fd, *buf, st.st_size); + e = errno; (*buf)[*size] = '\0'; - return (*size == st.st_size ? 0 : errno); + close(fd); + return (*size == st.st_size ? 0 : e); } diff --git a/ui-repolist.c b/ui-repolist.c index 3ef2e99..0a0b6ca 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -96,3 +96,3 @@ void print_sort_header(const char *title, const char *sort) { - htmlf("<th class='left'><a href='./?s=%s", sort); + htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort); if (ctx.qry.search) { diff --git a/ui-shared.c b/ui-shared.c index de55eff..08ea003 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -22,3 +22,3 @@ static char *http_date(time_t t) {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; struct tm *tm = gmtime(&t); @@ -784,4 +784,10 @@ void cgit_print_snapshot_links(const char *repo, const char *head, const struct cgit_snapshot_format* f; + char *prefix; char *filename; + unsigned char sha1[20]; + if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && + (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) + hex++; + prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); for (f = cgit_snapshot_formats; f->suffix; f++) { @@ -789,4 +795,3 @@ void cgit_print_snapshot_links(const char *repo, const char *head, continue; - filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, - f->suffix); + filename = fmt("%s%s", prefix, f->suffix); cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); diff --git a/ui-shared.h b/ui-shared.h index 166246d..9ebc1f9 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -5,2 +5,3 @@ extern char *cgit_httpscheme(); extern char *cgit_hosturl(); +extern char *cgit_rooturl(); extern char *cgit_repourl(const char *reponame); @@ -32,2 +32,10 @@ static void print_tag_content(char *buf) +void print_download_links(char *revname) +{ + html("<tr><th>download</th><td class='sha1'>"); + cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, + revname, ctx.repo->snapshots); + html("</td></tr>"); +} + void cgit_print_tag(char *revname) @@ -58,3 +66,3 @@ void cgit_print_tag(char *revname) html("<table class='commit-info'>\n"); - htmlf("<tr><td>Tag name</td><td>"); + htmlf("<tr><td>tag name</td><td>"); html_txt(revname); @@ -62,3 +70,3 @@ void cgit_print_tag(char *revname) if (info->tagger_date > 0) { - html("<tr><td>Tag date</td><td>"); + html("<tr><td>tag date</td><td>"); cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); @@ -67,3 +75,3 @@ void cgit_print_tag(char *revname) if (info->tagger) { - html("<tr><td>Tagged by</td><td>"); + html("<tr><td>tagged by</td><td>"); html_txt(info->tagger); @@ -75,5 +83,7 @@ void cgit_print_tag(char *revname) } - html("<tr><td>Tagged object</td><td>"); + html("<tr><td>tagged object</td><td class='sha1'>"); cgit_object_link(tag->tagged); html("</td></tr>\n"); + if (ctx.repo->snapshots) + print_download_links(revname); html("</table>\n"); @@ -82,8 +92,10 @@ void cgit_print_tag(char *revname) html("<table class='commit-info'>\n"); - htmlf("<tr><td>Tag name</td><td>"); + htmlf("<tr><td>tag name</td><td>"); html_txt(revname); html("</td></tr>\n"); - html("<tr><td>Tagged object</td><td>"); + html("<tr><td>Tagged object</td><td class='sha1'>"); cgit_object_link(obj); html("</td></tr>\n"); + if (ctx.repo->snapshots) + print_download_links(revname); html("</table>\n"); @@ -109,2 +109,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base + if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { + htmlf("<div class='error'>blob size (%dKB) exceeds display size limit (%dKB).</div>", + size / 1024, ctx.cfg.max_blob_size); + return; + } + if (buffer_is_binary(buf, size)) |