git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] gitweb: Add option to limit repositories to be shown by ServerName
@ 2012-08-14  8:47 Michal Novotny
  2012-08-14 16:04 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Novotny @ 2012-08-14  8:47 UTC (permalink / raw
  To: git; +Cc: Michal Novotny

Hi,
this is the patch to limit repositories to be shown
by the ServerName in the gitweb.cgi script. This is
useful for cases you're hosting multiple websites on
a single machine and you don't want all the repos to
be shown in all of them.

Functionality: Simply create file called 'server' in
               the git repository (the same location
               like for 'description' file) and put
               the server name to show this repo for.

Testing: It's been tested on a test server and everything
         was working fine/as expected. If there's no
         'server' file in the git repository it falls back
         to the default option to show the repository as
         it was working before this patch applied not to
         introduce any regressive behaviour.

Use case scenario: Imagine you have one server running HTTPd
                   for 3 domains, let's call them domain1,
                   domain2 and domain3, and you want all of
                   them to have a git server accessible via
                   gitweb at these URLs:
                   1) http://domain1/git
                   2) http://domain2/git
                   3) http://domain3/git

                   Before this patch, all the URLs would be
                   showing the same repos however we would
                   like to limit repo1 to be shown only on
                   domain1, repo2 to be shown only on domain2
                   and repo3 to be shown only on domain3. Here
                   my patch comes handy because you simply edit
                   the 'repo1/server' file and put 'domain1' in
                   here and it won't get shown on any other URL.
                   The same for repo2 and repo3 and it will be
                   shown only for the domain it belongs to.
                   Also, if no 'server' file exists in the repo
                   the repository is being shown so upgrading
                   gitweb with no creation of 'server' files
                   will preserve the old behaviour.

Hope this will help, at least it did help me on my test server.

Any feedback appreciated!

Thanks,
Michal

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 gitweb/gitweb.perl | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 3d6a705..1b74239 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2804,6 +2804,11 @@ sub git_get_project_description {
 	return git_get_file_or_project_config($path, 'description');
 }
 
