Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Offer the versions as an option
enable-version-info brings back the cgit and git versions that 3a00e19
took off the footer and the generator tag, for a site that wants them,
and the version 2a6726a put on the signature of patches now follows it
too. It stays off by default for the reason 3a00e19 gave.
| -rw-r--r-- | MANUAL.txt | 8 | |
| -rw-r--r-- | custom/cgitrc | 6 | |
| -rw-r--r-- | source/cgit.c | 2 | |
| -rw-r--r-- | source/cgit.h | 1 | |
| -rw-r--r-- | source/ui-patch.c | 8 | |
| -rw-r--r-- | source/ui-shared.c | 10 | |
| -rwxr-xr-x | tests/t0005-markup.sh | 22 | |
| -rwxr-xr-x | tests/t0109-patch.sh | 18 |
8 files changed, 68 insertions, 7 deletions
@@ -287,6 +287,14 @@ enable-tree-linenumbers:: Flag which, when set to "1", makes cgit generate linenumber links for plaintext blobs printed in the tree and blame pages. Default value: "1". +enable-version-info:: + Flag which, when set to "1", names the cgit and git versions in the + standard page footer and the generator meta tag, and the cgit version + in the signature that ends each patch. Exact versions help someone + match a site against published advisories, so they are left out unless + a site asks for them, and a footer set with footer replaces the + standard one either way. Default value: "0". + favicon:: Url used as link to the icon for cgit. Any path works, but keeping the value "/favicon.ico" is still worthwhile, since clients that do not diff --git a/custom/cgitrc b/custom/cgitrc index 569feb4..86f00aa 100644 --- a/custom/cgitrc +++ b/custom/cgitrc @@ -241,6 +241,12 @@ enable-html-serving=0 # Values are 0 or 1. Default is 1. enable-tree-linenumbers=1 +# Name the cgit and git versions in the page footer, the generator tag and +# the signature of patches. Exact versions help someone match a site against +# advisories, so they stay out unless asked for. Values are 0 or 1. Default +# is 0. +enable-version-info=0 + # List directories first, then files, in the tree page. Values are 0 or 1. # Default is 0. enable-tree-group-dirs=0 diff --git a/source/cgit.c b/source/cgit.c index efcb703..eaf1d19 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -586,6 +586,8 @@ static void apply_config(const char *name, const char *value) ctx.cfg.enable_html_serving = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); + else if (!strcmp(name, "enable-version-info")) + ctx.cfg.enable_version_info = atoi(value); else if (!strcmp(name, "enable-tree-group-dirs")) ctx.cfg.enable_tree_group_dirs = atoi(value); else if (!strcmp(name, "enable-git-config")) diff --git a/source/cgit.h b/source/cgit.h index c04193f..5e17a3e 100644 --- a/source/cgit.h +++ b/source/cgit.h @@ -227,6 +227,7 @@ struct cgit_config { int embedded; int trust_scan_config; int enable_follow_links; + int enable_version_info; int enable_gitmodules_links; int enable_header; int enable_http_clone; diff --git a/source/ui-patch.c b/source/ui-patch.c index 78c850c..04083fe 100644 --- a/source/ui-patch.c +++ b/source/ui-patch.c @@ -132,7 +132,8 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref cgit_print_http_headers(); // git format-patch signs with its bare version number, so the v that - // cgit's tags carry is left off to read the same way. + // cgit's tags carry is left off to read the same way. Without + // enable-version-info the signature names cgit alone. if (!skip_prefix(cgit_version, "v", &version)) version = cgit_version; @@ -141,6 +142,9 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref // Two dashes and a space is the mail signature separator, so // git am and mail readers drop the version note below rather // than carrying it into the commit message. - printf("-- \ncgit %s\n\n", version); + if (ctx.cfg.enable_version_info) + printf("-- \ncgit %s\n\n", version); + else + printf("-- \ncgit\n\n"); } } diff --git a/source/ui-shared.c b/source/ui-shared.c index 8da9878..936a6a4 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1558,7 +1558,10 @@ void cgit_print_docstart(void) html_attr(ctx.cfg.root_desc); html("'>\n"); } - html("<meta name='generator' content='cgit'>\n"); + if (ctx.cfg.enable_version_info) + htmlf("<meta name='generator' content='cgit %s'>\n", cgit_version); + else + html("<meta name='generator' content='cgit'>\n"); if (ctx.cfg.robots && *ctx.cfg.robots) { html("<meta name='robots' content='"); html_attr(ctx.cfg.robots); @@ -1615,6 +1618,11 @@ void cgit_print_docend(void) } if (ctx.cfg.footer) html_include(ctx.cfg.footer); + else if (ctx.cfg.enable_version_info) + htmlf("<footer class='footer'>generated by " + "<a href='https://github.com/brycekwon/cgit'>cgit %s</a> " + "(<a href='https://git-scm.com/'>git %s</a>)</footer>\n", + cgit_version, git_version_string); else html("<footer class='footer'>generated by <a href='https://github.com/brycekwon/cgit'>cgit</a></footer>\n"); html("</div>\n"); diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh index 52d9e34..5fa866d 100755 --- a/tests/t0005-markup.sh +++ b/tests/t0005-markup.sh @@ -44,6 +44,28 @@ test_expect_success 'the landmarks and the search form are in place' ' grep "<footer class=.footer.>" tmp ' +test_expect_success 'the pages name the versions only when asked to' ' + hooks "hooks/" >footer && + grep "<meta name=.generator. content=.cgit.>" footer && + grep "<footer class=.footer.>generated by <a href=[^>]*>cgit</a></footer>" footer && + { + echo "enable-version-info=1" && + cat hooksrc + } >versionrc && + CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=hooks/" cgit >footer && + grep "<meta name=.generator. content=.cgit v[0-9][^>]*>" footer && + grep "<footer class=.footer.>generated by <a href=[^>]*>cgit v[0-9][^<]*</a> (<a href=[^>]*>git [0-9][^<]*</a>)</footer>" footer && + echo "<footer>our own</footer>" >footer.html && + { + echo "enable-version-info=1" && + echo "footer=$PWD/footer.html" && + cat hooksrc + } >versionrc && + CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=hooks/" cgit >footer && + grep "<footer>our own</footer>" footer && + ! grep "git-scm" footer +' + test_expect_success 'the listings name themselves, their sections and their rows' ' grep "<table class=.list log. aria-label=.Commits.>" tmp && grep "<tbody class=.log.>" tmp && diff --git a/tests/t0109-patch.sh b/tests/t0109-patch.sh index 0c4bf8c..6840f0c 100755 --- a/tests/t0109-patch.sh +++ b/tests/t0109-patch.sh @@ -12,9 +12,10 @@ test_description='Check content on patch page' # tag, as git writes its own. CGIT_VERSION=$(sed -n "s/CGIT_VERSION = v\{0,1\}//p" "$TEST_OUTPUT_DIRECTORY/../build/VERSION") -# The signature sits on the second-to-last line, above the trailing blank. +# The signature sits on the second-to-last line, above the trailing blank, +# and names the version only when enable-version-info asks for it. check_cgit_signature() { - tail -2 tmp | head -1 | grep -x -F "cgit $CGIT_VERSION" + tail -2 tmp | head -1 | grep -x -F "cgit${1:+ $1}" } test_expect_success 'generate foo/patch' ' @@ -39,7 +40,7 @@ test_expect_success 'find `cgit` signature' ' test_expect_success 'compare with output of git-format-patch(1)' ' git --git-dir="$PWD/repos/foo/.git" format-patch --subject-prefix="" \ - --signature="cgit $CGIT_VERSION" --stdout HEAD^ >tmp2 && + --signature="cgit" --stdout HEAD^ >tmp2 && strip_headers <tmp >tmp_ && test_cmp tmp_ tmp2 ' @@ -68,7 +69,7 @@ test_expect_success 'find `cgit` signature on the range' ' test_expect_success 'compare the range with git-format-patch(1)' ' git --git-dir="$PWD/repos/foo/.git" format-patch --subject-prefix="" \ - -N --signature="cgit $CGIT_VERSION" --stdout HEAD~3..HEAD >tmp2 && + -N --signature="cgit" --stdout HEAD~3..HEAD >tmp2 && strip_headers <tmp >tmp_ && test_cmp tmp_ tmp2 ' @@ -86,4 +87,13 @@ test_expect_success 'max-patch-count bounds a patch range' ' test $(grep -c "^From " tmp) -eq 2 ' +test_expect_success 'the signature names the version when asked to' ' + { + echo "enable-version-info=1" && + sed "s/^cache-size=.*/cache-size=0/" cgitrc + } >versionrc && + CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=foo/patch" cgit >tmp && + check_cgit_signature "$CGIT_VERSION" +' + test_done |
