Skip to contentSkip to conversation

About [PATCH] gitweb: Create a perl module to store gitweb configuration

DISCUSSION Jakub Narebski 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

This comment is about commit 9526ab8 (gitweb: Create a perl module to store gitweb configuration, 2010-06-01) on 'master' branch of repository shown at http://repo.or.cz/w/git/gsoc2010-gitweb.git

Quoted 4 lines

From 9526ab8a12c8d4d875d08a6201c7eca963c7d9aa Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara <[email protected]>
Date: Tue, 1 Jun 2010 02:36:48 +0530
Subject: [PATCH] gitweb: Create a perl module to store gitweb configuration

I would probably say

Subject: [PATCH] gitweb: Create Gitweb::Config module to store gitweb configuration

or even

Subject: [PATCH] gitweb: Create Gitweb::Config module

so that _name_ of this module is in commit subject (summary).

Quoted 4 lines

Create a perl module in path gitweb/lib/Gitweb/Config.pm to store all the configuration variables of the gitweb.perl script and change the scope of those variables in main script.

A bit overlong sentence, isn't it? Perhaps

Create a Gitweb::Config module in 'gitweb/lib/Gitweb/Config.pm' to store all the configuration variables of the gitweb.perl script.

(Assuming that I can convince you to avoid fully qualified names).

Quoted 4 lines

Move subroutine evaluate_gitweb_config() into the same module so that the statement 'do GITWEB_CONFIG' or 'do GITWEB_CONFIG_SYSTEM' works similiar to the working before the split.

s/similiar/similar/

I agree that you should list which subroutines you do move to Gitweb::Config package, though this list would be probably longer that the evaluate_gitweb_config() alone... or perhaps not.

But I do not understand the statement about "do $GITWEB_CONFIG" etc. here. Did you wanted to say that setting $GITWEB_CONFIG etc. was moved out of evaluate_gitweb_config(), and is left in gitweb.perl?

Quoted 2 lines

Change Makefile accordingly to install the Perl Module.

I would say:

Update gitweb/Makefile to install gitweb modules alongside gitweb.

Or something like that.

Quoted 3 lines

---

When sending this patch to git mailing list you should mention that it is based on
gitweb: Put all per-connection code in run() subroutine
and perhaps also on
gitweb: Add support for FastCGI, using CGI::Fast
unless those two commits made it into 'master' till then.

Quoted 11 lines
 gitweb/Makefile             |    6 +
 gitweb/gitweb.perl          |  692 ++++++++++---------------------------------
 gitweb/lib/Gitweb/Config.pm |  389 ++++++++++++++++++++++++
 3 files changed, 558 insertions(+), 529 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Config.pm
gitweb/Makefile +0 -0
index d2584fe..45e176e 100644

gitweb/Makefile PERL_PATH ?= /usr/bin/perl · line 58

Quoted 4 lines
gitweb/Makefile +1 -0
@@ -55,6 +55,7 @@ PERL_PATH  ?= /usr/bin/perl
 bindir_SQ = $(subst ','\'',$(bindir))#'
 gitwebdir_SQ = $(subst ','\'',$(gitwebdir))#'
 gitwebstaticdir_SQ = $(subst ','\'',$(gitwebdir)/static)#'
+gitweblibdir_SQ = $(subst ','\'',$(gitwebdir)/lib)#'

I think it would be good idea to have 'gitweblibdir' as a separate variable, alongside 'gitwebdir', and which would default to

   gitweblibdir = $(gitwebdir)/lib

to make it possible to install gitweb modules not alongside gitweb, but somewhere else, for example together with other Perl modules.

Then you would have:

  +gitweblibdir_SQ = $(subst ','\'',$(gitweblibdir))#'

But I think this change can be left for a separate commit. It is not something terribly important, something blocking accepting the patch.

BTW. did you start working on the 'write' part yet, at least on the conceptual (specification / architecture) level?

Quoted 14 lines
gitweb/Makefile +3 -0
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#'
 PERL_PATH_SQ  = $(subst ','\'',$(PERL_PATH))#'
 DESTDIR_SQ    = $(subst ','\'',$(DESTDIR))#'
@@ -110,6 +111,9 @@ endif
 
 GITWEB_FILES += static/git-logo.png static/git-favicon.png
 
+# Files: gitweb/lib/Gitweb
+GITWEB_LIB_GITWEB += lib/Gitweb/Config.pm
+
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
 	-e 's|++GIT_BINDIR++|$(bindir)|g' \

gitweb/Makefile install: all · line 158

