{"thread":{"id":"31249","subject":"[PATCH] gitweb: Add option to limit repositories to be shown by ServerName","startedAt":"2012-08-14T08:47:48Z","lastAt":"2012-08-14T16:11:47Z","messageCount":3,"participants":["Michal Novotny","Junio C Hamano","J.H."],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"196965","messageId":"d4f61bb06c9a125113442ae63be15ccea9464afd.1344932897.git.minovotn@redhat.com","threadId":"31249","inReplyTo":null,"subject":"[PATCH] gitweb: Add option to limit repositories to be shown by ServerName","fromName":"Michal Novotny","fromEmail":"minovotn@redhat.com","sentAt":"2012-08-14T08:47:48Z","receivedAt":"2012-08-14T08:47:48Z","isPatch":true,"sender":{"key":"minovotn@redhat.com","avatar":null},"body":"Hi,\nthis is the patch to limit repositories to be shown\nby the ServerName in the gitweb.cgi script. This is\nuseful for cases you're hosting multiple websites on\na single machine and you don't want all the repos to\nbe shown in all of them.\n\nFunctionality: Simply create file called 'server' in\n               the git repository (the same location\n               like for 'description' file) and put\n               the server name to show this repo for.\n\nTesting: It's been tested on a test server and everything\n         was working fine/as expected. If there's no\n         'server' file in the git repository it falls back\n         to the default option to show the repository as\n         it was working before this patch applied not to\n         introduce any regressive behaviour.\n\nUse case scenario: Imagine you have one server running HTTPd\n                   for 3 domains, let's call them domain1,\n                   domain2 and domain3, and you want all of\n                   them to have a git server accessible via\n                   gitweb at these URLs:\n                   1) http://domain1/git\n                   2) http://domain2/git\n                   3) http://domain3/git\n\n                   Before this patch, all the URLs would be\n                   showing the same repos however we would\n                   like to limit repo1 to be shown only on\n                   domain1, repo2 to be shown only on domain2\n                   and repo3 to be shown only on domain3. Here\n                   my patch comes handy because you simply edit\n                   the 'repo1/server' file and put 'domain1' in\n                   here and it won't get shown on any other URL.\n                   The same for repo2 and repo3 and it will be\n                   shown only for the domain it belongs to.\n                   Also, if no 'server' file exists in the repo\n                   the repository is being shown so upgrading\n                   gitweb with no creation of 'server' files\n                   will preserve the old behaviour.\n\nHope this will help, at least it did help me on my test server.\n\nAny feedback appreciated!\n\nThanks,\nMichal\n\nSigned-off-by: Michal Novotny <minovotn@redhat.com>\n---\n gitweb/gitweb.perl | 24 ++++++++++++++++++++++--\n 1 file changed, 22 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 3d6a705..1b74239 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -2804,6 +2804,11 @@ sub git_get_project_description {\n \treturn git_get_file_or_project_config($path, 'description');\n }\n \n+sub git_get_project_server {\n+\tmy $path = shift;\n+\treturn git_get_file_or_project_config($path, 'server');\n+}\n+\n sub git_get_project_category {\n \tmy $path = shift;\n \treturn git_get_file_or_project_config($path, 'category');\n@@ -2947,6 +2952,19 @@ sub git_get_project_url_list {\n \treturn wantarray ? @git_project_url_list : \\@git_project_url_list;\n }\n \n+sub get_project_can_export {\n+\tmy ($path) = @_;\n+\n+\tif (defined $ENV{'SERVER_NAME'}) {\n+\t\tmy $server = git_get_project_server($path) || \"\";\n+\n+\t\treturn (($server eq $ENV{'SERVER_NAME'}) or ($server eq ''));\n+\t}\n+\telse {\n+\t\treturn 1;\n+\t}\n+}\n+\n sub git_get_projects_list {\n \tmy $filter = shift || '';\n \tmy $paranoid = shift;\n@@ -2990,7 +3008,8 @@ sub git_get_projects_list {\n \t\t\t\t\tnext;\n \t\t\t\t}\n \t\t\t\t# we check related file in $projectroot\n-\t\t\t\tif (check_export_ok(\"$projectroot/$path\")) {\n+\t\t\t\tif (check_export_ok(\"$projectroot/$path\") and\n+\t\t\t\t\tget_project_can_export($path)) {\n \t\t\t\t\tpush @list, { path => $path };\n \t\t\t\t\t$File::Find::prune = 1;\n \t\t\t\t}\n@@ -3016,7 +3035,8 @@ sub git_get_projects_list {\n \t\t\tif ($filter && $path !~ m!^\\Q$filter\\E/!) {\n \t\t\t\tnext;\n \t\t\t}\n-\t\t\tif (check_export_ok(\"$projectroot/$path\")) {\n+\t\t\tif (check_export_ok(\"$projectroot/$path\") and\n+\t\t\t\tget_project_can_export($path)) {\n \t\t\t\tmy $pr = {\n \t\t\t\t\tpath => $path\n \t\t\t\t};\n-- \n1.7.11.2\n"},{"id":"196979","messageId":"7v628l8noh.fsf@alter.siamese.dyndns.org","threadId":"31249","inReplyTo":"d4f61bb06c9a125113442ae63be15ccea9464afd.1344932897.git.minovotn@redhat.com","subject":"Re: [PATCH] gitweb: Add option to limit repositories to be shown by ServerName","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-14T16:04:46Z","receivedAt":"2012-08-14T16:04:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michal Novotny <minovotn@redhat.com> writes:\n\n> this is the patch to limit repositories to be shown by the\n> ServerName in the gitweb.cgi script. This is useful for cases\n> you're hosting multiple websites on a single machine and you don't\n> want all the repos to be shown in all of them.\n> ...\n> Use case scenario: Imagine you have one server running HTTPd\n>                    for 3 domains, let's call them domain1,\n>                    domain2 and domain3, and you want all of\n>                    them to have a git server accessible via\n>                    gitweb at these URLs:\n>                    1) http://domain1/git\n>                    2) http://domain2/git\n>                    3) http://domain3/git\n\n\nI do not run gitweb myself, but isn't the problem you are describing\nmerely a symptom caused by your <VirtualHost /> sections that are\nnot configured correctly, and instead having a single instance of\ngitweb cgi enabled for all the virtual hosts?  Why does such a\nphysical host want to have git repositories for different domains in\na single place that is covered by a single instance of gitweb (hence\na single $projectroot) in the first place?  After all, domain1's\nnotion of \"kernel git repository\" http://domain1/git/kernel.git\nmight be totally different from that of domain2's, so wouldn't it be\nfar more natural to have one $projectroot (hence one instance of\ngitweb) per such domains, configured in their own <VirtualHost />\nsections?\n\nAlso, there may even be http://domain3/git that does not want to be\nserved by gitweb but something else, e.g. cgit, on the same physical\nhost, and in such a case, the approach taken by this patch still uses\ngitweb only to fail the request without letting cgit have its\nchance, no?\n"},{"id":"196980","messageId":"502A78C3.8090809@eaglescrag.net","threadId":"31249","inReplyTo":"7v628l8noh.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] gitweb: Add option to limit repositories to be shown by ServerName","fromName":"J.H.","fromEmail":"warthog19@eaglescrag.net","sentAt":"2012-08-14T16:11:47Z","receivedAt":"2012-08-14T16:11:47Z","isPatch":true,"sender":{"key":"warthog19@eaglescrag.net","avatar":null},"body":"On 08/14/2012 10:04 AM, Junio C Hamano wrote:\n> Michal Novotny <minovotn@redhat.com> writes:\n> \n>> this is the patch to limit repositories to be shown by the\n>> ServerName in the gitweb.cgi script. This is useful for cases\n>> you're hosting multiple websites on a single machine and you don't\n>> want all the repos to be shown in all of them.\n>> ...\n>> Use case scenario: Imagine you have one server running HTTPd\n>>                    for 3 domains, let's call them domain1,\n>>                    domain2 and domain3, and you want all of\n>>                    them to have a git server accessible via\n>>                    gitweb at these URLs:\n>>                    1) http://domain1/git\n>>                    2) http://domain2/git\n>>                    3) http://domain3/git\n> \n> \n> I do not run gitweb myself, but isn't the problem you are describing\n> merely a symptom caused by your <VirtualHost /> sections that are\n> not configured correctly, and instead having a single instance of\n> gitweb cgi enabled for all the virtual hosts?  Why does such a\n> physical host want to have git repositories for different domains in\n> a single place that is covered by a single instance of gitweb (hence\n> a single $projectroot) in the first place?  After all, domain1's\n> notion of \"kernel git repository\" http://domain1/git/kernel.git\n> might be totally different from that of domain2's, so wouldn't it be\n> far more natural to have one $projectroot (hence one instance of\n> gitweb) per such domains, configured in their own <VirtualHost />\n> sections?\n> \n> Also, there may even be http://domain3/git that does not want to be\n> served by gitweb but something else, e.g. cgit, on the same physical\n> host, and in such a case, the approach taken by this patch still uses\n> gitweb only to fail the request without letting cgit have its\n> chance, no?\n\nThe use case scenario is doable with Apache's vhost directives, and is\nlikely a much better way to accomplish this then trying to teach gitweb\nabout vhosting.\n\nhttp://httpd.apache.org/docs/2.2/vhosts/mass.html\n\nshould give some hints on how this can be done, but the long and the\nshort is, single install of gitweb with the config file using, say %0,\nto dynamically figure out which domain to work from.\n\n- John\n"}]}