{"thread":{"id":"22454","subject":"[PATCH 0/8] Miscelanous gitweb improvements from 'Gitweb caching v5' by J.H.","startedAt":"2010-01-30T22:30:37Z","lastAt":"2010-02-02T05:26:55Z","messageCount":14,"participants":["Jakub Narebski","Junio C Hamano","J.H."],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"133144","messageId":"1264890645-28310-1-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":null,"subject":"[PATCH 0/8] Miscelanous gitweb improvements from 'Gitweb caching v5' by J.H.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:37Z","receivedAt":"2010-01-30T22:30:37Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"This series of patches consist of improved and reordered, and rebased early\nparts (1-7) of \"[PATCH 0/9] Gitweb caching v5\" thread by John 'Warthog9'\nHawley.  Those patches are also available from\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\nI have added signoff where it was missing, and changed all authorship\nof patches by J.H. to use @kernel.org email address.\n\nPull request:\n~~~~~~~~~~~~~\nThe following changes since commit 3a985c27fe8bb9ed2fa9580a27c4b4dd7c7192ea:\n  Junio C Hamano (1):\n        Update draft release notes to 1.7.0\n\nare available in the git repository at:\n\n  git://repo.or.cz/git/jnareb-git.git gitweb/gitweb-ml-v5\n\nTable of contents:\n~~~~~~~~~~~~~~~~~~\n [PATCH 1/8] gitweb: Make running t9501 test with '--debug' reliable and usable\n [PATCH 2/8] gitweb: Load checking\n [PATCH 3/8] gitweb: Makefile improvements\n [PATCH 4/8] gitweb: Check that $site_header etc. are defined before using them\n [PATCH 5/8] gitweb: add a get function to compliment print_local_time\n [PATCH 6/8] gitweb: add a get function to compliment print_sort_th\n [PATCH 7/8] gitweb: Add optional extra parameter to die_error, for extended explanation\n [PATCH 8/8] gitweb: Add an option to force version match\n\nFirst patch in series is my addition, made to be able to run t9501 test in\n'debug' mode without it screwing terminal due to dumping (binary!) snapshot\nto it.  All patches in series passes t9500, t9501 and t9502; it allowed to\nfind bugs in their implementation.\n\nI have reordered patches so those that are less controversial and more\nready to be applied come first, and those that are a bit controversial and\nperhaps less ready later (and also later those patches that introduce new\nfeature without any user for it).\n\nThe patches 5 and 6 \"add a get function\" introduce new format_* functions\nwhich do not have yet any user in gitweb.\n\nPatch 7 \"optional extra parameter to die_error\" is used only in patch 8,\nbut it would be I think good feature to have anyway.\n\nIn patch 8 the $git_versions_must_match variable is again set to 0 (off) by\ndefault; Pasky's complaint in\n  Message-ID: <20100124215924.GA9553@machine.or.cz>\n  http://permalink.gmane.org/gmane.comp.version-control.git/137922\nmade me notice (see my reply to it) that it could be very hard to explain\nhow to setup gitweb to turn this feature off, in some rare cases.  So it is\nagain off, and with more detailed explanation of an error.\n\nNote that like 'Gitweb caching v5' thread this series is missing\n  gitweb: Optionally add \"git\" links in project list page\nthat was present in 'Gitweb caching v2' and 'Miscelanous gitweb\nimprovements from J.H.' threads.\n\nDiffstat:\n~~~~~~~~~\n Makefile                                 |   65 +++------------\n gitweb/Makefile                          |  129 ++++++++++++++++++++++++++++++\n gitweb/README                            |   12 +++-\n gitweb/gitweb.perl                       |  121 ++++++++++++++++++++++++----\n t/gitweb-lib.sh                          |    2 +\n t/t9501-gitweb-standalone-http-status.sh |   57 ++++++++++++-\n 6 files changed, 309 insertions(+), 77 deletions(-)\n create mode 100644 gitweb/Makefile\n\n-- \nJakub Narebski\nPoland\n"},{"id":"133146","messageId":"1264890645-28310-2-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 1/8 v1] gitweb: Make running t9501 test with '--debug' reliable and usable","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:38Z","receivedAt":"2010-01-30T22:30:38Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Remove test_debug lines after 'snapshots: tgz only default format\nenabled' and 'snapshots: all enabled in default, use default disabled\nvalue' tests.  Those tests constitute of multiple gitweb_run\ninvocation, therefore outputting gitweb.output for the last gitweb_run\nwouldn't help much in debugging test failure, and can only confuse.\n\nFor snapshot tests which check for \"200 OK\" status, change\n  test_debug 'cat gitweb.output'\nto\n  test_debug 'cat gitweb.headers'\nOtherwise when running this test with '--debug' option,\nt/t9501-gitweb-standalone-http-status.sh would dump *binary data* (the\nsnapshot itself) to standard output, which can mess up state of terminal\ndue to term control characters which can be embedded in output.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis patch appears in this series for the first time.\n\nI have decided against cleaning up t/t9501-gitweb-standalone-http-status.sh\nby conforming to single style of quoting and whitespaces, and by putting \ninitial test_commit inside test_expect_success setup.  This is the minimal\nchange.\n\n t/t9501-gitweb-standalone-http-status.sh |    8 +++-----\n 1 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh\nindex 0688a57..9e8bc01 100755\n--- a/t/t9501-gitweb-standalone-http-status.sh\n+++ b/t/t9501-gitweb-standalone-http-status.sh\n@@ -33,7 +33,6 @@ test_expect_success \\\n     grep \"403 - Snapshot format not allowed\" gitweb.output &&\n     gitweb_run \"p=.git;a=snapshot;h=HEAD;sf=zip\" &&\n     grep \"403 - Unsupported snapshot format\" gitweb.output'\n-test_debug 'cat gitweb.output'\n \n \n cat >>gitweb_config.perl <<\\EOF\n@@ -50,7 +49,6 @@ test_expect_success \\\n     grep \"403 - Snapshot format not allowed\" gitweb.output &&\n     gitweb_run \"p=.git;a=snapshot;h=HEAD;sf=zip\" &&\n     grep \"Status: 200 OK\" gitweb.output'\n-test_debug 'cat gitweb.output'\n \n \n cat >>gitweb_config.perl <<\\EOF\n@@ -72,7 +70,7 @@ test_expect_success \\\n     'snapshots: tgz explicitly enabled' \\\n     'gitweb_run \"p=.git;a=snapshot;h=HEAD;sf=tgz\" &&\n     grep \"Status: 200 OK\" gitweb.output'\n-test_debug 'cat gitweb.output'\n+test_debug 'cat gitweb.headers'\n \n \n # ----------------------------------------------------------------------\n@@ -82,7 +80,7 @@ test_expect_success 'snapshots: good tree-ish id' '\n \tgitweb_run \"p=.git;a=snapshot;h=master;sf=tgz\" &&\n \tgrep \"Status: 200 OK\" gitweb.output\n '\n-test_debug 'cat gitweb.output'\n+test_debug 'cat gitweb.headers'\n \n test_expect_success 'snapshots: bad tree-ish id' '\n \tgitweb_run \"p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz\" &&\n@@ -105,7 +103,7 @@ test_expect_success 'snapshots: good object id' '\n \tgitweb_run \"p=.git;a=snapshot;h=$ID;sf=tgz\" &&\n \tgrep \"Status: 200 OK\" gitweb.output\n '\n-test_debug 'cat gitweb.output'\n+test_debug 'cat gitweb.headers'\n \n test_expect_success 'snapshots: bad object id' '\n \tgitweb_run \"p=.git;a=snapshot;h=abcdef01234;sf=tgz\" &&\n-- \n1.6.6.1\n"},{"id":"133150","messageId":"1264890645-28310-3-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 2/8 v6] gitweb: Load checking","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:39Z","receivedAt":"2010-01-30T22:30:39Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nThis changes slightly the behavior of gitweb, so that it verifies\nthat the box isn't inundated with before attempting to serve gitweb.\nIf the box is overloaded, it basically returns a 503 Server Unavailable\nuntil the load falls below the defined threshold.  This helps dramatically\nif you have a box that's I/O bound, reaches a certain load and you\ndon't want gitweb, the I/O hog that it is, increasing the pain the\nserver is already undergoing.\n\nThis behavior is controlled by $maxload configuration variable.\nDefault is a load of 300, which for most cases should never be hit.\nUnset it (set it to undefined value, i.e. undef) to turn off checking.\n\nCurrently it requires that '/proc/loadavg' file exists, otherwise the\nload check is bypassed (load is taken to be 0).  So platforms that do\nnot implement '/proc/loadavg' currently cannot use this feature\n(provisions are included for additional checks to be added by others).\n\nThere is simple test in t/t9501-gitweb-standalone-http-status.sh to\ncheck that it correctly returns \"503 Service Unavailable\" if load is\ntoo high, and also if there are any Perl warnings or errors.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nChanges from version from 'Gitweb caching v5' and\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n* Load checking was moved after setting $git_version, as this variable\n  is used in git_header_html, which in turn is used in die_error.  \n  Otherwise we would get \"Use of unitialized value\" warning.\n\n* In git_footer_html we check if $action is defined before comparing\n  it with 'blame_incremental'.  This is first time that git_footer_html\n  can be called (via die_error) with $action undefined; earlier all calls\n  to git_footer_html were after dispatch, which set $action to appropriate\n  default value if it was not set (actionless gitweb URL, e.g. projects\n  list or project summary).  Otherise we would get \"Use of unitialized\n  value\" warning.\n\n* t/gitweb-lib.sh turns off load checking, just in case.\n\n* There was added test for this feature to t9501, for the simplest case\n  of $maxload set to 0.\n\n\n gitweb/README                            |    7 ++++-\n gitweb/gitweb.perl                       |   48 ++++++++++++++++++++++++++---\n t/gitweb-lib.sh                          |    1 +\n t/t9501-gitweb-standalone-http-status.sh |   22 +++++++++++++\n 4 files changed, 72 insertions(+), 6 deletions(-)\n mode change 100644 => 100755 t/gitweb-lib.sh\n\ndiff --git a/gitweb/README b/gitweb/README\nindex e34ee79..6c2c8e1 100644\n--- a/gitweb/README\n+++ b/gitweb/README\n@@ -174,7 +174,7 @@ not include variables usually directly set during build):\n    Base URL for relative URLs in pages generated by gitweb,\n    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n    needed and used only for URLs with nonempty PATH_INFO via\n-   <base href=\"$base_url>.  Usually gitweb sets its value correctly,\n+   <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n    and there is no need to set this variable, e.g. to $my_uri or \"/\".\n  * $home_link\n    Target of the home link on top of all pages (the first part of view\n@@ -228,6 +228,11 @@ not include variables usually directly set during build):\n    repositories from launching cross-site scripting (XSS) attacks.  Set this\n    to true if you don't trust the content of your repositories. The default\n    is false.\n+ * $maxload\n+   Used to set the maximum load that we will still respond to gitweb queries.\n+   If server load exceed this value then return \"503 Service Unavaliable\" error.\n+   Server load is taken to be 0 if gitweb cannot determine its value.  Set it to\n+   undefined value to turn it off.  The default is 300.\n \n \n Projects list file format\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 7e477af..e2522cc 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -221,6 +221,12 @@ our %avatar_size = (\n \t'double'  => 32\n );\n \n+# Used to set the maximum load that we will still respond to gitweb queries.\n+# If server load exceed this value then return \"503 server busy\" error.\n+# If gitweb cannot determined server load, it is taken to be 0.\n+# Leave it undefined (or set to 'undef') to turn off load checking.\n+our $maxload = 300;\n+\n # You define site-wide feature defaults here; override them with\n # $GITWEB_CONFIG as necessary.\n our %feature = (\n@@ -551,12 +557,38 @@ if (-e $GITWEB_CONFIG) {\n \tdo $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;\n }\n \n+# Get loadavg of system, to compare against $maxload.\n+# Currently it requires '/proc/loadavg' present to get loadavg;\n+# if it is not present it returns 0, which means no load checking.\n+sub get_loadavg {\n+\tif( -e '/proc/loadavg' ){\n+\t\topen my $fd, '<', '/proc/loadavg'\n+\t\t\tor return 0;\n+\t\tmy @load = split(/\\s+/, scalar <$fd>);\n+\t\tclose $fd;\n+\n+\t\t# The first three columns measure CPU and IO utilization of the last one,\n+\t\t# five, and 10 minute periods.  The fourth column shows the number of\n+\t\t# currently running processes and the total number of processes in the m/n\n+\t\t# format.  The last column displays the last process ID used.\n+\t\treturn $load[0] || 0;\n+\t}\n+\t# additional checks for load average should go here for things that don't export\n+\t# /proc/loadavg\n+\n+\treturn 0;\n+}\n+\n # version of the core git binary\n our $git_version = qx(\"$GIT\" --version) =~ m/git version (.*)$/ ? $1 : \"unknown\";\n $number_of_git_cmds++;\n \n $projects_list ||= $projectroot;\n \n+if (defined $maxload && get_loadavg() > $maxload) {\n+\tdie_error(503, \"The load average on the server is too high\");\n+}\n+\n # ======================================================================\n # input validation and dispatch\n \n@@ -3328,7 +3360,8 @@ sub git_footer_html {\n \t}\n \n \tprint qq!<script type=\"text/javascript\" src=\"$javascript\"></script>\\n!;\n-\tif ($action eq 'blame_incremental') {\n+\tif (defined $action &&\n+\t    $action eq 'blame_incremental') {\n \t\tprint qq!<script type=\"text/javascript\">\\n!.\n \t\t      qq!startBlame(\"!. href(action=>\"blame_data\", -replay=>1) .qq!\",\\n!.\n \t\t      qq!           \"!. href() .qq!\");\\n!.\n@@ -3354,14 +3387,19 @@ sub git_footer_html {\n # 500: The server isn't configured properly, or\n #      an internal error occurred (e.g. failed assertions caused by bugs), or\n #      an unknown error occurred (e.g. the git binary died unexpectedly).\n+# 503: The server is currently unavailable (because it is overloaded,\n+#      or down for maintenance).  Generally, this is a temporary state.\n sub die_error {\n \tmy $status = shift || 500;\n \tmy $error = shift || \"Internal server error\";\n \n-\tmy %http_responses = (400 => '400 Bad Request',\n-\t\t\t      403 => '403 Forbidden',\n-\t\t\t      404 => '404 Not Found',\n-\t\t\t      500 => '500 Internal Server Error');\n+\tmy %http_responses = (\n+\t\t400 => '400 Bad Request',\n+\t\t403 => '403 Forbidden',\n+\t\t404 => '404 Not Found',\n+\t\t500 => '500 Internal Server Error',\n+\t\t503 => '503 Service Unavailable',\n+\t);\n \tgit_header_html($http_responses{$status});\n \tprint <<EOF;\n <div class=\"page_body\">\ndiff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh\nold mode 100644\nnew mode 100755\nindex 76d8b7b..5a734b1\n--- a/t/gitweb-lib.sh\n+++ b/t/gitweb-lib.sh\n@@ -25,6 +25,7 @@ our \\$favicon = 'file:///$TEST_DIRECTORY/../gitweb/git-favicon.png';\n our \\$projects_list = '';\n our \\$export_ok = '';\n our \\$strict_export = '';\n+our \\$maxload = undef;\n \n EOF\n \ndiff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh\nindex 9e8bc01..7590f10 100755\n--- a/t/t9501-gitweb-standalone-http-status.sh\n+++ b/t/t9501-gitweb-standalone-http-status.sh\n@@ -112,4 +112,26 @@ test_expect_success 'snapshots: bad object id' '\n test_debug 'cat gitweb.output'\n \n \n+# ----------------------------------------------------------------------\n+# load checking\n+\n+# always hit the load limit\n+cat >>gitweb_config.perl <<\\EOF\n+our $maxload = 0;\n+EOF\n+\n+test_expect_success 'load checking: load too high (default action)' '\n+\tgitweb_run \"p=.git\" &&\n+\tgrep \"Status: 503 Service Unavailable\" gitweb.headers &&\n+\tgrep \"503 - The load average on the server is too high\" gitweb.body\n+'\n+test_debug 'cat gitweb.log' # just in case\n+test_debug 'cat gitweb.headers'\n+\n+# turn off load checking\n+cat >>gitweb_config.perl <<\\EOF\n+our $maxload = undef;\n+EOF\n+\n+\n test_done\n-- \n1.6.6.1\n"},{"id":"133147","messageId":"1264890645-28310-4-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 3/8 v6] gitweb: Makefile improvements","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:40Z","receivedAt":"2010-01-30T22:30:40Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nThis commit adjust the main Makefile so you can simply run\n\n     make gitweb\n\nwhich in turn calls gitweb/Makefile.  This means that in order to\ngenerate gitweb, you can simply run 'make' from gitweb subdirectory:\n\n     cd gitweb\n     make\n\nTargets gitweb/gitweb.cgi and (dependent on JSMIN being defined)\ngitweb/gitweb.min.js in main Makefile are preserved for backward\ncompatibility.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis patch is unchanged from the version from 'Gitweb caching v5':\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n Makefile        |   65 +++++----------------------\n gitweb/Makefile |  129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 141 insertions(+), 53 deletions(-)\n create mode 100644 gitweb/Makefile\n\ndiff --git a/Makefile b/Makefile\nindex af08c8f..eb0fffb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -278,29 +278,6 @@ pathsep = :\n # JavaScript minifier invocation that can function as filter\n JSMIN =\n \n-# default configuration for gitweb\n-GITWEB_CONFIG = gitweb_config.perl\n-GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf\n-GITWEB_HOME_LINK_STR = projects\n-GITWEB_SITENAME =\n-GITWEB_PROJECTROOT = /pub/git\n-GITWEB_PROJECT_MAXDEPTH = 2007\n-GITWEB_EXPORT_OK =\n-GITWEB_STRICT_EXPORT =\n-GITWEB_BASE_URL =\n-GITWEB_LIST =\n-GITWEB_HOMETEXT = indextext.html\n-GITWEB_CSS = gitweb.css\n-GITWEB_LOGO = git-logo.png\n-GITWEB_FAVICON = git-favicon.png\n-ifdef JSMIN\n-GITWEB_JS = gitweb.min.js\n-else\n-GITWEB_JS = gitweb.js\n-endif\n-GITWEB_SITE_HEADER =\n-GITWEB_SITE_FOOTER =\n-\n export prefix bindir sharedir sysconfdir\n \n CC = gcc\n@@ -1538,6 +1515,11 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl\n \tchmod +x $@+ && \\\n \tmv $@+ $@\n \n+\n+.PHONY: gitweb\n+gitweb:\n+\t$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all\n+\n ifdef JSMIN\n OTHER_PROGRAMS += gitweb/gitweb.cgi   gitweb/gitweb.min.js\n gitweb/gitweb.cgi: gitweb/gitweb.perl gitweb/gitweb.min.js\n@@ -1545,30 +1527,13 @@ else\n OTHER_PROGRAMS += gitweb/gitweb.cgi\n gitweb/gitweb.cgi: gitweb/gitweb.perl\n endif\n-\t$(QUIET_GEN)$(RM) $@ $@+ && \\\n-\tsed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \\\n-\t    -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \\\n-\t    -e 's|++GIT_BINDIR++|$(bindir)|g' \\\n-\t    -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \\\n-\t    -e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \\\n-\t    -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \\\n-\t    -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \\\n-\t    -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \\\n-\t    -e 's|\"++GITWEB_PROJECT_MAXDEPTH++\"|$(GITWEB_PROJECT_MAXDEPTH)|g' \\\n-\t    -e 's|++GITWEB_EXPORT_OK++|$(GITWEB_EXPORT_OK)|g' \\\n-\t    -e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \\\n-\t    -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \\\n-\t    -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \\\n-\t    -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \\\n-\t    -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \\\n-\t    -e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \\\n-\t    -e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \\\n-\t    -e 's|++GITWEB_JS++|$(GITWEB_JS)|g' \\\n-\t    -e 's|++GITWEB_SITE_HEADER++|$(GITWEB_SITE_HEADER)|g' \\\n-\t    -e 's|++GITWEB_SITE_FOOTER++|$(GITWEB_SITE_FOOTER)|g' \\\n-\t    $< >$@+ && \\\n-\tchmod +x $@+ && \\\n-\tmv $@+ $@\n+\t$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)\n+\n+ifdef JSMIN\n+gitweb/gitweb.min.js: gitweb/gitweb.js\n+\t$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)\n+endif # JSMIN\n+\n \n git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.js\n \t$(QUIET_GEN)$(RM) $@ $@+ && \\\n@@ -1595,12 +1560,6 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)) git-instaweb: % : unimplemented.sh\n \tmv $@+ $@\n endif # NO_PERL\n \n-\n-ifdef JSMIN\n-gitweb/gitweb.min.js: gitweb/gitweb.js\n-\t$(QUIET_GEN)$(JSMIN) <$< >$@\n-endif # JSMIN\n-\n ifndef NO_PYTHON\n $(patsubst %.py,%,$(SCRIPT_PYTHON)): GIT-CFLAGS\n $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py\ndiff --git a/gitweb/Makefile b/gitweb/Makefile\nnew file mode 100644\nindex 0000000..c9eb1ee\n--- /dev/null\n+++ b/gitweb/Makefile\n@@ -0,0 +1,129 @@\n+# The default target of this Makefile is...\n+all::\n+\n+# Define V=1 to have a more verbose compile.\n+#\n+# Define JSMIN to point to JavaScript minifier that functions as\n+# a filter to have gitweb.js minified.\n+#\n+\n+prefix ?= $(HOME)\n+bindir ?= $(prefix)/bin\n+RM ?= rm -f\n+\n+# JavaScript minifier invocation that can function as filter\n+JSMIN ?=\n+\n+# default configuration for gitweb\n+GITWEB_CONFIG = gitweb_config.perl\n+GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf\n+GITWEB_HOME_LINK_STR = projects\n+GITWEB_SITENAME =\n+GITWEB_PROJECTROOT = /pub/git\n+GITWEB_PROJECT_MAXDEPTH = 2007\n+GITWEB_EXPORT_OK =\n+GITWEB_STRICT_EXPORT =\n+GITWEB_BASE_URL =\n+GITWEB_LIST =\n+GITWEB_HOMETEXT = indextext.html\n+GITWEB_CSS = gitweb.css\n+GITWEB_LOGO = git-logo.png\n+GITWEB_FAVICON = git-favicon.png\n+ifdef JSMIN\n+GITWEB_JS = gitweb.min.js\n+else\n+GITWEB_JS = gitweb.js\n+endif\n+GITWEB_SITE_HEADER =\n+GITWEB_SITE_FOOTER =\n+\n+# include user config\n+-include ../config.mak.autogen\n+-include ../config.mak\n+\n+# determine version\n+../GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n+\t$(QUIET_SUBDIR0)../ $(QUIET_SUBDIR1) GIT-VERSION-FILE\n+\n+-include ../GIT-VERSION-FILE\n+\n+### Build rules\n+\n+SHELL_PATH ?= $(SHELL)\n+PERL_PATH  ?= /usr/bin/perl\n+\n+# Shell quote;\n+bindir_SQ = $(subst ','\\'',$(bindir))         #'\n+SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH)) #'\n+PERL_PATH_SQ  = $(subst ','\\'',$(PERL_PATH))  #'\n+\n+# Quiet generation (unless V=1)\n+QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir\n+QUIET_SUBDIR1  =\n+\n+ifneq ($(findstring $(MAKEFLAGS),w),w)\n+PRINT_DIR = --no-print-directory\n+else # \"make -w\"\n+NO_SUBDIR = :\n+endif\n+\n+ifneq ($(findstring $(MAKEFLAGS),s),s)\n+ifndef V\n+\tQUIET          = @\n+\tQUIET_GEN      = $(QUIET)echo '   ' GEN $@;\n+\tQUIET_SUBDIR0  = +@subdir=\n+\tQUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \\\n+\t                 $(MAKE) $(PRINT_DIR) -C $$subdir\n+\texport V\n+\texport QUIET\n+\texport QUIET_GEN\n+\texport QUIET_SUBDIR0\n+\texport QUIET_SUBDIR1\n+endif\n+endif\n+\n+all:: gitweb.cgi\n+\n+ifdef JSMIN\n+FILES=gitweb.cgi gitweb.min.js\n+gitweb.cgi: gitweb.perl gitweb.min.js\n+else # !JSMIN\n+FILES=gitweb.cgi\n+gitweb.cgi: gitweb.perl\n+endif # JSMIN\n+\n+gitweb.cgi:\n+\t$(QUIET_GEN)$(RM) $@ $@+ && \\\n+\tsed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \\\n+\t    -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \\\n+\t    -e 's|++GIT_BINDIR++|$(bindir)|g' \\\n+\t    -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \\\n+\t    -e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \\\n+\t    -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \\\n+\t    -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \\\n+\t    -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \\\n+\t    -e 's|\"++GITWEB_PROJECT_MAXDEPTH++\"|$(GITWEB_PROJECT_MAXDEPTH)|g' \\\n+\t    -e 's|++GITWEB_EXPORT_OK++|$(GITWEB_EXPORT_OK)|g' \\\n+\t    -e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \\\n+\t    -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \\\n+\t    -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \\\n+\t    -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \\\n+\t    -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \\\n+\t    -e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \\\n+\t    -e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \\\n+\t    -e 's|++GITWEB_JS++|$(GITWEB_JS)|g' \\\n+\t    -e 's|++GITWEB_SITE_HEADER++|$(GITWEB_SITE_HEADER)|g' \\\n+\t    -e 's|++GITWEB_SITE_FOOTER++|$(GITWEB_SITE_FOOTER)|g' \\\n+\t    $< >$@+ && \\\n+\tchmod +x $@+ && \\\n+\tmv $@+ $@\n+\n+ifdef JSMIN\n+gitweb.min.js: gitweb.js\n+\t$(QUIET_GEN)$(JSMIN) <$< >$@\n+endif # JSMIN\n+\n+clean:\n+\t$(RM) $(FILES)\n+\n+.PHONY: all clean .FORCE-GIT-VERSION-FILE\n-- \n1.6.6.1\n"},{"id":"133145","messageId":"1264890645-28310-5-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 4/8 v6] gitweb: Check that $site_header etc. are defined before using them","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:41Z","receivedAt":"2010-01-30T22:30:41Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nIf one of $site_header, $site_footer or $home_text is not defined you\nget extraneous errors in the web logs, for example (line wrapped for\nbetter readibility):\n\n [Wed Jan 13 16:55:42 2010] [error] [client ::1] [Wed Jan 13 16:55:42 2010]\n gitweb.cgi: Use of uninitialized value $site_header in -f at\n /var/www/gitweb/gitweb.cgi line 3287., referer: http://git/gitweb.cgi\n\nThis ensures that those variables are defined before trying to use it.\n\nNote that such error can happen only because of an error in gitweb\nconfig file; building gitweb.cgi can make mentioned variables holding\nempty string (it is even the default), but they not undefined.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nChanges from version from 'Gitweb caching v5' and\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n* Check explicitly that $site_header is defined, and not only that it\n  is false-ish\n* Check also for $site_footer and $home_text being defined\n* Slightly more detailed commit message\n\n\nI have decided not to protect against undefined $projects_list, as\nsuch check would have to be more complicated and quite different from\nchecks for $site_header, $site_footer and $home_text.\n\nNote that it is purely defensive programming, as this should not\nhappen unless there are very strange errors in gitweb config file.\n\n gitweb/gitweb.perl |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex e2522cc..a4148d3 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3254,7 +3254,7 @@ EOF\n \tprint \"</head>\\n\" .\n \t      \"<body>\\n\";\n \n-\tif (-f $site_header) {\n+\tif (defined $site_header && -f $site_header) {\n \t\tinsert_file($site_header);\n \t}\n \n@@ -3355,7 +3355,7 @@ sub git_footer_html {\n \t\tprint \"</div>\\n\"; # class=\"page_footer\"\n \t}\n \n-\tif (-f $site_footer) {\n+\tif (defined $site_footer && -f $site_footer) {\n \t\tinsert_file($site_footer);\n \t}\n \n@@ -4781,7 +4781,7 @@ sub git_project_list {\n \t}\n \n \tgit_header_html();\n-\tif (-f $home_text) {\n+\tif (defined $home_text && -f $home_text) {\n \t\tprint \"<div class=\\\"index_include\\\">\\n\";\n \t\tinsert_file($home_text);\n \t\tprint \"</div>\\n\";\n-- \n1.6.6.1\n"},{"id":"133151","messageId":"1264890645-28310-6-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 5/8 v6] gitweb: add a get function to compliment print_local_time","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:42Z","receivedAt":"2010-01-30T22:30:42Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nThis adds a get function (named format_local_time) for print_local_time,\nso that the basic function can be used outside of their straight printing\noperation.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nChanges from version from 'Gitweb caching v5' and\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n* Change function name from get_* to format_*, following gitweb\n  subroutine naming convention.\n* Add final ';'\n\n gitweb/gitweb.perl |   11 +++++++++--\n 1 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex a4148d3..debaf55 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3509,14 +3509,21 @@ sub git_print_header_div {\n }\n \n sub print_local_time {\n+\tprint format_local_time(@_);\n+}\n+\n+sub format_local_time {\n+\tmy $localtime = '';\n \tmy %date = @_;\n \tif ($date{'hour_local'} < 6) {\n-\t\tprintf(\" (<span class=\\\"atnight\\\">%02d:%02d</span> %s)\",\n+\t\t$localtime .= sprintf(\" (<span class=\\\"atnight\\\">%02d:%02d</span> %s)\",\n \t\t\t$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});\n \t} else {\n-\t\tprintf(\" (%02d:%02d %s)\",\n+\t\t$localtime .= sprintf(\" (%02d:%02d %s)\",\n \t\t\t$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});\n \t}\n+\n+\treturn $localtime;\n }\n \n # Outputs the author name and date in long form\n-- \n1.6.6.1\n"},{"id":"133148","messageId":"1264890645-28310-7-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 6/8 v6] gitweb: add a get function to compliment print_sort_th","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:43Z","receivedAt":"2010-01-30T22:30:43Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nThis adds a get function (named format_sort_th) for print_sort_th,\nso that the basic function can be used outside of their straight\nprinting operation.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nChanges from version from 'Gitweb caching v5' and\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n* Change function name from get_* to format_*, following gitweb\n  subroutine naming convention.\n\n gitweb/gitweb.perl |   17 ++++++++++++-----\n 1 files changed, 12 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex debaf55..466fa8a 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -4347,17 +4347,24 @@ sub fill_project_list_info {\n # print 'sort by' <th> element, generating 'sort by $name' replay link\n # if that order is not selected\n sub print_sort_th {\n+\tprint format_sort_th(@_);\n+}\n+\n+sub format_sort_th {\n \tmy ($name, $order, $header) = @_;\n+\tmy $sort_th = \"\";\n \t$header ||= ucfirst($name);\n \n \tif ($order eq $name) {\n-\t\tprint \"<th>$header</th>\\n\";\n+\t\t$sort_th .= \"<th>$header</th>\\n\";\n \t} else {\n-\t\tprint \"<th>\" .\n-\t\t      $cgi->a({-href => href(-replay=>1, order=>$name),\n-\t\t               -class => \"header\"}, $header) .\n-\t\t      \"</th>\\n\";\n+\t\t$sort_th .= \"<th>\" .\n+\t\t            $cgi->a({-href => href(-replay=>1, order=>$name),\n+\t\t                     -class => \"header\"}, $header) .\n+\t\t            \"</th>\\n\";\n \t}\n+\n+\treturn $sort_th;\n }\n \n sub git_project_list_body {\n-- \n1.6.6.1\n"},{"id":"133149","messageId":"1264890645-28310-8-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 7/8 v6] gitweb: Add optional extra parameter to die_error, for extended explanation","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:44Z","receivedAt":"2010-01-30T22:30:44Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nThis is a small change that just adds a 3rd, optional, parameter to die_error\nthat allows for extended error information to be output along with what the\nerror was.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nChanges from version from 'Gitweb caching v5' and\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n* Slightly changed commit summary (commit description).\n* Align with spaces, instead of indenting with tab\n\nThose changes are purely cosmetic; the commit is practically unchanged\nfrom the version by J.H.\n\n gitweb/gitweb.perl |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 466fa8a..d0c3ff2 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3392,6 +3392,7 @@ sub git_footer_html {\n sub die_error {\n \tmy $status = shift || 500;\n \tmy $error = shift || \"Internal server error\";\n+\tmy $extra = shift;\n \n \tmy %http_responses = (\n \t\t400 => '400 Bad Request',\n@@ -3406,8 +3407,13 @@ sub die_error {\n <br /><br />\n $status - $error\n <br />\n-</div>\n EOF\n+\tif (defined $extra) {\n+\t\tprint \"<hr />\\n\" .\n+\t\t      \"$extra\\n\";\n+\t}\n+\tprint \"</div>\\n\";\n+\n \tgit_footer_html();\n \texit;\n }\n-- \n1.6.6.1\n"},{"id":"133152","messageId":"1264890645-28310-9-git-send-email-jnareb@gmail.com","threadId":"22454","inReplyTo":"1264890645-28310-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 8/8 v6] gitweb: Add an option to force version match","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-30T22:30:45Z","receivedAt":"2010-01-30T22:30:45Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: John 'Warthog9' Hawley <warthog9@kernel.org>\n\nThis adds $git_versions_must_match variable, which if set to true,\nchecks that we are running on the same version of git that we\nshipped with, and if not throw '500 Internal Server Error' error.\nWhat is checked is the version of gitweb (embedded in building\ngitweb.cgi), against version of runtime git binary used.\n\nGitweb can usually run with a mismatched git install.  This is more\nhere to give an obvious warning as to what's going on vs. silently\nfailing.\n\nBy default this feature is turned off.\n\nAdd tests to t9501-gitweb-standalone-http-status.sh that this feature\nworks correctly (as expected) if turned on, both in match and no match\ncase.\n\nSigned-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nChanges from version from 'Gitweb caching v5' and\n  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n\n* Again turned off by default\n* More detailed error description, as requested by Petr 'Pasky' Baudis\n  in http://permalink.gmane.org/gmane.comp.version-control.git/137922\n* Which in turn required to set $GITWEB_CONFIG_SYSTEM to be able to\n  use its value in error description; otherwise we would get 'Variable \n  \"$GITWEB_CONFIG_SYSTEM\" is not imported' error.\n* Turn off forcing version matching in t/gitweb-lib.sh\n* Add some tests for this feature in t9501-gitweb-standalone-http-status.sh\n\n gitweb/README                            |    5 +++++\n gitweb/gitweb.perl                       |   29 ++++++++++++++++++++++++++++-\n t/gitweb-lib.sh                          |    1 +\n t/t9501-gitweb-standalone-http-status.sh |   27 +++++++++++++++++++++++++++\n 4 files changed, 61 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/README b/gitweb/README\nindex 6c2c8e1..83a25a9 100644\n--- a/gitweb/README\n+++ b/gitweb/README\n@@ -233,6 +233,11 @@ not include variables usually directly set during build):\n    If server load exceed this value then return \"503 Service Unavaliable\" error.\n    Server load is taken to be 0 if gitweb cannot determine its value.  Set it to\n    undefined value to turn it off.  The default is 300.\n+ * $git_versions_must_match\n+   If set to true value, gitweb fails with \"500 Internal Server Error\" error\n+   if the version of the gitweb doesn't match version of the git binary.\n+   Gitweb can usually run with a mismatched git install.   The default is 0\n+   (false).\n \n \n Projects list file format\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex d0c3ff2..e69efeb 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -221,6 +221,9 @@ our %avatar_size = (\n \t'double'  => 32\n );\n \n+# If it is true, exit if gitweb version and git binary version don't match\n+our $git_versions_must_match = 0;\n+\n # Used to set the maximum load that we will still respond to gitweb queries.\n # If server load exceed this value then return \"503 server busy\" error.\n # If gitweb cannot determined server load, it is taken to be 0.\n@@ -550,10 +553,10 @@ sub filter_snapshot_fmts {\n }\n \n our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || \"++GITWEB_CONFIG++\";\n+our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || \"++GITWEB_CONFIG_SYSTEM++\";\n if (-e $GITWEB_CONFIG) {\n \tdo $GITWEB_CONFIG;\n } else {\n-\tour $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || \"++GITWEB_CONFIG_SYSTEM++\";\n \tdo $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;\n }\n \n@@ -583,6 +586,30 @@ sub get_loadavg {\n our $git_version = qx(\"$GIT\" --version) =~ m/git version (.*)$/ ? $1 : \"unknown\";\n $number_of_git_cmds++;\n \n+# Throw an error if git versions does not match, if $git_versions_must_match is true.\n+if ($git_versions_must_match &&\n+    $git_version ne $version) {\n+\tmy $admin_contact =\n+\t\tdefined $ENV{'SERVER_ADMIN'} ? \", $ENV{'SERVER_ADMIN'},\" : '';\n+\tmy $err_msg = <<EOT;\n+<h1 align=\"center\">*** Warning ***</h1>\n+<p>\n+This version of gitweb was compiled for <b>@{[esc_html($version)]}</b>,\n+however git version <b>@{[esc_html($git_version)]}</b> was found on server,\n+and administrator requested strict version checking by setting\n+\\$git_versions_must_match to @{[esc_html($git_versions_must_match)]}\n+(true value) in gitweb configuration file,\n+'@{[esc_path(-e $GITWEB_CONFIG ? $GITWEB_CONFIG : $GITWEB_CONFIG_SYSTEM)]}'.\n+</p>\n+<p>\n+Please contact the server administrator${admin_contact} to either configure\n+gitweb to allow mismatched versions, or update git or gitweb installation\n+so that their versions do match.\n+</p>\n+EOT\n+\tdie_error(500, 'Internal server error', $err_msg);\n+}\n+\n $projects_list ||= $projectroot;\n \n if (defined $maxload && get_loadavg() > $maxload) {\ndiff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh\nindex 5a734b1..66a3e2d 100755\n--- a/t/gitweb-lib.sh\n+++ b/t/gitweb-lib.sh\n@@ -26,6 +26,7 @@ our \\$projects_list = '';\n our \\$export_ok = '';\n our \\$strict_export = '';\n our \\$maxload = undef;\n+our \\$git_versions_must_match = 0;\n \n EOF\n \ndiff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh\nindex 7590f10..e195f97 100755\n--- a/t/t9501-gitweb-standalone-http-status.sh\n+++ b/t/t9501-gitweb-standalone-http-status.sh\n@@ -133,5 +133,32 @@ cat >>gitweb_config.perl <<\\EOF\n our $maxload = undef;\n EOF\n \n+# ======================================================================\n+# check $git_versions_must_match feature\n+# should be last section, just in case\n+cp -f gitweb_config.perl gitweb_config.perl.bak\n+echo 'our $git_versions_must_match = 1;' >>gitweb_config.perl\n+\n+cat <<\\EOF >>gitweb_config.perl\n+our $version = \"current\";\n+EOF\n+test_expect_success 'force version match: no match' '\n+\tgitweb_run \"p=.git\" &&\n+\tgrep \"Status: 500 Internal Server Error\" gitweb.headers &&\n+\tgrep \"500 - Internal server error\" gitweb.body\n+'\n+test_debug 'cat gitweb.headers'\n+\n+cat <<\\EOF >>gitweb_config.perl\n+# must be kept in sync with code in gitweb/gitweb.perl\n+our $version = qx(\"$GIT\" --version) =~ m/git version (.*)$/ ? $1 : \"unknown\";\n+EOF\n+test_expect_success 'force version match: match' '\n+\tgitweb_run \"p=.git\" &&\n+\tgrep \"Status: 200 OK\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+mv -f gitweb_config.perl.bak gitweb_config.perl\n \n test_done\n-- \n1.6.6.1\n"},{"id":"133161","messageId":"7vzl3vf7j7.fsf@alter.siamese.dyndns.org","threadId":"22454","inReplyTo":"1264890645-28310-6-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH 5/8 v6] gitweb: add a get function to compliment print_local_time","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-31T00:21:48Z","receivedAt":"2010-01-31T00:21:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> This adds a get function (named format_local_time) for print_local_time,\n> so that the basic function can be used outside of their straight printing\n> operation.\n\nI didn't particularly feel like giving praise to print-local-time nor\nprint-sort-th, so I rewrote the log message for these two commits ;-).\n\n    gitweb: add a \"string\" variant of print_local_time\n    \n    Add a function (named format_local_time) that returns the string that\n    print_local_time would print.\n\nThanks.  Now I can drop GIT_SKIP_TESTS=t95?? while building 'pu'.  All\npushed out to the usual places.\n"},{"id":"133307","messageId":"4B677971.2080100@eaglescrag.net","threadId":"22454","inReplyTo":"1264890645-28310-9-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH 8/8 v6] gitweb: Add an option to force version match","fromName":"J.H.","fromEmail":"warthog9@eaglescrag.net","sentAt":"2010-02-02T01:01:37Z","receivedAt":"2010-02-02T01:01:37Z","isPatch":true,"sender":{"key":"warthog9@kernel.org","avatar":"https://avatars.githubusercontent.com/u/2334704?v=4"},"body":"Starting to pop off the stack, and this came up first.  A quick reading\nof this, I'd sign-off and agree to patches 1-7 completely.\n\nI'm still going to take issue that this being off by default is the\nwrong behavior and leaving this off by default more or less means that\nit will never get run and it becomes useless code.  If this isn't on by\ndefault, it shouldn't be committed, as I can't think of a legitimate use\ncase where an admin is going to turn this on.\n\nI'd still argue this needs to be on by default to at least give admins\nthe explicit warning that if they want to deviate they are taking their\nown risks, and that gitweb might not run as expected.  Once the warning\nis disabled in a configuration file it's not like it's going to be\nre-enabled.  People loading gitweb from their distro's package\nmanagement will likely be in sync properly and will never see this.\nThose who are installing gitweb independent of their distro's package\nmanagement will at least be warned of the risk, at least until better\nerror reporting is done and in gitweb.\n\nI've got a slightly modified version of this that re-enables it by\ndefault, it passes t9501 for me.\n\n- John 'Warthog9' Hawley\n\nOn 01/30/2010 02:30 PM, Jakub Narebski wrote:\n> From: John 'Warthog9' Hawley <warthog9@kernel.org>\n> \n> This adds $git_versions_must_match variable, which if set to true,\n> checks that we are running on the same version of git that we\n> shipped with, and if not throw '500 Internal Server Error' error.\n> What is checked is the version of gitweb (embedded in building\n> gitweb.cgi), against version of runtime git binary used.\n> \n> Gitweb can usually run with a mismatched git install.  This is more\n> here to give an obvious warning as to what's going on vs. silently\n> failing.\n> \n> By default this feature is turned off.\n> \n> Add tests to t9501-gitweb-standalone-http-status.sh that this feature\n> works correctly (as expected) if turned on, both in match and no match\n> case.\n> \n> Signed-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>\n> Signed-off-by: Jakub Narebski <jnareb@gmail.com>\n> ---\n> Changes from version from 'Gitweb caching v5' and\n>   git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5\n> \n> * Again turned off by default\n> * More detailed error description, as requested by Petr 'Pasky' Baudis\n>   in http://permalink.gmane.org/gmane.comp.version-control.git/137922\n> * Which in turn required to set $GITWEB_CONFIG_SYSTEM to be able to\n>   use its value in error description; otherwise we would get 'Variable \n>   \"$GITWEB_CONFIG_SYSTEM\" is not imported' error.\n> * Turn off forcing version matching in t/gitweb-lib.sh\n> * Add some tests for this feature in t9501-gitweb-standalone-http-status.sh\n> \n>  gitweb/README                            |    5 +++++\n>  gitweb/gitweb.perl                       |   29 ++++++++++++++++++++++++++++-\n>  t/gitweb-lib.sh                          |    1 +\n>  t/t9501-gitweb-standalone-http-status.sh |   27 +++++++++++++++++++++++++++\n>  4 files changed, 61 insertions(+), 1 deletions(-)\n> \n> diff --git a/gitweb/README b/gitweb/README\n> index 6c2c8e1..83a25a9 100644\n> --- a/gitweb/README\n> +++ b/gitweb/README\n> @@ -233,6 +233,11 @@ not include variables usually directly set during build):\n>     If server load exceed this value then return \"503 Service Unavaliable\" error.\n>     Server load is taken to be 0 if gitweb cannot determine its value.  Set it to\n>     undefined value to turn it off.  The default is 300.\n> + * $git_versions_must_match\n> +   If set to true value, gitweb fails with \"500 Internal Server Error\" error\n> +   if the version of the gitweb doesn't match version of the git binary.\n> +   Gitweb can usually run with a mismatched git install.   The default is 0\n> +   (false).\n>  \n>  \n>  Projects list file format\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index d0c3ff2..e69efeb 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -221,6 +221,9 @@ our %avatar_size = (\n>  \t'double'  => 32\n>  );\n>  \n> +# If it is true, exit if gitweb version and git binary version don't match\n> +our $git_versions_must_match = 0;\n> +\n>  # Used to set the maximum load that we will still respond to gitweb queries.\n>  # If server load exceed this value then return \"503 server busy\" error.\n>  # If gitweb cannot determined server load, it is taken to be 0.\n> @@ -550,10 +553,10 @@ sub filter_snapshot_fmts {\n>  }\n>  \n>  our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || \"++GITWEB_CONFIG++\";\n> +our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || \"++GITWEB_CONFIG_SYSTEM++\";\n>  if (-e $GITWEB_CONFIG) {\n>  \tdo $GITWEB_CONFIG;\n>  } else {\n> -\tour $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || \"++GITWEB_CONFIG_SYSTEM++\";\n>  \tdo $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;\n>  }\n>  \n> @@ -583,6 +586,30 @@ sub get_loadavg {\n>  our $git_version = qx(\"$GIT\" --version) =~ m/git version (.*)$/ ? $1 : \"unknown\";\n>  $number_of_git_cmds++;\n>  \n> +# Throw an error if git versions does not match, if $git_versions_must_match is true.\n> +if ($git_versions_must_match &&\n> +    $git_version ne $version) {\n> +\tmy $admin_contact =\n> +\t\tdefined $ENV{'SERVER_ADMIN'} ? \", $ENV{'SERVER_ADMIN'},\" : '';\n> +\tmy $err_msg = <<EOT;\n> +<h1 align=\"center\">*** Warning ***</h1>\n> +<p>\n> +This version of gitweb was compiled for <b>@{[esc_html($version)]}</b>,\n> +however git version <b>@{[esc_html($git_version)]}</b> was found on server,\n> +and administrator requested strict version checking by setting\n> +\\$git_versions_must_match to @{[esc_html($git_versions_must_match)]}\n> +(true value) in gitweb configuration file,\n> +'@{[esc_path(-e $GITWEB_CONFIG ? $GITWEB_CONFIG : $GITWEB_CONFIG_SYSTEM)]}'.\n> +</p>\n> +<p>\n> +Please contact the server administrator${admin_contact} to either configure\n> +gitweb to allow mismatched versions, or update git or gitweb installation\n> +so that their versions do match.\n> +</p>\n> +EOT\n> +\tdie_error(500, 'Internal server error', $err_msg);\n> +}\n> +\n>  $projects_list ||= $projectroot;\n>  \n>  if (defined $maxload && get_loadavg() > $maxload) {\n> diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh\n> index 5a734b1..66a3e2d 100755\n> --- a/t/gitweb-lib.sh\n> +++ b/t/gitweb-lib.sh\n> @@ -26,6 +26,7 @@ our \\$projects_list = '';\n>  our \\$export_ok = '';\n>  our \\$strict_export = '';\n>  our \\$maxload = undef;\n> +our \\$git_versions_must_match = 0;\n>  \n>  EOF\n>  \n> diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh\n> index 7590f10..e195f97 100755\n> --- a/t/t9501-gitweb-standalone-http-status.sh\n> +++ b/t/t9501-gitweb-standalone-http-status.sh\n> @@ -133,5 +133,32 @@ cat >>gitweb_config.perl <<\\EOF\n>  our $maxload = undef;\n>  EOF\n>  \n> +# ======================================================================\n> +# check $git_versions_must_match feature\n> +# should be last section, just in case\n> +cp -f gitweb_config.perl gitweb_config.perl.bak\n> +echo 'our $git_versions_must_match = 1;' >>gitweb_config.perl\n> +\n> +cat <<\\EOF >>gitweb_config.perl\n> +our $version = \"current\";\n> +EOF\n> +test_expect_success 'force version match: no match' '\n> +\tgitweb_run \"p=.git\" &&\n> +\tgrep \"Status: 500 Internal Server Error\" gitweb.headers &&\n> +\tgrep \"500 - Internal server error\" gitweb.body\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +cat <<\\EOF >>gitweb_config.perl\n> +# must be kept in sync with code in gitweb/gitweb.perl\n> +our $version = qx(\"$GIT\" --version) =~ m/git version (.*)$/ ? $1 : \"unknown\";\n> +EOF\n> +test_expect_success 'force version match: match' '\n> +\tgitweb_run \"p=.git\" &&\n> +\tgrep \"Status: 200 OK\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +mv -f gitweb_config.perl.bak gitweb_config.perl\n>  \n>  test_done\n"},{"id":"133309","messageId":"201002020235.19943.jnareb@gmail.com","threadId":"22454","inReplyTo":"4B677971.2080100@eaglescrag.net","subject":"Re: [PATCH 8/8 v6] gitweb: Add an option to force version match","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-02-02T01:35:17Z","receivedAt":"2010-02-02T01:35:17Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 1 Feb 2010, at 17:01:37 -0800, J.H. wrote:\n\n> Starting to pop off the stack, and this came up first.  A quick reading\n> of this, I'd sign-off and agree to patches 1-7 completely.\n> \n> I'm still going to take issue that this being off by default is the\n> wrong behavior and leaving this off by default more or less means that\n> it will never get run and it becomes useless code.  If this isn't on by\n> default, it shouldn't be committed, as I can't think of a legitimate use\n> case where an admin is going to turn this on.\n\nWell, I don't think that mismatched git and gitweb version should be\nserious problem in practice, unless they are seriously out of sync.  \nAnd in such situation (where either git is stale and gitweb updated,\nor git updated and gitweb kept stale e.g. because it is heavily \ncustomized with not ported changes) gitweb admin should turn this\nfeature on.\n\n> \n> I'd still argue this needs to be on by default to at least give admins\n> the explicit warning that if they want to deviate they are taking their\n> own risks, and that gitweb might not run as expected.  Once the warning\n> is disabled in a configuration file it's not like it's going to be\n> re-enabled.  People loading gitweb from their distro's package\n> management will likely be in sync properly and will never see this.\n> Those who are installing gitweb independent of their distro's package\n> management will at least be warned of the risk, at least until better\n> error reporting is done and in gitweb.\n\nIf you want to have it turned on by default (which is _incompatible_\nchange, and which was not announced enough, I think; it might mean\nthat gitweb can stop working after git or gitweb update), beside\nchanging commit message and gitweb/README (and of course definition of\n$git_versions_must_match variable), you would have also update \nexplanation in die_error for version mismatch.\n\nCurrent version, as requested by Petr 'Pasky' Baudis, explains how\nto turn feature off if it was enabled.  For this it needs to check\nwhich config file is present, but we know at least that some config\nfile had to be used (beside possibility of hand-editing gitweb.cgi).\nThis is not the case if this feature is turned on by default: there\nis possible that there is no gitweb config file, and all configuration\nwas done at build time.  How to explain then how to turn this feature\noff?  What happens if both $GIWEB_CONFIG and $GITWEB_CONFIG_SYSTEM\nare empty because of misconfiguration during build ($GITWEB_CONFIG\nis set by default to gitweb_config.perl, and $GITWEB_CONFIG_SYSTEM\nis set by default to /etc/gitweb.conf)?  Which one to recommend if both\nvariables are set, but neither file exists?\n\nThe difficulty of explanation how to turn this feature off if it is\non by default was one of main reasons to not have it turned on by\ndefault.\n\n\nSide-note: Perhaps error is too strong a measure, and it would be better\nto just issue warning somewhere instead?\n\n> \n> I've got a slightly modified version of this that re-enables it by\n> default, it passes t9501 for me.\n\nAs it should, because gitweb-lib.sh was modified to explicitly turn off\nthis feature (see below), to allow testing gitweb without need to \nrecompile whole git, and to allow testing _not installed_ (source)\nversion of gitweb.\n\n> > diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh\n> > index 5a734b1..66a3e2d 100755\n> > --- a/t/gitweb-lib.sh\n> > +++ b/t/gitweb-lib.sh\n> > @@ -26,6 +26,7 @@ our \\$projects_list = '';\n> >  our \\$export_ok = '';\n> >  our \\$strict_export = '';\n> >  our \\$maxload = undef;\n> > +our \\$git_versions_must_match = 0;\n> >  \n> >  EOF\n> >  \n\n-- \nJakub Narebski\nPoland\n"},{"id":"133311","messageId":"7vfx5kiaty.fsf@alter.siamese.dyndns.org","threadId":"22454","inReplyTo":"201002020235.19943.jnareb@gmail.com","subject":"Re: [PATCH 8/8 v6] gitweb: Add an option to force version match","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-02T03:19:05Z","receivedAt":"2010-02-02T03:19:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> On Mon, 1 Feb 2010, at 17:01:37 -0800, J.H. wrote:\n>\n>> Starting to pop off the stack, and this came up first.  A quick reading\n>> of this, I'd sign-off and agree to patches 1-7 completely.\n>> \n>> I'm still going to take issue that this being off by default is the\n>> wrong behavior and leaving this off by default more or less means that\n>> it will never get run and it becomes useless code.  If this isn't on by\n>> default, it shouldn't be committed, as I can't think of a legitimate use\n>> case where an admin is going to turn this on.\n>\n> Well, I don't think that mismatched git and gitweb version should be\n> serious problem in practice, unless they are seriously out of sync.  \n> And in such situation (where either git is stale and gitweb updated,\n> or git updated and gitweb kept stale e.g. because it is heavily \n> customized with not ported changes) gitweb admin should turn this\n> feature on.\n\nI am not quite sure why the \"boolean\" default matters that much to deserve\nthis much of bandwidth.\n\nIf it is assumed that most everybody uses matching git and gitweb given by\ntheir distro, then the default does not matter to them.  So let's think\nabout others.\n\nIf it is by default on, then here are what the site administrators would\ndo:\n\n - Some may want to _always_ make sure they run matching versions and\n   consider having different versions of git and gitweb as _a mistake_; .\n   they leave the check on by default, and they don't have to do anything.\n\n - Some may _not_ even care.  They flip it off, and keep it that way.\n   They do that _only_ once.\n\nBetween these two classes of people, if you make the default off, you are\nmaking more careful ones pay a bit more \"one time\" price, while allowing\nlazy ones potentially shoot themselves in the foot more easily.  As the\nmaintainer, I am sympathetic John's insistence of having this check on by\ndefault, and would even suggest that the configuration variable has to be\nset to the exact string \"I accept the risk of running non-matching\nversions of git and gitweb\" to turn the warning off ;-), but either way,\nit doesn't seem to make too much of a difference.\n\nAdmittedly, unlike John or Pasky, I do not run a public gitweb instanace\nnor have to deal with error reports from the end users, and that might be\ncontributing to my bias.\n\nBut I think we need to try helping the third category of people:\n\n - Some may need to _keep_ unmatched versions of git and gitweb for the\n   users on their box.  Perhaps interactive users need a certain version\n   of git, but they want to show spiffier looking gitweb to the general\n   public by installing newer one.  They check if the combination of the\n   particular (older) git and (newer) gitweb work well together, and then\n   they say \"don't warn, I know it is Ok _now_\".\n\nUnless the configuration can express \"this combination has been checked,\nso do not warn, but do warn when any other untested combination is being\nused\", this class of people won't be helped by having a configuration.\n\nThey instead have to _remember_ that they need to flip the warning bit on\nbefore updating their git and/or gitweb, only to get reminded that they\nneed to make sure the combination works well.\n\nThat's a funny chicken-and-egg problem, isn't it?\n"},{"id":"133317","messageId":"7vvdegfbs0.fsf@alter.siamese.dyndns.org","threadId":"22454","inReplyTo":"4B677971.2080100@eaglescrag.net","subject":"Re: [PATCH 8/8 v6] gitweb: Add an option to force version match","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-02T05:26:55Z","receivedAt":"2010-02-02T05:26:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"J.H.\" <warthog9@eaglescrag.net> writes:\n\n> Starting to pop off the stack, and this came up first.  A quick reading\n> of this, I'd sign-off and agree to patches 1-7 completely.\n\nThen let me queue up to 7th to 'next', so I do not have to mentally keep\ntrack of which ones are already judged to be good, and we can move forward\nimmediately after 1.7.0 ships, regardless of the discusson on the 8th one.\n"}]}