Quoted 5 lines
gitweb/Makefile +2 -0
@@ -150,6 +154,8 @@ install: all
 	$(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
 	$(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb'
+	$(INSTALL) -m 644 $(GITWEB_LIB_GITWEB) '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb'

Uhhh... this would probably get more complicated *if* there would be more complicated hierarchy, e.g. if there would be Gitweb module in lib/Gitweb.pm. I guess that is the reason behind $(GITWEB_LIB_GITWEB) name, isn't it?

Quoted 8 lines
gitweb/Makefile +0 -0
 ### Cleaning rules
 
gitweb/gitweb.perl +0 -0
index 673e7a3..98a85f4 100755

gitweb/gitweb.perl use Encode; · line 21

Quoted 6 lines
gitweb/gitweb.perl +1 -0
@@ -16,19 +16,22 @@ use Encode;
 use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
+use File::Spec;
 binmode STDOUT, ':utf8';
 

The fragment below was slightly edited to make it more clear.

gitweb/gitweb.perl use Encode; · line 25

Quoted 5 lines
gitweb/gitweb.perl +0 -5
-our $t0;
-if (eval { require Time::HiRes; 1; }) {
-	$t0 = [Time::HiRes::gettimeofday()];
-}
-our $number_of_git_cmds = 0;

Theoretically neither $t0 nor $number_of_git_cmds belong to Gitweb::Config, as those are about runtime timing, not about gitweb configuration.

But perhaps for the time being you can put it in Gitweb::Config.

gitweb/gitweb.perl use Encode; · line 28

Quoted 7 lines
gitweb/gitweb.perl +7 -0
+# __DIR__ is taken from Dir::Self __DIR__ fragment
+sub __DIR__ () {
+	File::Spec->rel2abs(join '', (File::Spec->splitpath(__FILE__))[0, 1]);
+}
+use lib __DIR__ . "/lib";
+
+use Gitweb::Config;

O.K.

It's a pity that Dir::Self is not a core Perl module since Perl 5.8, and that FindBin which is in core since 5.4 has its quirks and nowadays is not recommended to use...

gitweb/gitweb.perl use Encode; · line 33

Quoted 7 lines
gitweb/gitweb.perl +1 -1
 BEGIN {
 	CGI->compile() if $ENV{'MOD_PERL'};
 }
 
-our $version = "++GIT_VERSION++";
+$Gitweb::Config::version = "++GIT_VERSION++";

If '$version' was exported by Gitweb::Config this change would be not necessary.

I would remove all such changes from discussion of this patch.

gitweb/gitweb.perl use Encode;

Quoted 5 lines
gitweb/gitweb.perl +0 -5
-# URI and label (title) of GIT logo link
-#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
-#our $logo_label = "git documentation";
-our $logo_url = "http://git-scm.com/";
-our $logo_label = "git homepage";

All right, those variables that do not need initialization using build-time substitutions are put together with their description in Gitweb::Config.

I would remove all such changes from discussion of this patch.

Quoted 2 lines

sub gitweb_get_feature {
my ($name) = @_;

[...]

I wonder if this subroutine, and its companion 'gitweb_check_feature' should be not moved to Gitweb::Config module.

gitweb/gitweb.perl

Quoted 3 lines
gitweb/gitweb.perl +2 -1
-our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
+our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
+our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";

This would probably look like this, because $GITWEB_CONFIG must be set in gitweb.perl -> gitweb.cgi, and not in Gitweb::Config, where evaluate_gitweb_config() would be.

gitweb/gitweb.perl

Quoted 12 lines
gitweb/gitweb.perl +0 -12
-sub evaluate_gitweb_config {
-	our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
-	our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
-	# die if there are errors parsing config file
-	if (-e $GITWEB_CONFIG) {
-		do $GITWEB_CONFIG;
-		die $@ if $@;
-	} elsif (-e $GITWEB_CONFIG_SYSTEM) {
-		do $GITWEB_CONFIG_SYSTEM;
-		die $@ if $@;
-	}
-}

Right, this got moved to Gitweb::Config.

gitweb/gitweb.perl

Quoted 6 lines
gitweb/gitweb.perl +0 -3
-our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
-     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
-     $searchtext, $search_regexp);
 sub evaluate_and_validate_params {
 	our $action = $input_params{'action'};
 	if (defined $action) {

Hmmm... it looks like those got also moved to Gitweb::Config, even if those variables have nothing to do with gitweb configuration, but are about request, and therefore belong to Gitweb::Request. Thus this commit should probably not touch this.

gitweb/gitweb.perl sub evaluate_and_validate_params { · line 607

Quoted 9 lines
gitweb/gitweb.perl +0 -2
@@ -963,10 +602,8 @@ sub evaluate_and_validate_params {
 	}
 }
 
-# path to the current git repository
-our $git_dir;
 sub evaluate_git_dir {
 	our $git_dir = "$projectroot/$project" if $project;
 }

Same with $git_dir -- it is request dependent, not configuration dependent.

[very large cut, not necessary with exporting variables]

Quoted 10 lines
gitweb/lib/Gitweb/Config.pm new file +4 -0
new file mode 100644
index 0000000..e1bd06f
@@ -0,0 +1,389 @@
+#!/usr/bin/perl
+#
+# Gitweb::Config -- gitweb configuration package
+#

gitweb/lib/Gitweb/Config.pm line 14

Quoted 10 lines
gitweb/lib/Gitweb/Config.pm new file +10 -0
+# This program is licensed under the GPLv2
+
+package Gitweb::Config;
+
+use strict;
+
+BEGIN {
+	use Exporter();
+
+	@Gitweb::Config::ISA = qw(Exporter);	
                                            ^^^^

Trailing whitespace. Didn't git warn you about this?

gitweb/lib/Gitweb/Config.pm line 16

Quoted 2 lines
gitweb/lib/Gitweb/Config.pm new file +2 -0
+	@Gitweb::Config::EXPORT = qw();
+}

Why BEGIN block? Why 'use Exporter();' and not 'use Exporter;'?

Why not

use Exporter;
use base 'Exporter';

or even

   use Exporter qw(import);

(we can use the last version, because gitweb requires high enough Perl version itself, so that this form can be used).

gitweb/lib/Gitweb/Config.pm line 22

Quoted 6 lines
gitweb/lib/Gitweb/Config.pm new file +6 -0
+
+our $t0;
+if (eval { require Time::HiRes; 1; }) {
+	$t0 = [Time::HiRes::gettimeofday()];
+}
+our $number_of_git_cmds = 0;

This does not strictly speaking belong in Gitweb::Config, and probably neither in Gitweb::Request, but Gitweb::request is a better place for it.

Never-mind, we can move it later.

gitweb/lib/Gitweb/Config.pm line 23

Quoted 1 line
gitweb/lib/Gitweb/Config.pm new file +1 -0
+

Here it would be good place for comment that those are variables that are affected by build-time configuration, and therefore their initialization is put in gitweb.perl (together with comments with their description).

gitweb/lib/Gitweb/Config.pm line 35

Quoted 12 lines
gitweb/lib/Gitweb/Config.pm new file +12 -0
+our ($GIT, $version, $git_version);
+our ($projectroot, $project_maxdepth, $projects_list, @git_base_url_list);
+our ($export_ok, $strict_export);
+our ($home_link_str, $site_name, $site_header, $site_footer, $home_text);
+our (@stylesheets, $stylesheet, $logo, $favicon, $javascript);
+our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
+
+# URI and label (title) of GIT logo link
+#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
+#our $logo_label = "git documentation";
+our $logo_url = "http://git-scm.com/";
+our $logo_label = "git homepage";

[cut]

Nothing especially interesting here. 'git blame -C -C' should detect code movement.

gitweb/lib/Gitweb/Config.pm line 46

Quoted 11 lines
gitweb/lib/Gitweb/Config.pm new file +11 -0
+
+sub evaluate_gitweb_config {
+	# die if there are errors parsing config file
+	if (-e $GITWEB_CONFIG) {
+		do $GITWEB_CONFIG;
+		die $@ if $@;
+	} elsif (-e $GITWEB_CONFIG_SYSTEM) {
+		do $GITWEB_CONFIG_SYSTEM;
+		die $@ if $@;
+	}
+}

Here the question is if this would affect interpretation of $GITWEB_CONFIG etc. if it is a relative path. Perhaps nothing will change, because paths are relative to the directory the script is run, not relative to where module resides.

Not that is matter much either way, as at most it would require stating in gitweb/README that one should use absolute pathnames.

Note that tests use absolute pathname, so passing test does not answer this.

gitweb/lib/Gitweb/Config.pm line 48

Quoted 2 lines
gitweb/lib/Gitweb/Config.pm new file +2 -0
+
+1;

O.K.

Good work!

Signature · 2 lines
Jakub Narebski
Poland
#1 lore raw

About [PATCH 2/2] gitweb: Create a perl module to handle gitweb cgi params and vars

This comment is about commit a6d54b3 (gitweb: Create a perl module to handle gitweb cgi params and vars, 2010-06-02) on 'master' branch of repository shown at http://repo.or.cz/w/git/gsoc2010-gitweb.git

Quoted 4 lines

From a6d54b39cee3d8d39c7ffd993b23e7477d4b0eeb Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara <[email protected]>
Date: Wed, 2 Jun 2010 01:09:51 +0530
Subject: [PATCH] gitweb: Create a perl module to handle gitweb cgi params and vars

I would probably say

Subject: [PATCH] gitweb: Create Gitweb::Request module to handle gitweb cgi params and vars

or even

Subject: [PATCH] gitweb: Create Gitweb::Request module

so that _name_ of this module is in commit subject (summary).

Quoted 7 lines

Create a perl module in path gitweb/lib/Gitweb/Request.pm to store and handle all the cgi params and global variables regarding the gitweb.perl script and change the scope of those variables in the main script.

Change Makefile accordingly to install the Perl Module.

Similar comment like for the previous patch.

You would probably want to list which subroutines were moved to Gitweb::Request, I think.

Quoted 3 lines

---

This patch would be probably based on 'next', and this should be mentioned in this area, in comment about patch.

Quoted 11 lines
 gitweb/Makefile              |    1 +
 gitweb/gitweb.perl           | 1245 ++++++++++++++++++++----------------------
 gitweb/lib/Gitweb/Request.pm |   58 ++
 3 files changed, 662 insertions(+), 642 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Request.pm
gitweb/Makefile +0 -0
index 45e176e..15646b2 100644

gitweb/Makefile GITWEB_FILES += static/git-logo.png static/git-favicon.png · line 116

Quoted 4 lines
gitweb/Makefile +1 -0
@@ -113,6 +113,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png
 
 # Files: gitweb/lib/Gitweb
 GITWEB_LIB_GITWEB += lib/Gitweb/Config.pm
+GITWEB_LIB_GITWEB += lib/Gitweb/Request.pm

Nice.

gitweb/gitweb.perl sub __DIR__ () { · line 29

Quoted 9 lines
gitweb/gitweb.perl +1 -0
index 98a85f4..263af48 100755
@@ -26,6 +26,7 @@ sub __DIR__ () {
 use lib __DIR__ . "/lib";
 
 use Gitweb::Config;
+use Gitweb::Request;

Nice.

gitweb/gitweb.perl BEGIN { · line 35

Quoted 3 lines
gitweb/gitweb.perl +0 -0
@@ -33,42 +34,6 @@ BEGIN {
 
 our $version = "++GIT_VERSION++";

The above context line changed wrt. original patch, to follow the idea about exporting variables by default in Gitweb::Config, and not using fully qualified variable names.

gitweb/gitweb.perl BEGIN { · line 37

Quoted 4 lines
gitweb/gitweb.perl +0 -3
-our ($my_url, $my_uri, $base_url, $path_info, $home_link);
-sub evaluate_uri {
-	our $cgi;

I guess that $cgi is left for gitweb.perl, isn't it, because it depends on FastCGI vs CGI? [reads later part]. I guess not, only $CGI is left in gitweb.perl.

[...]

gitweb/gitweb.perl BEGIN { · line 38

Quoted 1 line
gitweb/gitweb.perl +0 -1
-}

O.K. these variables, and evaluate_uri() is moved to Gitweb::Request.

[removed changes related to introducing fully qualified variable
names; it would make patch smaller without those]

Quoted 5 lines
gitweb/gitweb.perl +0 -1
@@ -347,13 +312,11 @@ our %allowed_options = (
 # build an array of parameters that can be multi-valued, but since for the time
 # being it's only this one, we just single it out
 sub evaluate_query_params {
-	our $cgi;

[...]

Quoted 5 lines

}

gitweb/gitweb.perl +0 -0
@@ -361,12 +324,12 @@ sub evaluate_query_params {
 # now read PATH_INFO and update the parameter list for missing parameters
 sub evaluate_path_info {

[...]

Quoted 3 lines

}

sub evaluate_and_validate_params {

[...]

Quoted 1 line

}

Shouldn't evaluate_query_params(), evaluate_path_info(), and the subroutine that ties them together evaluate_and_validate_params() be in Gitweb::Request too?

Quoted 2 lines

sub evaluate_git_dir {

[....]

Quoted 1 line

}

Ditto with evaluate_git_dir()?

BTW. as I said in comment to previous patch, vriables such as $project should be put in Gitweb::Request in my opinion, not in Gitweb::Config. Perhaps they are, but it is not obvious from this patch.

Quoted 6 lines

our (@snapshot_fmts, $git_avatar);

gitweb/gitweb.perl +0 -0
@@ -643,32 +605,32 @@ set_message(\&handle_errors_html);
 
 # dispatch
 sub dispatch {

[...]

Quoted 3 lines

}

sub run_request {

Those two subroutines should not, I guess, be put in Gitweb::Request. They would be in catch-all Gitweb module, I guess, or perhaps in the later post-GSoC future in Gitweb::Dispatch or something.

gitweb/gitweb.perl sub run_request { · line 655

Quoted 7 lines
gitweb/gitweb.perl +0 -1
@@ -689,7 +651,6 @@ sub run_request {
 our $is_last_request = sub { 1 };
 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
 our $CGI = 'CGI';
-our $cgi;
 sub evaluate_argv {
 	return unless (@ARGV);

Ah, so $CGI is left in gitweb.perl, $cgi is moved to Gitweb::Request.

[cut more than half of patch, which sould not be needed with exporting
variables and not using fully qualified variable names]

gitweb/lib/Gitweb/Request.pm line 5

Quoted 11 lines
gitweb/lib/Gitweb/Request.pm new file +5 -0
new file mode 100644
index 0000000..91cc492
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+#
+# Gitweb::Request -- gitweb request(cgi) package
+#
+# This program is licensed under the GPLv2

I don't remember what is git policy on copyright statements, and on GPLv2 vs GPLv2+...

gitweb/lib/Gitweb/Request.pm line 16

Quoted 11 lines
gitweb/lib/Gitweb/Request.pm new file +11 -0
+
+package Gitweb::Request;
+
+use strict;
+
+BEGIN {
+	use Exporter();
+
+	@Gitweb::Request::ISA = qw(Exporter);	
+	@Gitweb::Request::EXPORT = qw();
+}

Same comment as for previous patch.

   use Exporter qw(import);
   our @EXPORT = qw($cgi, $my_url, $my_uri, $base_url, ...);

BTW with exporting variables you can easily see here that Gitweb::Request does not use any variable from Gitweb::Config.

Quoted 7 lines
gitweb/lib/Gitweb/Request.pm new file +7 -0
+
+our ($cgi, $my_url, $my_uri, $base_url, $path_info, $home_link);
+our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
+     $hash_parent_base, @extra_options, $page, $git_dir);
+our ($searchtype, $search_use_regexp, $searchtext, $search_regexp);
+
+sub evaluate_uri {

[...]

Quoted 1 line

+}

Straightforward code movement. But see comment above on which subroutines I feel should be also put in Gitweb::Request.

Signature · 2 lines
Jakub Narebski
Poland
#2 lore raw

Re: About [PATCH 2/2] gitweb: Create a perl module to handle gitweb cgi params and vars

Quoted 10 lines

Shouldn't evaluate_query_params(), evaluate_path_info(), and the subroutine that ties them together evaluate_and_validate_params() be in Gitweb::Request too?

Quoted 2 lines

 sub evaluate_git_dir {

[....]

Quoted 1 line

 }

Ditto with evaluate_git_dir()?

Well, evaluate_and_validate_params() and evaluate_path_info() contains calls to subroutines which are not yet moved into any package. So, what do you want to in such a case ?

Quoted 11 lines

BTW. as I said in comment to previous patch, vriables such as $project should be put in Gitweb::Request in my opinion, not in Gitweb::Config. Perhaps they are, but it is not obvious from this patch.

Quoted 6 lines

 our (@snapshot_fmts, $git_avatar);

(quoted diff) +0 -0
@@ -643,32 +605,32 @@ set_message(\&handle_errors_html);
 
  # dispatch
  sub dispatch {

[...]

Quoted 7 lines
Quoted 3 lines

 }

 sub run_request {

Those two subroutines should not, I guess, be put in Gitweb::Request. They would be in catch-all Gitweb module, I guess, or perhaps in the later post-GSoC future in Gitweb::Dispatch or something.

Yes.

Quoted 56 lines

Review sub run_request { · line 655

Quoted 7 lines
(quoted diff) +0 -1
@@ -689,7 +651,6 @@ sub run_request {
  our $is_last_request = sub { 1 };
  our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
  our $CGI = 'CGI';
-our $cgi;
  sub evaluate_argv {
       return unless (@ARGV);

Ah, so $CGI is left in gitweb.perl, $cgi is moved to Gitweb::Request.

[cut more than half of patch, which sould not be needed with exporting variables and not using fully qualified variable names]

gitweb/lib/Gitweb/Request.pm line 5

Quoted 11 lines
gitweb/lib/Gitweb/Request.pm new file +5 -0
new file mode 100644
index 0000000..91cc492
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+#
+# Gitweb::Request -- gitweb request(cgi) package
+#
+# This program is licensed under the GPLv2

I don't remember what is git policy on copyright statements, and on GPLv2 vs GPLv2+...

gitweb/lib/Gitweb/Request.pm line 16

Quoted 11 lines
gitweb/lib/Gitweb/Request.pm new file +11 -0
+
+package Gitweb::Request;
+
+use strict;
+
+BEGIN {
+     use Exporter();
+
+     @Gitweb::Request::ISA = qw(Exporter);
+     @Gitweb::Request::EXPORT = qw();
+}

Same comment as for previous patch.

  use Exporter qw(import);
  our @EXPORT = qw($cgi, $my_url, $my_uri, $base_url, ...);

BTW with exporting variables you can easily see here that Gitweb::Request does not use any variable from Gitweb::Config.

Quoted 7 lines
gitweb/lib/Gitweb/Request.pm new file +7 -0
+
+our ($cgi, $my_url, $my_uri, $base_url, $path_info, $home_link);
+our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
+     $hash_parent_base, @extra_options, $page, $git_dir);
+our ($searchtype, $search_use_regexp, $searchtext, $search_regexp);
+
+sub evaluate_uri {

[...]

Quoted 4 lines
Quoted 1 line

+}

Straightforward code movement.  But see comment above on which subroutines I feel should be also put in Gitweb::Request.

Please answer the question regarding calls to not-yet-packaged subroutines.

Thanks,
Pavan.

#3 lore raw

Re: About [PATCH 2/2] gitweb: Create a perl module to handle gitweb cgi params and vars

Quoted 11 lines · Pavan Kumar Sunkara
Quoted 5 lines · Jakub Narebski

Shouldn't evaluate_query_params(), evaluate_path_info(), and the subroutine that ties them together evaluate_and_validate_params() be in Gitweb::Request too?

Ditto with evaluate_git_dir()?

Well, evaluate_and_validate_params() and evaluate_path_info() contains calls to subroutines which are not yet moved into any package. So, what do you want to in such a case ?

O.K., in this case you should mention in the commit message that the subroutines evaluate_query_params(), evaluate_path_info(), evaluate_and_validate_params() and evaluate_git_dir() didn't get moved to Gitweb::Request because evaluate_and_validate_params() and evaluate_path_info() contain calls to check_head_link(), die_error() and validate_*() subroutines which are not yet moved into any package. And it doesn't make sense to put only some of them in Gitweb::Request.

We can always move them later.

P.S. The validate_*() subroutines could also be moved to Gitweb::Request. The check_head_link() subroutine looks like candidate for Gitweb::Util / Gitweb::Utils; I am not sure where one should put die_error() and friends: git_header_html(), git_footer_html(), get_page_title(), and other subroutines they use.

Signature · 2 lines
Jakub Narebski
Poland
#4 lore raw
In reply to Jakub Narebski

2010/6/3 Jakub Narebski <[email protected]>:

Quoted 24 lines

This comment is about commit 9526ab8 (gitweb: Create a perl module to store gitweb configuration, 2010-06-01) on 'master' branch of repository shown at http://repo.or.cz/w/git/gsoc2010-gitweb.git

Quoted 4 lines

From 9526ab8a12c8d4d875d08a6201c7eca963c7d9aa Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara <[email protected]>
Date: Tue, 1 Jun 2010 02:36:48 +0530
Subject: [PATCH] gitweb: Create a perl module to store gitweb configuration

I would probably say

 Subject: [PATCH] gitweb: Create Gitweb::Config module to store gitweb configuration

or even

 Subject: [PATCH] gitweb: Create Gitweb::Config module

so that _name_ of this module is in commit subject (summary).

Quoted 4 lines

Create a perl module in path gitweb/lib/Gitweb/Config.pm to store all the configuration variables of the gitweb.perl script and change the scope of those variables in main script.

Quoted 7 lines

A bit overlong sentence, isn't it?  Perhaps

 Create a Gitweb::Config module in 'gitweb/lib/Gitweb/Config.pm' to store all the configuration variables of the gitweb.perl script.

(Assuming that I can convince you to avoid fully qualified names).

Ok.

Quoted 10 lines
Quoted 4 lines

Move subroutine evaluate_gitweb_config() into the same module so that the statement 'do GITWEB_CONFIG' or 'do GITWEB_CONFIG_SYSTEM' works similiar to the working before the split.

s/similiar/similar/

I agree that you should list which subroutines you do move to Gitweb::Config package, though this list would be probably longer that the evaluate_gitweb_config() alone... or perhaps not.

Ok.

Quoted 3 lines

But I do not understand the statement about "do $GITWEB_CONFIG" etc. here.  Did you wanted to say that setting $GITWEB_CONFIG etc. was moved out of evaluate_gitweb_config(), and is left in gitweb.perl?

Nope. I actually wanted to say that any of the previous gitweb_config.perl will work without the problems of scoping.

Quoted 8 lines
Quoted 2 lines

Change Makefile accordingly to install the Perl Module.

I would say:

 Update gitweb/Makefile to install gitweb modules alongside gitweb.

Or something like that.

Ok.

Quoted 10 lines
Quoted 3 lines

---

When sending this patch to git mailing list you should mention that it is based on
 gitweb: Put all per-connection code in run() subroutine and perhaps also on
 gitweb: Add support for FastCGI, using CGI::Fast
unless those two commits made it into 'master' till then.

Ok.

Quoted 19 lines
Quoted 11 lines

 gitweb/Makefile             |    6 +
 gitweb/gitweb.perl          |  692 ++++++++++--------------------------------- gitweb/lib/Gitweb/Config.pm |  389 ++++++++++++++++++++++++

 3 files changed, 558 insertions(+), 529 deletions(-)

 create mode 100644 gitweb/lib/Gitweb/Config.pm

gitweb/Makefile +0 -0
index d2584fe..45e176e 100644
@@ -55,6 +55,7 @@ PERL_PATH  ?= /usr/bin/perl
Quoted 4 lines

 bindir_SQ = $(subst ','\'',$(bindir))#' gitwebdir_SQ = $(subst ','\'',$(gitwebdir))#' gitwebstaticdir_SQ = $(subst ','\'',$(gitwebdir)/static)#' +gitweblibdir_SQ = $(subst ','\'',$(gitwebdir)/lib)#'

I think it would be good idea to have 'gitweblibdir' as a separate variable, alongside 'gitwebdir', and which would default to

Quoted 8 lines

  gitweblibdir = $(gitwebdir)/lib

to make it possible to install gitweb modules not alongside gitweb, but somewhere else, for example together with other Perl modules.

Then you would have:

 +gitweblibdir_SQ = $(subst ','\'',$(gitweblibdir))#'

It's great.

Quoted 6 lines

But I think this change can be left for a separate commit.  It is not something terribly important, something blocking accepting the patch.

BTW. did you start working on the 'write' part yet, at least on the conceptual (specification / architecture) level?

Yeah. I have already written some of it in python before I applied for gsoc. So, I have a good idea over it on the conceptual level.

Quoted 16 lines
Quoted 16 lines

 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#'
 PERL_PATH_SQ  = $(subst ','\'',$(PERL_PATH))#'
 DESTDIR_SQ    = $(subst ','\'',$(DESTDIR))#'

gitweb/Makefile +0 -0
@@ -110,6 +111,9 @@ endif
 

 GITWEB_FILES += static/git-logo.png static/git-favicon.png

gitweb/Makefile +3 -0
+# Files: gitweb/lib/Gitweb
+GITWEB_LIB_GITWEB += lib/Gitweb/Config.pm
+

 GITWEB_REPLACE = \
      -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
      -e 's|++GIT_BINDIR++|$(bindir)|g' \

gitweb/Makefile +0 -0
@@ -150,6 +154,8 @@ install: all

      $(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)' $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'

Quoted 8 lines
Quoted 3 lines

      $(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
+     $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb'
+     $(INSTALL) -m 644 $(GITWEB_LIB_GITWEB) '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb'

Uhhh... this would probably get more complicated *if* there would be more complicated hierarchy, e.g. if there would be Gitweb module in lib/Gitweb.pm.  I guess that is the reason behind $(GITWEB_LIB_GITWEB) name, isn't it?

Yes. Exactly.

Quoted 27 lines
Quoted 8 lines

 ### Cleaning rules

gitweb/gitweb.perl +0 -0
index 673e7a3..98a85f4 100755

gitweb/gitweb.perl use Encode; · line 21

Quoted 6 lines
gitweb/gitweb.perl +1 -0
@@ -16,19 +16,22 @@ use Encode;
  use Fcntl ':mode';
  use File::Find qw();
  use File::Basename qw(basename);
+use File::Spec;
  binmode STDOUT, ':utf8';
 

The fragment below was slightly edited to make it more clear.

gitweb/gitweb.perl use Encode; · line 25

Quoted 5 lines
gitweb/gitweb.perl +0 -5
-our $t0;
-if (eval { require Time::HiRes; 1; }) {
-     $t0 = [Time::HiRes::gettimeofday()];
-}
-our $number_of_git_cmds = 0;

Theoretically neither $t0 nor $number_of_git_cmds belong to Gitweb::Config, as those are about runtime timing, not about gitweb configuration.

Quoted 1 line

But perhaps for the time being you can put it in Gitweb::Config.

Ok.

Quoted 19 lines

gitweb/gitweb.perl use Encode; · line 28

Quoted 7 lines
gitweb/gitweb.perl +7 -0
+# __DIR__ is taken from Dir::Self __DIR__ fragment
+sub __DIR__ () {
+     File::Spec->rel2abs(join '', (File::Spec->splitpath(__FILE__))[0, 1]);
+}
+use lib __DIR__ . "/lib";
+
+use Gitweb::Config;

O.K.

It's a pity that Dir::Self is not a core Perl module since Perl 5.8, and that FindBin which is in core since 5.4 has its quirks and nowadays is not recommended to use...

Quoted 5 lines
gitweb/gitweb.perl +0 -0
  BEGIN {
       CGI->compile() if $ENV{'MOD_PERL'};
  }
 
Quoted 5 lines

gitweb/gitweb.perl use Encode; · line 33

Quoted 2 lines
gitweb/gitweb.perl +1 -1
-our $version = "++GIT_VERSION++";
+$Gitweb::Config::version = "++GIT_VERSION++";

If '$version' was exported by Gitweb::Config this change would be not necessary.

Yeah. I am currently removing them.

Quoted 12 lines

I would remove all such changes from discussion of this patch.

gitweb/gitweb.perl use Encode;

Quoted 5 lines
gitweb/gitweb.perl +0 -5
-# URI and label (title) of GIT logo link
-#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
-#our $logo_label = "git documentation";
-our $logo_url = "http://git-scm.com/";
-our $logo_label = "git homepage";

All right, those variables that do not need initialization using build-time substitutions are put together with their description in Gitweb::Config.

Quoted 8 lines

I would remove all such changes from discussion of this patch.

Quoted 2 lines

 sub gitweb_get_feature {
      my ($name) = @_;

[...]

I wonder if this subroutine, and its companion 'gitweb_check_feature' should be not moved to Gitweb::Config module.

Ok. Will do it.

Quoted 30 lines

gitweb/gitweb.perl

Quoted 3 lines
gitweb/gitweb.perl +2 -1
-our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
+our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
+our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";

This would probably look like this, because $GITWEB_CONFIG must be set in gitweb.perl -> gitweb.cgi, and not in Gitweb::Config, where evaluate_gitweb_config() would be.

gitweb/gitweb.perl

Quoted 12 lines
gitweb/gitweb.perl +0 -12
-sub evaluate_gitweb_config {
-     our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
-     our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
-     # die if there are errors parsing config file
-     if (-e $GITWEB_CONFIG) {
-             do $GITWEB_CONFIG;
-             die $@ if $@;
-     } elsif (-e $GITWEB_CONFIG_SYSTEM) {
-             do $GITWEB_CONFIG_SYSTEM;
-             die $@ if $@;
-     }
-}

Right, this got moved to Gitweb::Config.

Quoted 6 lines

-our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
-     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
-     $searchtext, $search_regexp);
 sub evaluate_and_validate_params {
      our $action = $input_params{'action'};
      if (defined $action) {

Quoted 4 lines

Hmmm... it looks like those got also moved to Gitweb::Config, even if those variables have nothing to do with gitweb configuration, but are about request, and therefore belong to Gitweb::Request.  Thus this commit should probably not touch this.

Sorry. That was a mistake. I probably ammended the commit while working on Gitweb:Request Module.

Quoted 49 lines

gitweb/gitweb.perl sub evaluate_and_validate_params { · line 607

Quoted 9 lines
gitweb/gitweb.perl +0 -2
@@ -963,10 +602,8 @@ sub evaluate_and_validate_params {
       }
  }
 
-# path to the current git repository
-our $git_dir;
  sub evaluate_git_dir {
       our $git_dir = "$projectroot/$project" if $project;
  }

Same with $git_dir -- it is request dependent, not configuration dependent.

[very large cut, not necessary with exporting variables]

Quoted 10 lines
gitweb/lib/Gitweb/Config.pm new file +4 -0
new file mode 100644
index 0000000..e1bd06f
@@ -0,0 +1,389 @@
+#!/usr/bin/perl
+#
+# Gitweb::Config -- gitweb configuration package
+#

gitweb/lib/Gitweb/Config.pm line 14

Quoted 10 lines
gitweb/lib/Gitweb/Config.pm new file +10 -0
+# This program is licensed under the GPLv2
+
+package Gitweb::Config;
+
+use strict;
+
+BEGIN {
+     use Exporter();
+
+     @Gitweb::Config::ISA = qw(Exporter);

                                           ^^^^

Trailing whitespace.  Didn't git warn you about this?

gitweb/lib/Gitweb/Config.pm line 16

Quoted 2 lines
gitweb/lib/Gitweb/Config.pm new file +2 -0
+     @Gitweb::Config::EXPORT = qw();
+}

Why BEGIN block?  Why 'use Exporter();' and not 'use Exporter;'?

Why not

  use Exporter;
  use base 'Exporter';

Quoted 6 lines

or even

  use Exporter qw(import);

(we can use the last version, because gitweb requires high enough Perl version itself, so that this form can be used).

Ok. Sure.

Quoted 11 lines

gitweb/lib/Gitweb/Config.pm line 22

Quoted 6 lines
gitweb/lib/Gitweb/Config.pm new file +6 -0
+
+our $t0;
+if (eval { require Time::HiRes; 1; }) {
+     $t0 = [Time::HiRes::gettimeofday()];
+}
+our $number_of_git_cmds = 0;

This does not strictly speaking belong in Gitweb::Config, and probably neither in Gitweb::Request, but Gitweb::request is a better place for it.

Quoted 8 lines

Never-mind, we can move it later.

gitweb/lib/Gitweb/Config.pm line 23

Quoted 1 line
gitweb/lib/Gitweb/Config.pm new file +1 -0
+

Here it would be good place for comment that those are variables that are affected by build-time configuration, and therefore their initialization is put in gitweb.perl (together with comments with their description).

Ok.

Quoted 35 lines

gitweb/lib/Gitweb/Config.pm line 35

Quoted 12 lines
gitweb/lib/Gitweb/Config.pm new file +12 -0
+our ($GIT, $version, $git_version);
+our ($projectroot, $project_maxdepth, $projects_list, @git_base_url_list);
+our ($export_ok, $strict_export);
+our ($home_link_str, $site_name, $site_header, $site_footer, $home_text);
+our (@stylesheets, $stylesheet, $logo, $favicon, $javascript);
+our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
+
+# URI and label (title) of GIT logo link
+#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
+#our $logo_label = "git documentation";
+our $logo_url = "http://git-scm.com/";
+our $logo_label = "git homepage";

[cut]

Nothing especially interesting here.  'git blame -C -C' should detect code movement.

gitweb/lib/Gitweb/Config.pm line 46

Quoted 11 lines
gitweb/lib/Gitweb/Config.pm new file +11 -0
+
+sub evaluate_gitweb_config {
+     # die if there are errors parsing config file
+     if (-e $GITWEB_CONFIG) {
+             do $GITWEB_CONFIG;
+             die $@ if $@;
+     } elsif (-e $GITWEB_CONFIG_SYSTEM) {
+             do $GITWEB_CONFIG_SYSTEM;
+             die $@ if $@;
+     }
+}

Here the question is if this would affect interpretation of $GITWEB_CONFIG etc. if it is a relative path.  Perhaps nothing will change, because paths are relative to the directory the script is run, not relative to where module resides.

Quoted 5 lines

Not that is matter much either way, as at most it would require stating in gitweb/README that one should use absolute pathnames.

Note that tests use absolute pathname, so passing test does not answer this.

Will check it out and update README accoringly.

Quoted 10 lines

gitweb/lib/Gitweb/Config.pm line 48

Quoted 2 lines
gitweb/lib/Gitweb/Config.pm new file +2 -0
+
+1;

O.K.

Good work!
--
Jakub Narebski
Poland

Thanks,
Pavan.

#5 lore raw
Quoted 21 lines · Pavan Kumar Sunkara

2010/6/3 Jakub Narebski <[email protected]>:

Quoted 20 lines

This comment is about commit 9526ab8 (gitweb: Create a perl module to store gitweb configuration, 2010-06-01) on 'master' branch of repository shown at http://repo.or.cz/w/git/gsoc2010-gitweb.git

gitweb/Makefile PERL_PATH ?= /usr/bin/perl · line 58

Quoted 9 lines
gitweb/Makefile +1 -0
index d2584fe..45e176e 100644
@@ -55,6 +55,7 @@ PERL_PATH  ?= /usr/bin/perl
 bindir_SQ = $(subst ','\'',$(bindir))#'
 gitwebdir_SQ = $(subst ','\'',$(gitwebdir))#'
 gitwebstaticdir_SQ = $(subst ','\'',$(gitwebdir)/static)#'
+gitweblibdir_SQ = $(subst ','\'',$(gitwebdir)/lib)#'

I think it would be good idea to have 'gitweblibdir' as a separate variable, alongside 'gitwebdir', and which would default to

  gitweblibdir = $(gitwebdir)/lib
Quoted 11 lines
Quoted 6 lines

to make it possible to install gitweb modules not alongside gitweb, but somewhere else, for example together with other Perl modules.

Then you would have:

+gitweblibdir_SQ = $(subst ','\'',$(gitweblibdir))#'

It's great.

Quoted 2 lines

But I think this change can be left for a separate commit. It is not something terribly important, something blocking accepting the patch.

Actually to really be able to put gitweb packages somewhere else, gitweb.perl should *probably* contain

use lib '++GITWEBLIBDIR++';

Otherwise 'gitweblibdir' would have to be either left default to install packages alingside gitweb.cgi script, or be directory that is in PERL5LIB for web server.

So let's leave it for a later commit.

Signature · 2 lines
Jakub Narebski
Poland