{"thread":{"id":"27910","subject":"[PATCH (resend)] gitweb: Introduce common system-wide settings for convenience","startedAt":"2011-07-24T22:29:18Z","lastAt":"2011-07-24T22:29:18Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"171972","messageId":"1311546558-25766-1-git-send-email-jnareb@gmail.com","threadId":"27910","inReplyTo":null,"subject":"[PATCH (resend)] gitweb: Introduce common system-wide settings for convenience","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-07-24T22:29:18Z","receivedAt":"2011-07-24T22:29:18Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Because of backward compatibility we cannot change gitweb to always\nuse /etc/gitweb.conf (i.e. even if gitweb_config.perl exists).  For\ncommon system-wide settings we therefore need separate configuration\nfile: /etc/gitweb-common.conf.\n\n\nLong description:\n\ngitweb currently obtains configuration from the following sources:\n\n  1. per-instance configuration file (default: gitweb_conf.perl)\n  2. system-wide configuration file (default: /etc/gitweb.conf)\n\nIf per-instance configuration file exists, then system-wide\nconfiguration is _not used at all_.  This is quite untypical and\nsuprising behavior.\n\nMoreover it is different from way git itself treats /etc/git.conf.  It\nreads in stuff from /etc/git.conf and then local repos can change or\noverride things as needed.  In fact this is quite beneficial, because\nit gives site admins a simple and easy way to give an automatic hint\nto a repo about things the admin would like.\n\nOn the other hand changing current behavior may lead to the situation,\nwhere something in /etc/gitweb.conf may interfere with unintended\ninteraction in the local repository.  One solution would be to\n_require_ to do explicit include; with read_config_file() it is now\neasy, as described in gitweb/README (description introduced in this\ncommit).\n\nBut as J.H. noticed we cannot ask people to modify their per-instance\ngitweb config file to include system-wide settings, nor we can require\nthem to do this.\n\nTherefore, as proposed by Junio, for gitweb to have centralized config\nelements while retaining backwards compatibility, introduce separate\ncommon system-wide configuration file, by default /etc/gitweb-common.conf\n\nNoticed-by: Drew Northup <drew.northup@maine.edu>\nHelped-by: John 'Warthog9' Hawley <warthog9@kernel.org>\nInspired-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis patch was originally sent to git mailing list as\n\n  [PATCH/RFC 2/2 (version C)] gitweb: Introduce common system-wide settings for convenience\n  http://thread.gmane.org/gmane.comp.version-control.git/174424/focus=174517\n\nin the following thread\n\n  [PATCH 0/2] gitweb: Improve handling of configuration files\n\nfrom 2011-05-26.  It looks like it was forgotten / fallen through\ncracks.\n\n...\n\nThere is a question how we should go from there.  A simple thing would\nbe to introduce GITWEB_CONFIG_FALLBACK or GITWEB_CONFIG_DEFAULT, or\nGITWEB_CONFIG_TEMPLATE, or GITWEB_CONFIG_SKEL environment variable in\naddition to existing GITWEB_CONFIG_SYSTEM.\n\n\nTwo following steps could be made in either order, but neither of them\nis backwards compatibile.\n\nOne step would be to replace build time configuration variable\nGITWEB_CONFIG_SYSTEM (in gitweb/Makefile) with GITWEB_CONFIG_DEFAULT\nor similar, and rename $GITWEB_CONFIG_SYSTEM variable.\n\nFirst change would break backward compatibility with (rare?)\ngitweb/config.mak.  Second could break backward compatibility if one's\nper-instance config file calls global (fallback) config file.\n\n\nOther change would be to replace default value of GITWEB_CONFIG_SYSTEM\nfrom /etc/gitweb.conf to e.g. /etc/gitweb_config.perl, or\n/etc/skel/gitweb_config.perl, or /etc/gitweb-default.conf\n\nThis could be accompanied with renaming default value of\nGITWEB_CONFIG_COMMON from /etc/gitweb-common.conf to /etc/gitweb.conf\n\n\n gitweb/INSTALL     |   13 ++++++++++++-\n gitweb/Makefile    |    2 ++\n gitweb/README      |   27 ++++++++++++++++++++++++---\n gitweb/gitweb.perl |   18 +++++++++++++++---\n 4 files changed, 53 insertions(+), 7 deletions(-)\n\ndiff --git a/gitweb/INSTALL b/gitweb/INSTALL\nindex c5236fe..f5efe74 100644\n--- a/gitweb/INSTALL\n+++ b/gitweb/INSTALL\n@@ -231,7 +231,7 @@ Gitweb config file\n See also \"Runtime gitweb configuration\" section in README file\n for gitweb (in gitweb/README).\n \n-- You can configure gitweb further using the gitweb configuration file;\n+- You can configure gitweb further using the per-instance gitweb configuration file;\n   by default this is a file named gitweb_config.perl in the same place as\n   gitweb.cgi script. You can control the default place for the config file\n   using the GITWEB_CONFIG build configuration variable, and you can set it\n@@ -241,6 +241,17 @@ for gitweb (in gitweb/README).\n   GITWEB_CONFIG_SYSTEM build configuration variable, and override it\n   through the GITWEB_CONFIG_SYSTEM environment variable.\n \n+  Note that if per-instance configuration file exists, then system-wide\n+  configuration is _not used at all_.  This is quite untypical and suprising\n+  behavior.  On the other hand changing current behavior would break backwards\n+  compatibility and can lead to unexpected changes in gitweb behavior.\n+  Therefore gitweb also looks for common system-wide configuration file,\n+  normally /etc/gitweb-common.conf (set during build time using build time\n+  configuration variable GITWEB_CONFIG_COMMON, set it at runtime using\n+  environment variable with the same name).  Settings from per-instance or\n+  system-wide configuration file override those from common system-wide\n+  configuration file.\n+\n - The gitweb config file is a fragment of perl code. You can set variables\n   using \"our $variable = value\"; text from \"#\" character until the end\n   of a line is ignored. See perlsyn(1) for details.\ndiff --git a/gitweb/Makefile b/gitweb/Makefile\nindex 5d20515..1c85b5f 100644\n--- a/gitweb/Makefile\n+++ b/gitweb/Makefile\n@@ -20,6 +20,7 @@ INSTALL ?= install\n # default configuration for gitweb\n GITWEB_CONFIG = gitweb_config.perl\n GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf\n+GITWEB_CONFIG_COMMON = /etc/gitweb-common.conf\n GITWEB_HOME_LINK_STR = projects\n GITWEB_SITENAME =\n GITWEB_PROJECTROOT = /pub/git\n@@ -129,6 +130,7 @@ GITWEB_REPLACE = \\\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_CONFIG_COMMON++|$(GITWEB_CONFIG_COMMON)|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' \\\ndiff --git a/gitweb/README b/gitweb/README\nindex a4cfcb4..a998820 100644\n--- a/gitweb/README\n+++ b/gitweb/README\n@@ -10,9 +10,30 @@ From the git version 1.4.0 gitweb is bundled with git.\n Runtime gitweb configuration\n ----------------------------\n \n-You can adjust gitweb behaviour using the file specified in `GITWEB_CONFIG`\n-(defaults to 'gitweb_config.perl' in the same directory as the CGI), and\n-as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).\n+Gitweb obtains configuration data from the following sources in the\n+following order:\n+\n+1. built-in values (some set during build stage),\n+2. common system-wide configuration file (`GITWEB_CONFIG_COMMON`,\n+   defaults to '/etc/gitweb-common.conf'),\n+3. either per-instance configuration file (`GITWEB_CONFIG`, defaults to\n+   'gitweb_config.perl' in the same directory as the installed gitweb),\n+   or if it does not exists then system-wide configuration file\n+   (`GITWEB_CONFIG_SYSTEM`, defaults to '/etc/gitweb.conf').\n+\n+Values obtained in later configuration files override values obtained earlier\n+in above sequence.\n+\n+You can read defaults in system-wide GITWEB_CONFIG_SYSTEM from GITWEB_CONFIG\n+by adding\n+\n+  read_config_file($GITWEB_CONFIG_SYSTEM);\n+\n+at very beginning of per-instance GITWEB_CONFIG file.  In this case\n+settings in said per-instance file will override settings from\n+system-wide configuration file.  Note that read_config_file checks\n+itself that the $GITWEB_CONFIG_SYSTEM file exists.\n+\n The most notable thing that is not configurable at compile time are the\n optional features, stored in the '%features' variable.\n \ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex dab89f2..1070805 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -665,13 +665,25 @@ sub read_config_file {\n \treturn;\n }\n \n-our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);\n+our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM, $GITWEB_CONFIG_COMMON);\n sub evaluate_gitweb_config {\n \tour $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || \"++GITWEB_CONFIG++\";\n \tour $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || \"++GITWEB_CONFIG_SYSTEM++\";\n+\tour $GITWEB_CONFIG_COMMON = $ENV{'GITWEB_CONFIG_COMMON'} || \"++GITWEB_CONFIG_COMMON++\";\n \n-\t# use first config file that exists\n-\tread_config_file($GITWEB_CONFIG) or\n+\t# Protect agains duplications of file names, to not read config twice.\n+\t# Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so\n+\t# there possibility of duplication of filename there doesn't matter.\n+\t$GITWEB_CONFIG = \"\"        if ($GITWEB_CONFIG eq $GITWEB_CONFIG_COMMON);\n+\t$GITWEB_CONFIG_SYSTEM = \"\" if ($GITWEB_CONFIG_SYSTEM eq $GITWEB_CONFIG_COMMON);\n+\n+\t# Common system-wide settings for convenience.\n+\t# Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.\n+\tread_config_file($GITWEB_CONFIG_COMMON);\n+\n+\t# Use first config file that exists.  This means use the per-instance\n+\t# GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG.\n+\tread_config_file($GITWEB_CONFIG) and return;\n \tread_config_file($GITWEB_CONFIG_SYSTEM);\n }\n \n-- \n1.7.5\n"}]}