Author: Florian Pritz <bluewind@xssn.at>
Add 'linenumbers' config option Signed-off-by: Florian Pritz <bluewind@xssn.at> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c | 2 ++ cgit.h | 1 + cgitrc.5.txt | 4 ++++ ui-tree.c | 27 ++++++++++++++++-----------
diff --git a/cgit.c b/cgit.c index b0e1c44366cda6e9af2951561e092cba91959b14..a4788cbb34b2ac198dbdcb9d49a4e4d0d96f8ea9 100644 --- a/cgit.c +++ b/cgit.c @@ -66,6 +66,8 @@ else if (!strcmp(name, "index-info")) ctx.cfg.index_info = xstrdup(value); else if (!strcmp(name, "logo-link")) ctx.cfg.logo_link = xstrdup(value); + else if (!strcmp(name, "linenumbers")) + ctx.cfg.linenumbers = atoi(value); else if (!strcmp(name, "module-link")) ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "virtual-root")) { diff --git a/cgit.h b/cgit.h index adb8da4f49be0499eb83ed4a40794f11825be96a..2fdc53159171f2add27fabeabf4b0fbaa36f2318 100644 --- a/cgit.h +++ b/cgit.h @@ -174,6 +174,7 @@ int enable_index_links; int enable_log_filecount; int enable_log_linecount; int local_time; + int linenumbers; int max_repo_count; int max_commit_count; int max_lock_attempts; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 3c35b02ad5b6eb8983e3144a8796db6591e2b50a..a762ccc7c3e96aecbe8aee4817b09998bb1d62c6 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -146,6 +146,10 @@ Url loaded when clicking on the cgit logo image. If unspecified the calculated url of the repository index page will be used. Default value: none. +linenumbers:: + If set to "1" lines in tree view will have numbers. + Default value: "0". + max-commit-count:: Specifies the number of entries to list per page in "log" view. Default value: "50". diff --git a/ui-tree.c b/ui-tree.c index 7bf2ad2cc409ac80173c454135e1a18624637c9b..f64e6e0d701ebf73c06c2bcebebb712abcd69859 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -23,19 +23,24 @@ "%1$d\n"; html("<table summary='blob content' class='blob'>\n"); - html("<tr><td class='linenumbers'><pre>"); - idx = 0; - lineno = 0; - - if (size) { - htmlf(numberfmt, ++lineno); - while(idx < size - 1) { // skip absolute last newline - if (buf[idx] == '\n') - htmlf(numberfmt, ++lineno); - idx++; + if (ctx.cfg.linenumbers) { + html("<tr><td class='linenumbers'><pre>"); + idx = 0; + lineno = 0; + + if (size) { + htmlf(numberfmt, ++lineno); + while(idx < size - 1) { // skip absolute last newline + if (buf[idx] == '\n') + htmlf(numberfmt, ++lineno); + idx++; + } } + html("</pre></td>\n"); } - html("</pre></td>\n"); + else { + html("<tr>\n"); + } if (ctx.repo->source_filter) { html("<td class='lines'><pre><code>");