+sub git_get_project_server {
+	my $path = shift;
+	return git_get_file_or_project_config($path, 'server');
+}
+
 sub git_get_project_category {
 	my $path = shift;
 	return git_get_file_or_project_config($path, 'category');
@@ -2947,6 +2952,19 @@ sub git_get_project_url_list {
 	return wantarray ? @git_project_url_list : \@git_project_url_list;
 }
 
+sub get_project_can_export {
+	my ($path) = @_;
+
+	if (defined $ENV{'SERVER_NAME'}) {
+		my $server = git_get_project_server($path) || "";
+
+		return (($server eq $ENV{'SERVER_NAME'}) or ($server eq ''));
+	}
+	else {
+		return 1;
+	}
+}
+
 sub git_get_projects_list {
 	my $filter = shift || '';
 	my $paranoid = shift;
@@ -2990,7 +3008,8 @@ sub git_get_projects_list {
 					next;
 				}
 				# we check related file in $projectroot
-				if (check_export_ok("$projectroot/$path")) {
+				if (check_export_ok("$projectroot/$path") and
+					get_project_can_export($path)) {
 					push @list, { path => $path };
 					$File::Find::prune = 1;
 				}
@@ -3016,7 +3035,8 @@ sub git_get_projects_list {
 			if ($filter && $path !~ m!^\Q$filter\E/!) {
 				next;
 			}
-			if (check_export_ok("$projectroot/$path")) {
+			if (check_export_ok("$projectroot/$path") and
+				get_project_can_export($path)) {
 				my $pr = {
 					path => $path
 				};
-- 
1.7.11.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] gitweb: Add option to limit repositories to be shown by ServerName
  2012-08-14  8:47 [PATCH] gitweb: Add option to limit repositories to be shown by ServerName Michal Novotny
@ 2012-08-14 16:04 ` Junio C Hamano
  2012-08-14 16:11   ` J.H.
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2012-08-14 16:04 UTC (permalink / raw
  To: Michal Novotny; +Cc: git

Michal Novotny <minovotn@redhat.com> writes:

> this is the patch to limit repositories to be shown by the
> ServerName in the gitweb.cgi script. This is useful for cases
> you're hosting multiple websites on a single machine and you don't
> want all the repos to be shown in all of them.
> ...
> Use case scenario: Imagine you have one server running HTTPd
>                    for 3 domains, let's call them domain1,
>                    domain2 and domain3, and you want all of
>                    them to have a git server accessible via
>                    gitweb at these URLs:
>                    1) http://domain1/git
>                    2) http://domain2/git
>                    3) http://domain3/git


I do not run gitweb myself, but isn't the problem you are describing
merely a symptom caused by your <VirtualHost /> sections that are
not configured correctly, and instead having a single instance of
gitweb cgi enabled for all the virtual hosts?  Why does such a
physical host want to have git repositories for different domains in
a single place that is covered by a single instance of gitweb (hence
a single $projectroot) in the first place?  After all, domain1's
notion of "kernel git repository" http://domain1/git/kernel.git
might be totally different from that of domain2's, so wouldn't it be
far more natural to have one $projectroot (hence one instance of
gitweb) per such domains, configured in their own <VirtualHost />
sections?

Also, there may even be http://domain3/git that does not want to be
served by gitweb but something else, e.g. cgit, on the same physical
host, and in such a case, the approach taken by this patch still uses
gitweb only to fail the request without letting cgit have its
chance, no?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gitweb: Add option to limit repositories to be shown by ServerName
  2012-08-14 16:04 ` Junio C Hamano
@ 2012-08-14 16:11   ` J.H.
  0 siblings, 0 replies; 3+ messages in thread
From: J.H. @ 2012-08-14 16:11 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Michal Novotny, git

On 08/14/2012 10:04 AM, Junio C Hamano wrote:
> Michal Novotny <minovotn@redhat.com> writes:
> 
>> this is the patch to limit repositories to be shown by the
>> ServerName in the gitweb.cgi script. This is useful for cases
>> you're hosting multiple websites on a single machine and you don't
>> want all the repos to be shown in all of them.
>> ...
>> Use case scenario: Imagine you have one server running HTTPd
>>                    for 3 domains, let's call them domain1,
>>                    domain2 and domain3, and you want all of
>>                    them to have a git server accessible via
>>                    gitweb at these URLs:
>>                    1) http://domain1/git
>>                    2) http://domain2/git
>>                    3) http://domain3/git
> 
> 
> I do not run gitweb myself, but isn't the problem you are describing
> merely a symptom caused by your <VirtualHost /> sections that are
> not configured correctly, and instead having a single instance of
> gitweb cgi enabled for all the virtual hosts?  Why does such a
> physical host want to have git repositories for different domains in
> a single place that is covered by a single instance of gitweb (hence
> a single $projectroot) in the first place?  After all, domain1's
> notion of "kernel git repository" http://domain1/git/kernel.git
> might be totally different from that of domain2's, so wouldn't it be
> far more natural to have one $projectroot (hence one instance of
> gitweb) per such domains, configured in their own <VirtualHost />
> sections?
> 
> Also, there may even be http://domain3/git that does not want to be
> served by gitweb but something else, e.g. cgit, on the same physical
> host, and in such a case, the approach taken by this patch still uses
> gitweb only to fail the request without letting cgit have its
> chance, no?

The use case scenario is doable with Apache's vhost directives, and is
likely a much better way to accomplish this then trying to teach gitweb
about vhosting.

http://httpd.apache.org/docs/2.2/vhosts/mass.html

should give some hints on how this can be done, but the long and the
short is, single install of gitweb with the config file using, say %0,
to dynamically figure out which domain to work from.

- John

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-14 16:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-14  8:47 [PATCH] gitweb: Add option to limit repositories to be shown by ServerName Michal Novotny
2012-08-14 16:04 ` Junio C Hamano
2012-08-14 16:11   ` J.H.

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).