From 56522ebe1387721d10196e835346257e7494abad Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Thu, 19 Nov 2009 12:14:45 +0100 Subject: syntax highlighting for all formats supported by "highlight" The highlight tool can be given any of the supported file extensions as its -S parameter. This patch replaces the case-switch by extracting the extension from the supplied file name and passing it to highlight. However, this requires a shell supporting the ${var##pattern} syntax, like dash or bash. Unknown extensions cause a fall-back to plain text using the --force switch. Error messages are redirected to /dev/null. A special case maps Makefile and Makefile.* to the "mk" extension. The total overhead is reduced by calling "exec highlight". No forks are needed during script execution. Signed-off-by: Georg Lukas --- filters/syntax-highlighting.sh | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) 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 @@ -3,6 +3,10 @@ # tree-view by refering to this file with the source-filter or repo.source- # filter options in cgitrc. # +# 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 # highlighting, so you'll probably want something like the following included # in your css file (generated by highlight 2.4.8 and adapted for cgit): @@ -20,20 +24,11 @@ # table.blob .kwc { color:#000000; font-weight:bold; } # table.blob .kwd { color:#010181; } -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 -- cgit v1.2.3-70-g09d2 From 545b5a5dcae2a0c322381493ee90f6c37353da9c Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Sat, 28 Nov 2009 03:07:34 +0100 Subject: cgit.css: highlight directories in tree --- cgit.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cgit.css b/cgit.css index c47ebc9..ef7d3c1 100644 --- a/cgit.css +++ b/cgit.css @@ -162,6 +162,11 @@ table.list td a { color: black; } +table.list td a.ls-dir { + font-weight: bold; + color: #00f; +} + table.list td a:hover { color: #00f; } -- cgit v1.2.3-70-g09d2 From ef07ccc72da0270e9298c36046a0187dc359b0da Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Sat, 28 Nov 2009 03:44:33 +0100 Subject: "max-blob-size" config var to limit generated HTML size Sometimes it is not feasible to generate the HTML pretty-print for large files, especially if a source-filter is involved or binary data is to be displayed. The "max-blob-size" config var allows to disable HTML output for blobs bigger than X KBytes. Plain downloads are not affected. Signed-off-by: Georg Lukas --- cgit.c | 3 +++ cgit.h | 1 + cgitrc.5.txt | 4 ++++ ui-tree.c | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/cgit.c b/cgit.c index a17f40d..e1d38c2 100644 --- a/cgit.c +++ b/cgit.c @@ -165,6 +165,8 @@ void config_cb(const char *name, const char *value) ctx.cfg.max_msg_len = atoi(value); else if (!strcmp(name, "max-repodesc-length")) 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")) ctx.cfg.max_repo_count = atoi(value); else if (!strcmp(name, "max-commit-count")) @@ -270,6 +272,7 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.max_lock_attempts = 5; ctx->cfg.max_msg_len = 80; ctx->cfg.max_repodesc_len = 80; + ctx->cfg.max_blob_size = 0; ctx->cfg.max_stats = 0; ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; ctx->cfg.renamelimit = -1; diff --git a/cgit.h b/cgit.h index 6c6c460..39853df 100644 --- a/cgit.h +++ b/cgit.h @@ -185,6 +185,7 @@ struct cgit_config { int max_lock_attempts; int max_msg_len; int max_repodesc_len; + int max_blob_size; int max_stats; int nocache; int noplainemail; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 0c13485..e69140b 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -177,6 +177,10 @@ max-repodesc-length:: Specifies the maximum number of repo description characters to display on the repository index page. Default value: "80". +max-blob-size:: + Specifies the maximum size of a blob to display HTML for in KBytes. + Default value: "0" (limit disabled). + max-stats:: Set the default maximum statistics period. Valid values are "week", "month", "quarter" and "year". If unspecified, statistics are diff --git a/ui-tree.c b/ui-tree.c index f53ab64..f281937 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -107,6 +107,12 @@ static void print_object(const unsigned char *sha1, char *path, const char *base curr_rev, path); htmlf(")
blob: %s\n", sha1_to_hex(sha1)); + if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { + htmlf("
blob size (%dKB) exceeds display size limit (%dKB).
", + size / 1024, ctx.cfg.max_blob_size); + return; + } + if (buffer_is_binary(buf, size)) print_binary_buffer(buf, size); else -- cgit v1.2.3-70-g09d2