Skip to contentSkip to conversation

Splitting gitweb

PATCH In review Pavan Kumar Sunkara 4 participants 27 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover Splitting gitweb

The patch series is based on 'pu' branch.

10 patches out of the 11 patches in this patch series split gitweb into several small sized modules which is one of the goal of my GSoC's project.

The first patch of this patch series is for fixing esc_url function which is previously missed by commit 425e225.

The second patch is produced by my commit ammend to jakub nareski's initial commit to prepare splitting of gitweb in the message-id:
http://mid.gmane.org/[email protected]

There is a small ammendment to that patch.
$(INSTALL) -m 644 $(mod) '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(mod)'
is changed to
$(INSTALL) -m 644 $(mod) '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir $(mod))';) because it is better if we gave 'dir $(mod)' as the target for install command rather than '$(mod)' because it may cause problems in the future when gitweblibdir is used and the modules are installed elsewhere rather than in /use/share/gitweb.

The modules created and being used by Gitweb are
Gitweb::Git
Gitweb::Config
Gitweb::Request
Gitweb::Escape
Gitweb::RepoConfig
Gitweb::View
Gitweb::Util
Gitweb::Format
Gitweb::Parse

Table of contents:
=======

1. gitweb: fix esc_url
The custom CGI escaping done in esc_url failed to escape UTF-8 properly. Fix by using CGI::escape on each sequence of matched characters instead of sprintf()ing a custom escaping for each byte.

Additionally, the space -> + escape was being escaped due to greedy matching on the first substitution. Fix by adding space to the list of characters not handled on the first substitution.

Finally, remove an unnecessary escaping of the + sign.

commit 452e225 has missed fixing esc_url.

2. gitweb: Prepare for splitting gitweb
Prepare gitweb for having been split into modules that are to be installed alongside gitweb in 'lib/' subdirectory, by adding

use lib __DIR__.'/lib';

to gitweb.perl (to main gitweb script), and preparing for putting modules (relative path) in $(GITWEB_MODULES) in gitweb/Makefile.

3. gitweb: Create Gitweb::Git module
Create a Gitweb::Git module in 'gitweb/lib/Gitweb/Git.pm' to deal with running git commands (and also processing output of git commands with external programs) from gitweb.

This module is intended as standalone module, which does not require (include) other gitweb' modules to avoid circular dependencies. That is why it includes $GIT variable, even though this variable is configured during building gitweb. On the other hand $GIT is more about git configuration, than gitweb configuration.

Subroutines moved:
evaluate_git_version
git_cmd
quote_command

Update gitweb/Makefile to install Gitweb::Git module alongside gitweb

4. gitweb: Create Gitweb::Config module
Create Gitweb::Config module in 'gitweb/lib/Gitweb/Config.pm' to store all the configuration variables and subroutines regarding the gitweb.perl script.

This module depends only on $git_dir from Gitweb::Git and includes the configuration related variables and subroutines (Including those required for configuration of gitweb features)

Subroutines moved:
evaluate_gitweb_config
configure_gitweb_features
filter_snapshot_fmts
gitweb_get_feature
gitweb_check_feature

Update gitweb/Makefile to install Gitweb::Config module alongside gitweb

5. gitweb: Create Gitweb::Request module
Create a Gitweb::Request module in 'gitweb/lib/Gitweb/Request.pm' to store and handle all the cgi params and related variables regarding the gitweb.perl script.

This module is intended as standalone module, which does not require (include) other gitweb' modules to avoid circular dependencies.

Subroutines moved:
evaluate_uri
evaluate_query_params

Update gitweb/Makefile to install Gitweb::Request module alongside gitweb

6. gitweb: Create Gitweb::Escape module
Create a Gitweb::Escape module in 'gitweb/lib/Gitweb/Escape.pm' to store all the quoting/unquoting and escaping subroutines regarding the gitweb.perl script.

This module imports $fallback_encoding variable from Gitweb::Config module to use it in sub 'to_utf8'

Subroutines moved:

	to_utf8
	esc_param
	esc_url
	esc_html
	esc_path
	quot_cec
	quot_upr
	untabify

Update gitweb/Makefile to install Gitweb::Escape module alongside gitweb

7. gitweb: Create Gitweb::RepoConfig module
Create a Gitweb::RepoConfig module in 'gitweb/lib/Gitweb/RepoConfig.pm' to store and handle all the configuration and subroutines related to a single repository regarding the gitweb.perl script.

This module depend on several other modules like Git.pm, Config.pm, Request.pm and Escape.pm.

It also include subroutines regarding project_list and it's handling.

Subroutines moved:
check_head_link
check_export_ok
hash_set_multi
git_parse_project_config
config_to_bool
config_to_int
config_to_multi
feature_bool
feature_snapshot
feature_patches
feature_avatar
git_get_project_config
git_get_project_description
git_get_project_ctags
git_populate_project_tagcloud
git_show_project_tagcloud
git_get_project_url_list
git_get_projects_list
git_get_project_list_from_file
git_get_project_owner
get_file_owner
project_in_list

Update gitweb/Makefile to install Gitweb::RepoConfig module alongside gitweb

8. gitweb: Create Gitweb::View module
Create Gitweb::View module in 'gitweb/lib/Gitweb/View.pm' to store the subroutines related to the HTML output for gitweb.

This module depends on Git.pm, Config.pm, Request.pm, Escape.pm and RepoConfig.pm. Action specific HTML div subroutines are not included in this module due to unmet dependencies of Gitweb::Parse and Gitweb::Format.

Subroutines moved:
*href
get_feed_info
*chop_str
chop_and_escape_str
*age_class
age_string
*S_ISGITLINK
mode_str
file_type
file_type_long
*get_page_title
git_header_html
git_footer_html
die_error
*git_print_page_nav
format_paging_nav
git_print_header_div
git_print_page_path
*print_local_time
format_local_time
*insert_file
*git_get_link_target
normalize_link_target
git_print_tree_entry
*print_sort_th
format_sort_th

Update 'gitweb/Makefile' to install Gitweb::View alongside gitweb.

9. gitweb: Create Gitweb::Util module
Create Gitweb::Util module in 'gitweb/lib/Gitweb/Util.pm' to store the git utility subroutines related to gitweb.

This module include subroutines in various categories such as git utility subs invoking git commands, git utility subs accessing git repository, mimetype related subs and HTML output utility subs.

Subroutines moved:
git_get_head_hash
git_get_full_hash
git_get_short_hash
git_get_hash
git_get_type
git_get_hash_by_path
git_get_path_by_hash
git_get_last_activity
git_get_references
git_get_rev_name_tags
git_get_heads_list
git_get_tags_list
mimetype_guess_file
mimetype_guess
blob_mimetype
blob_contenttype
guess_file_syntax
run_highlighter
fill_from_file_info
is_deleted
is_patch_split

Update 'gitweb/Makefile' to install Gitweb::Util alongside gitweb.

10. gitweb: Create Gitweb::Format module
Create Gitweb::Format module in 'gitweb/lib/Gitweb/Format.pm' to store the subroutines related to formatting of HTML fragments required for gitweb.

This module depends on Config.pm, View.pm, Escape.pm, Util.pm and Request.pm. It mainly contain functions returning short HTML fragments or transforming HTML fragments. Also include subroutines regarding avatar formatting.

Subroutines moved:
format_log_line_html
format_ref_marker
format_subject_html
picon_url
gravatar_url
git_get_avatar
format_search_author
format_author_html
format_git_diff_header_line
format_extended_diff_header_line
format_diff_from_to_header
format_diff_cc_simplified
format_diff_line
format_snapshot_links

Update 'gitweb/Makefile' to install Gitweb::Format alongside gitweb.

11. gitweb: Create Gitweb::Parse module
Create Gitweb::Parse module in 'gitweb/lib/Gitweb/Parse.pm' to store the subroutines which related to parsing functions required for gitweb.

This module depends on Git.pm, Escape.pm, View.pm and Util.pm.

Subroutines moved:
unquote
parse_date
parse_tag
parse_commit_text
parse_commit
parse_commits
parse_difftree_raw_line
parsed_difftree_line
parse_ls_tree_line
parse_from_to_diffinfo

Update 'gitweb/Makefile' to install Gitweb::Parse alongside gitweb.

Pavan Kumar Sunkara (11):
gitweb: fix esc_url
gitweb: Prepare for splitting gitweb
gitweb: Create Gitweb::Git module
gitweb: Create Gitweb::Config module
gitweb: Create Gitweb::Request module
gitweb: Create Gitweb::Escape module
gitweb: Create Gitweb::RepoConfig module
gitweb: Create Gitweb::View module
gitweb: Create Gitweb::Util module
gitweb: Create Gitweb::Format module
gitweb: Create Gitweb::Parse module

 gitweb/Makefile                 |   14 +
 gitweb/gitweb.perl              | 3861 +++------------------------------------
 gitweb/lib/Gitweb/Config.pm     |  498 +++++
 gitweb/lib/Gitweb/Escape.pm     |  138 ++
 gitweb/lib/Gitweb/Format.pm     |  537 ++++++
 gitweb/lib/Gitweb/Git.pm        |   48 +
 gitweb/lib/Gitweb/Parse.pm      |  414 +++++
 gitweb/lib/Gitweb/RepoConfig.pm |  466 +++++
 gitweb/lib/Gitweb/Request.pm    |  119 ++
 gitweb/lib/Gitweb/Util.pm       |  447 +++++
 gitweb/lib/Gitweb/View.pm       | 1022 +++++++++++
 11 files changed, 3915 insertions(+), 3649 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Config.pm
 create mode 100644 gitweb/lib/Gitweb/Escape.pm
 create mode 100644 gitweb/lib/Gitweb/Format.pm
 create mode 100644 gitweb/lib/Gitweb/Git.pm
 create mode 100644 gitweb/lib/Gitweb/Parse.pm
 create mode 100644 gitweb/lib/Gitweb/RepoConfig.pm
 create mode 100644 gitweb/lib/Gitweb/Request.pm
 create mode 100644 gitweb/lib/Gitweb/Util.pm
 create mode 100644 gitweb/lib/Gitweb/View.pm
#1 lore raw

PATCH v2 1/11 gitweb: fix esc_url

The custom CGI escaping done in esc_url failed to escape UTF-8 properly. Fix by using CGI::escape on each sequence of matched characters instead of sprintf()ing a custom escaping for each byte.

Additionally, the space -> + escape was being escaped due to greedy matching on the first substitution. Fix by adding space to the list of characters not handled on the first substitution.

Finally, remove an unnecessary escaping of the + sign.

commit 452e225 has missed fixing esc_url.

---
 gitweb/gitweb.perl |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +1 -2
index 9446376..518328f 100755
@@ -1322,8 +1322,7 @@ sub esc_param {
 sub esc_url {
 	my $str = shift;
 	return undef unless defined $str;
-	$str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
-	$str =~ s/\+/%2B/g;
+	$str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;
 	$str =~ s/ /\+/g;
 	return $str;
 }
Signature · 1 line
1.7.1.455.g8f441
#2 lore raw

Re: [PATCHv2 GSOC 01/11] gitweb: fix esc_url

Quoted 8 lines · Pavan Kumar Sunkara

The custom CGI escaping done in esc_url failed to escape UTF-8 properly. Fix by using CGI::escape on each sequence of matched characters instead of sprintf()ing a custom escaping for each byte.

Additionally, the space -> + escape was being escaped due to greedy matching on the first substitution. Fix by adding space to the list of characters not handled on the first substitution.

Quoted 5 lines

Finally, remove an unnecessary escaping of the + sign.

commit 452e225 has missed fixing esc_url.

First, as this patch is independent and unrelated to either splitting gitweb, or write support, it would be better if this patch was sent individually to git mailing list, and not only as a part of a large patch series. It would likely to be applied, as it is pure bugfix.

Second, I would probably write commit message differently, to emphasize that it is just finishing work of commit 452e225 (gitweb: fix esc_param, 2009-10-13) by fixing esc_url like it fixed esc_params. But it is not something very important.

For what it is worth, ACK from me for this patch.

Quoted 22 lines
---
 gitweb/gitweb.perl |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +1 -2
index 9446376..518328f 100755
@@ -1322,8 +1322,7 @@ sub esc_param {
 sub esc_url {
 	my $str = shift;
 	return undef unless defined $str;
-	$str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
-	$str =~ s/\+/%2B/g;
+	$str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;
 	$str =~ s/ /\+/g;
 	return $str;
 }
Signature · 1 line
1.7.1.455.g8f441
Signature · 2 lines
Jakub Narebski
Poland
#3 lore raw

Re: [PATCHv2 GSOC 01/11] gitweb: fix esc_url

Quoted 20 lines · Jakub Narebski
Quoted 8 lines · Pavan Kumar Sunkara

The custom CGI escaping done in esc_url failed to escape UTF-8 properly. Fix by using CGI::escape on each sequence of matched characters instead of sprintf()ing a custom escaping for each byte.

Additionally, the space -> + escape was being escaped due to greedy matching on the first substitution. Fix by adding space to the list of characters not handled on the first substitution.

Quoted 5 lines

Finally, remove an unnecessary escaping of the + sign.

commit 452e225 has missed fixing esc_url.

First, as this patch is independent and unrelated to either splitting gitweb, or write support, it would be better if this patch was sent individually to git mailing list, and not only as a part of a large patch series. It would likely to be applied, as it is pure bugfix.

Quoted 4 lines

Second, I would probably write commit message differently, to emphasize that it is just finishing work of commit 452e225 (gitweb: fix esc_param, 2009-10-13) by fixing esc_url like it fixed esc_params. But it is not something very important.

I tentatively rewrote the message like so:

Earlier, 452e225 (gitweb: fix esc_param, 2009-10-13) fixed CGI escaping rules used in esc_url. A very similar logic exists in esc_param and needs to be fixed the same way.

It makes one wonder why they have to be separate functions, doesn't it, though?

Quoted 1 line

For what it is worth, ACK from me for this patch.

Thanks

#4 lore raw

Re: [PATCHv2 GSOC 01/11] gitweb: fix esc_url

Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Jakub Narebski
Quoted 13 lines · Pavan Kumar Sunkara

The custom CGI escaping done in esc_url failed to escape UTF-8 properly. Fix by using CGI::escape on each sequence of matched characters instead of sprintf()ing a custom escaping for each byte.

Additionally, the space -> + escape was being escaped due to greedy matching on the first substitution. Fix by adding space to the list of characters not handled on the first substitution.

Finally, remove an unnecessary escaping of the + sign.

commit 452e225 has missed fixing esc_url.

[...]

Quoted 10 lines
Quoted 4 lines

Second, I would probably write commit message differently, to emphasize that it is just finishing work of commit 452e225 (gitweb: fix esc_param, 2009-10-13) by fixing esc_url like it fixed esc_params. But it is not something very important.

I tentatively rewrote the message like so:

Earlier, 452e225 (gitweb: fix esc_param, 2009-10-13) fixed CGI escaping rules used in esc_url. A very similar logic exists in esc_param and needs to be fixed the same way.

Thanks.

Quoted 2 lines

It makes one wonder why they have to be separate functions, doesn't it, though?

They need to be separate because you have to escape params-related special characters ('?', ';', '=') when quoting params, but you shouldn't when escaping (external) URL as a whole.

Signature · 2 lines
Jakub Narebski
Poland
#5 lore raw

PATCH v2 2/11 gitweb: Prepare for splitting gitweb

In reply to Pavan Kumar Sunkara

Prepare gitweb for having been split into modules that are to be installed alongside gitweb in 'lib/' subdirectory, by adding

use lib __DIR__.'/lib';

to gitweb.perl (to main gitweb script), and preparing for putting modules (relative path) in $(GITWEB_MODULES) in gitweb/Makefile.

---
 gitweb/Makefile    |    3 +++
 gitweb/gitweb.perl |    9 +++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
gitweb/Makefile +3 -0
index d2584fe..c7610b3 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)#'
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#'
 PERL_PATH_SQ  = $(subst ','\'',$(PERL_PATH))#'
 DESTDIR_SQ    = $(subst ','\'',$(DESTDIR))#'
@@ -150,6 +151,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)'
+	$(foreach dir,$(sort $(dir $(GITWEB_MODULES))),test -d '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir)' || $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir)';)
+	$(foreach mod,$(GITWEB_MODULES),$(INSTALL) -m 644 $(mod) '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir $(mod))';)
 
 ### Cleaning rules
 
gitweb/gitweb.perl +9 -0
index 518328f..bda7da3 100755
@@ -9,6 +9,14 @@
 
 use strict;
 use warnings;
+
+use File::Spec;
+# __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 CGI qw(:standard :escapeHTML -nosticky);
 use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser set_message);
@@ -16,6 +24,7 @@ use Encode;
 use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
+
 binmode STDOUT, ':utf8';
 
 our $t0;
Signature · 1 line
1.7.1.455.g8f441
#6 lore raw

Re: [PATCHv2 GSOC 02/11] gitweb: Prepare for splitting gitweb

Quoted 11 lines · Pavan Kumar Sunkara

Prepare gitweb for having been split into modules that are to be installed alongside gitweb in 'lib/' subdirectory, by adding

use lib __DIR__.'/lib';

to gitweb.perl (to main gitweb script), and preparing for putting modules (relative path) in $(GITWEB_MODULES) in gitweb/Makefile.

---

First, it would be better if the comment from the cover letter about this patch (quoted below) was [also] put as the comment for this patch (i.e. in this area).

Quoted 4 lines

The second patch is produced by my commit ammend to Jakub Narębski's initial commit to prepare splitting of gitweb in the message-id:
http://mid.gmane.org/[email protected]

Quoted 8 lines

There is a small ammendment to that patch.
$(INSTALL) -m 644 $(mod) '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(mod)' is changed to
$(INSTALL) -m 644 $(mod) '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir $(mod))';) because it is better if we gave 'dir $(mod)' as the target for install command rather than '$(mod)' because it may cause problems in the future when gitweblibdir is used and the modules are installed elsewhere rather than in /use/share/gitweb.

Second, I don't quite understand the reason for your amendment. The difference is between two argument

install [OPTION]... SOURCE DEST

in my original version of this patch, and two argument

install [OPTION]... SOURCE DIRECTORY

after your change. In both cases we install _single_ file at once. What problems first version may cause if $(gitweblibdir) is used and it points elsewhere than $(gitwebdir)/lib?

Quoted 17 lines
 gitweb/Makefile    |    3 +++
 gitweb/gitweb.perl |    9 +++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
gitweb/Makefile +1 -0
index d2584fe..c7610b3 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)#'
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#'
 PERL_PATH_SQ  = $(subst ','\'',$(PERL_PATH))#'
 DESTDIR_SQ    = $(subst ','\'',$(DESTDIR))#'

gitweb/Makefile install: all · line 155

Quoted 5 lines
gitweb/Makefile +2 -0
@@ -150,6 +151,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)'
+	$(foreach dir,$(sort $(dir $(GITWEB_MODULES))),test -d '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir)' || $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir)';)
+	$(foreach mod,$(GITWEB_MODULES),$(INSTALL) -m 644 $(mod) '$(DESTDIR_SQ)$(gitwebdir_SQ)/$(dir $(mod))';)

Third, if you were folloring git mailing list (or at least patches for gitweb on it), you would notice new version of my "gitweb: Prepare for splitting gitweb" patch:

"[PATCHv3/RFC] gitweb: Prepare for splitting gitweb"
Message-ID: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/150463/focus=150544

which uses shell for loop, instead of make's $(foreach ...) function to avoid _possible_ problems with generating a command line that exceeded the maximum argument list length, as explained in comment section of

http://thread.gmane.org/gmane.comp.version-control.git/150463/focus=150463

Note that this version uses SOURCE DIRECTORY version rather than SOURCE DEST, like in your patch... probably unnecessary.

Quoted 23 lines
gitweb/Makefile +0 -0
 ### Cleaning rules
 
gitweb/gitweb.perl +8 -0
index 518328f..bda7da3 100755
@@ -9,6 +9,14 @@
 
 use strict;
 use warnings;
+
+use File::Spec;
+# __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 CGI qw(:standard :escapeHTML -nosticky);
 use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser set_message);

gitweb/gitweb.perl use Encode; · line 30

Quoted 7 lines
gitweb/gitweb.perl +1 -0
@@ -16,6 +24,7 @@ use Encode;
 use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
+
 binmode STDOUT, ':utf8';
 
 our $t0;

In "[PATCHv3/RFC] gitweb: Prepare for splitting gitweb" this spurious change was removed from patch.

Anyway, eventual replacing of this patch by other version should be fairly easy, so it shouldn't hold this series.

Signature · 2 lines
Jakub Narebski
Poland
#7 lore raw

PATCH v2 3/11 gitweb: Create Gitweb::Git module

In reply to Pavan Kumar Sunkara

Create a Gitweb::Git module in 'gitweb/lib/Gitweb/Git.pm' to deal with running git commands (and also processing output of git commands with external programs) from gitweb.

This module is intended as standalone module, which does not require (include) other gitweb' modules to avoid circular dependencies. That is why it includes $GIT variable, even though this variable is configured during building gitweb. On the other hand $GIT is more about git configuration, than gitweb configuration.

Subroutines moved:
evaluate_git_version
git_cmd
quote_command

Update gitweb/Makefile to install Gitweb::Git module alongside gitweb

---
 gitweb/Makefile          |    3 ++
 gitweb/gitweb.perl       |   35 ++++----------------------------
 gitweb/lib/Gitweb/Git.pm |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 30 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Git.pm
gitweb/Makefile +3 -0
index c7610b3..5035c2e 100644
@@ -111,6 +111,9 @@ endif
 
 GITWEB_FILES += static/git-logo.png static/git-favicon.png
 
+# Modules: Gitweb::*
+GITWEB_MODULES += lib/Gitweb/Git.pm
+
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
 	-e 's|++GIT_BINDIR++|$(bindir)|g' \
gitweb/gitweb.perl +5 -30
index bda7da3..778ac13 100755
@@ -27,11 +27,12 @@ use File::Basename qw(basename);
 
 binmode STDOUT, ':utf8';
 
+use Gitweb::Git;
+
 our $t0;
 if (eval { require Time::HiRes; 1; }) {
 	$t0 = [Time::HiRes::gettimeofday()];
 }
-our $number_of_git_cmds = 0;
 
 BEGIN {
 	CGI->compile() if $ENV{'MOD_PERL'};
@@ -75,9 +76,8 @@ sub evaluate_uri {
 	our $home_link = $my_uri || "/";
 }
 
-# core git executable to use
-# this can just be "git" if your webserver has a sensible PATH
-our $GIT = "++GIT_BINDIR++/git";
+# $GIT is from Gitweb::Git
+$GIT = "++GIT_BINDIR++/git";
 
 # absolute fs-path which will be prepended to the project path
 #our $projectroot = "/pub/scm";
@@ -482,7 +482,6 @@ sub gitweb_get_feature {
 		$feature{$name}{'override'},
 		@{$feature{$name}{'default'}});
 	# project specific override is possible only if we have project
-	our $git_dir; # global variable, declared later
 	if (!$override || !defined $git_dir) {
 		return @defaults;
 	}
@@ -616,13 +615,6 @@ sub get_loadavg {
 	return 0;
 }
 
-# version of the core git binary
-our $git_version;
-sub evaluate_git_version {
-	our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
-	$number_of_git_cmds++;
-}
-
 sub check_loadavg {
 	if (defined $maxload && get_loadavg() > $maxload) {
 		die_error(503, "The load average on the server is too high");
@@ -972,10 +964,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;
+	$git_dir = "$projectroot/$project" if $project;
 }
 
 our (@snapshot_fmts, $git_avatar);
@@ -2230,21 +2220,6 @@ sub get_feed_info {
 ## ----------------------------------------------------------------------
 ## git utility subroutines, invoking git commands
 
-# returns path to the core git executable and the --git-dir parameter as list
-sub git_cmd {
-	$number_of_git_cmds++;
-	return $GIT, '--git-dir='.$git_dir;
-}
-
-# quote the given arguments for passing them to the shell
-# quote_command("command", "arg 1", "arg with ' and ! characters")
-# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
-# Try to avoid using this function wherever possible.
-sub quote_command {
-	return join(' ',
-		map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
-}
-
 # get HEAD ref of given project as hash
 sub git_get_head_hash {
 	return git_get_full_hash(shift, 'HEAD');
gitweb/lib/Gitweb/Git.pm new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#8 lore raw

Re: [PATCHv2 GSOC 03/11] gitweb: Create Gitweb::Git module

Quoted 15 lines · Pavan Kumar Sunkara

Create a Gitweb::Git module in 'gitweb/lib/Gitweb/Git.pm' to deal with running git commands (and also processing output of git commands with external programs) from gitweb.

This module is intended as standalone module, which does not require (include) other gitweb' modules to avoid circular dependencies. That is why it includes $GIT variable, even though this variable is configured during building gitweb. On the other hand $GIT is more about git configuration, than gitweb configuration.

Subroutines moved:
evaluate_git_version
git_cmd
quote_command

Quoted 4 lines

Update gitweb/Makefile to install Gitweb::Git module alongside gitweb

---

This change (this refactoring) is fairly uncontroversial...

Quoted 2 lines
gitweb/gitweb.perl +0 -0

[...]

Quoted 5 lines
gitweb/gitweb.perl +2 -3
-# core git executable to use
-# this can just be "git" if your webserver has a sensible PATH
-our $GIT = "++GIT_BINDIR++/git";
+# $GIT is from Gitweb::Git
+$GIT = "++GIT_BINDIR++/git";

[...]

gitweb/gitweb.perl

Quoted 3 lines
gitweb/gitweb.perl +3 -0
+# core git executable to use
+# this can just be "git" if your webserver has a sensible PATH
+our $GIT;

...but for addressing the discussion about whether to put (or rather leave) description of $GIT variable in main gitweb/gitweb.perl script, to have description of all build-time configuration variables in one place. You should at least say something about this issue either in commit message, or in the comments for this patch, in my opinion.

Signature · 2 lines
Jakub Narebski
Poland
#9 lore raw

PATCH v2 4/11 gitweb: Create Gitweb::Config module

In reply to Pavan Kumar Sunkara

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

This module depends only on $git_dir from Gitweb::Git and includes the configuration related variables and subroutines (Including those required for configuration of gitweb features)

Subroutines moved:
evaluate_gitweb_config
configure_gitweb_features
filter_snapshot_fmts
gitweb_get_feature
gitweb_check_feature

Update gitweb/Makefile to install Gitweb::Config module alongside gitweb

---
 gitweb/Makefile             |    1 +
 gitweb/gitweb.perl          |  495 ++----------------------------------------
 gitweb/lib/Gitweb/Config.pm |  498 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 522 insertions(+), 472 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Config.pm
gitweb/Makefile +1 -0
index 5035c2e..492b0fa 100644
@@ -113,6 +113,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png
 
 # Modules: Gitweb::*
 GITWEB_MODULES += lib/Gitweb/Git.pm
+GITWEB_MODULES += lib/Gitweb/Config.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +23 -472

538 lines not on this page · raw message

gitweb/lib/Gitweb/Config.pm new file +498 -0

498 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#10 lore raw

Re: [PATCHv2 GSOC 04/11] gitweb: Create Gitweb::Config module

Quoted 8 lines · Pavan Kumar Sunkara

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

This module depends only on $git_dir from Gitweb::Git and includes the configuration related variables and subroutines (Including those required for configuration of gitweb features).

Here it might be worth noting that subroutines related to per-repository config (feature_* subroutines) are not in this module, I guess because of (inter)dependencies.

Quoted 17 lines

Subroutines moved:
evaluate_gitweb_config
configure_gitweb_features
filter_snapshot_fmts
gitweb_get_feature
gitweb_check_feature

Update gitweb/Makefile to install Gitweb::Config module alongside gitweb

---
 gitweb/Makefile             |    1 +
 gitweb/gitweb.perl          |  495 ++----------------------------------------
 gitweb/lib/Gitweb/Config.pm |  498 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 522 insertions(+), 472 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Config.pm

[...]

gitweb/gitweb.perl BEGIN { · line 45

Quoted 5 lines
gitweb/gitweb.perl +4 -1
-our $version = "++GIT_VERSION++";
+# Only configuration variables with build-time overridable
+# defaults are listed below. The complete set of variables
+# with their descriptions is listed in Gitweb::Config.
+$version = "++GIT_VERSION++";

Ah, I see that here you address (somewhat) the issue of moving descriptions of build-time configuration variables out of gitweb.perl into individual module(s).

[...]

Nice straight refactoring. It's a pity that git-diff cannot show this
as code movement + some changes, like it would in the case of wholesame file rename.

Signature · 2 lines
Jakub Narebski
Poland
#11 lore raw

PATCH v2 5/11 gitweb: Create Gitweb::Request module

In reply to Pavan Kumar Sunkara

Create a Gitweb::Request module in 'gitweb/lib/Gitweb/Request.pm' to store and handle all the cgi params and related variables regarding the gitweb.perl script.

This module is intended as standalone module, which does not require (include) other gitweb' modules to avoid circular dependencies.

Subroutines moved:
evaluate_uri
evaluate_query_params

Update gitweb/Makefile to install Gitweb::Request module alongside gitweb

---
 gitweb/Makefile              |    1 +
 gitweb/gitweb.perl           |  130 +++++-------------------------------------
 gitweb/lib/Gitweb/Request.pm |  119 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 134 insertions(+), 116 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Request.pm
gitweb/Makefile +1 -0
index 492b0fa..cd36dc6 100644
@@ -114,6 +114,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png
 # Modules: Gitweb::*
 GITWEB_MODULES += lib/Gitweb/Git.pm
 GITWEB_MODULES += lib/Gitweb/Config.pm
+GITWEB_MODULES += lib/Gitweb/Request.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +14 -116

234 lines not on this page · raw message

gitweb/lib/Gitweb/Request.pm new file +119 -0

119 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#12 lore raw

Re: [PATCHv2 GSOC 05/11] gitweb: Create Gitweb::Request module

Quoted 10 lines · Pavan Kumar Sunkara

Create a Gitweb::Request module in 'gitweb/lib/Gitweb/Request.pm' to store and handle all the cgi params and related variables regarding the gitweb.perl script.

This module is intended as standalone module, which does not require (include) other gitweb' modules to avoid circular dependencies.

Subroutines moved:
evaluate_uri
evaluate_query_params

Here you would really need to explain why Gitweb::Request does not include evaluate_path_info, the companion to evaluate_query_params. It is strange to me that query_params is in it, but path_info is not.

Would it be possible, perhaps, to modify evaluate_path_info so it can be moved to Gitweb::Request without adding additional dependencies to it?

Quoted 3 lines

Update gitweb/Makefile to install Gitweb::Request module alongside gitweb

[...]

Quoted 2 lines
gitweb/lib/Gitweb/Request.pm new file +0 -0

[...]

gitweb/lib/Gitweb/Request.pm line 16

Quoted 4 lines
gitweb/lib/Gitweb/Request.pm new file +4 -0
+our @EXPORT = qw($cgi $my_url $my_uri $base_url $path_info $home_link $action $project $file_name
+                 $file_parent $hash $hash_parent $hash_base $hash_parent_base @extra_options $page
+                 $searchtype $search_use_regexp $searchtext $search_regexp %input_params %allowed_options
+                 @cgi_param_mapping %cgi_param_mapping $t0 evaluate_query_params evaluate_uri);

You are working off older base, which did not include reset_timer subroutine, added in 869d588 (gitweb: Move evaluate_gitweb_config out of run_request, 2010-07-05).

Signature · 2 lines
Jakub Narebski
Poland
#13 lore raw

PATCH v2 6/11 gitweb: Create Gitweb::Escape module

In reply to Pavan Kumar Sunkara

Create a Gitweb::Escape module in 'gitweb/lib/Gitweb/Escape.pm' to store all the quoting/unquoting and escaping subroutines regarding the gitweb.perl script.

This module imports $fallback_encoding variable from Gitweb::Config module to use it in sub 'to_utf8'

Subroutines moved:

	to_utf8
	esc_param
	esc_url
	esc_html
	esc_path
	quot_cec
	quot_upr
	untabify

Update gitweb/Makefile to install Gitweb::Escape module alongside gitweb

---
 gitweb/Makefile             |    1 +
 gitweb/gitweb.perl          |  120 +-------------------------------------
 gitweb/lib/Gitweb/Escape.pm |  138 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+), 119 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Escape.pm
gitweb/Makefile +1 -0
index cd36dc6..c145ebd 100644
@@ -115,6 +115,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png
 GITWEB_MODULES += lib/Gitweb/Git.pm
 GITWEB_MODULES += lib/Gitweb/Config.pm
 GITWEB_MODULES += lib/Gitweb/Request.pm
+GITWEB_MODULES += lib/Gitweb/Escape.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +1 -119

144 lines not on this page · raw message

gitweb/lib/Gitweb/Escape.pm new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#14 lore raw

Re: [PATCHv2 GSOC 06/11] gitweb: Create Gitweb::Escape module

Quoted 17 lines · Pavan Kumar Sunkara

Create a Gitweb::Escape module in 'gitweb/lib/Gitweb/Escape.pm' to store all the quoting/unquoting and escaping subroutines regarding the gitweb.perl script.

This module imports $fallback_encoding variable from Gitweb::Config module to use it in sub 'to_utf8'

Subroutines moved:

	to_utf8
	esc_param
	esc_url
	esc_html
	esc_path
	quot_cec
	quot_upr
	untabify
Quoted 1 line

Update gitweb/Makefile to install Gitweb::Escape module alongside gitweb

Nice and straightforward refactoring.

For what it is worth, ACK from me.

[...]

Quoted 8 lines
gitweb/lib/Gitweb/Escape.pm new file +8 -0
+# quote unsafe chars, but keep the slash, even when it's not
+# correct, but quoted slashes look too horrible in bookmarks
+sub esc_param {
+	my $str = shift;
+	return undef unless defined $str;
+	$str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;
+	$str =~ s/ /\+/g;
+	return $str;

gitweb/lib/Gitweb/Escape.pm line 51

Quoted 10 lines
gitweb/lib/Gitweb/Escape.pm new file +10 -0
+}
+
+# quote unsafe chars in whole URL, so some charactrs cannot be quoted
+sub esc_url {
+	my $str = shift;
+	return undef unless defined $str;
+	$str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;
+	$str =~ s/ /\+/g;
+	return $str;
+}

I see that here (or rather in corresponding preimage) you have dependency on first patch in series, i.e. "gitweb: fix esc_url".

If you had send first patch as a separate email, not as part of series, you would have need to mention in cover letter that the series (without first patch) is based on / requires "gitweb: fix esc_url".

Signature · 2 lines
Jakub Narebski
Poland
#15 lore raw

PATCH v2 7/11 gitweb: Create Gitweb::RepoConfig module

In reply to Pavan Kumar Sunkara

Create a Gitweb::RepoConfig module in 'gitweb/lib/Gitweb/RepoConfig.pm' to store and handle all the configuration and subroutines related to a single repository regarding the gitweb.perl script.

This module depend on several other modules like Git.pm, Config.pm, Request.pm and Escape.pm.

It also include subroutines regarding project_list and it's handling.

Subroutines moved:
check_head_link
check_export_ok
hash_set_multi
git_parse_project_config
config_to_bool
config_to_int
config_to_multi
feature_bool
feature_snapshot
feature_patches
feature_avatar
git_get_project_config
git_get_project_description
git_get_project_ctags
git_populate_project_tagcloud
git_show_project_tagcloud
git_get_project_url_list
git_get_projects_list
git_get_project_list_from_file
git_get_project_owner
get_file_owner
project_in_list

Update gitweb/Makefile to install Gitweb::RepoConfig module alongside gitweb

---
 gitweb/Makefile                 |    1 +
 gitweb/gitweb.perl              |  441 +------------------------------------
 gitweb/lib/Gitweb/RepoConfig.pm |  466 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 468 insertions(+), 440 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/RepoConfig.pm
gitweb/Makefile +1 -0
index c145ebd..726f393 100644
@@ -116,6 +116,7 @@ GITWEB_MODULES += lib/Gitweb/Git.pm
 GITWEB_MODULES += lib/Gitweb/Config.pm
 GITWEB_MODULES += lib/Gitweb/Request.pm
 GITWEB_MODULES += lib/Gitweb/Escape.pm
+GITWEB_MODULES += lib/Gitweb/RepoConfig.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +1 -440

483 lines not on this page · raw message

gitweb/lib/Gitweb/RepoConfig.pm new file +466 -0

466 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#16 lore raw

Re: [PATCHv2 GSOC 07/11] gitweb: Create Gitweb::RepoConfig module

Quoted 3 lines · Pavan Kumar Sunkara

Create a Gitweb::RepoConfig module in 'gitweb/lib/Gitweb/RepoConfig.pm' to store and handle all the configuration and subroutines related to a single repository regarding the gitweb.perl script.

The above sentence is hard to parse (hard to understand). Please try to be more clear. I guess that you wanted to say that this module is about checking repositories and repository parameters, and about per-repository configuration.

Quoted 3 lines

This module depend on several other modules like Git.pm, Config.pm, Request.pm and Escape.pm.

Nitpick: the names of those modules are Gitweb::Git, Gitweb::Config, Gitweb::Request and Gitweb::Escape.

Quoted 19 lines

It also include subroutines regarding project_list and it's handling.

Subroutines moved:
check_head_link
check_export_ok
hash_set_multi
git_parse_project_config
config_to_bool
config_to_int
config_to_multi
feature_bool
feature_snapshot
feature_patches
feature_avatar
git_get_project_config
git_get_project_description
git_get_project_ctags

Quoted 8 lines

git_populate_project_tagcloud
git_show_project_tagcloud
git_get_project_url_list
git_get_projects_list
git_get_project_list_from_file
git_get_project_owner
get_file_owner
project_in_list

In the future we might want to separate handling of per-repository overriding of features in a separae module.

Quoted 5 lines

Update gitweb/Makefile to install Gitweb::RepoConfig module alongside gitweb

Other than those minor issues it seems all right.

P.S. I'm sorry, but I wouldn't be able to examine the rest of series before this Sunday at earliest.

Signature · 2 lines
Jakub Narebski
Poland
#17 lore raw

PATCH v2 8/11 gitweb: Create Gitweb::View module

In reply to Pavan Kumar Sunkara

Create Gitweb::View module in 'gitweb/lib/Gitweb/View.pm' to store the subroutines related to the HTML output for gitweb.

This module depends on Git.pm, Config.pm, Request.pm, Escape.pm and RepoConfig.pm. Action specific HTML div subroutines are not included in this module due to unmet dependencies of Gitweb::Parse and Gitweb::Format.

Subroutines moved:
*href
get_feed_info
*chop_str
chop_and_escape_str
*age_class
age_string
*S_ISGITLINK
mode_str
file_type
file_type_long
*get_page_title
git_header_html
git_footer_html
die_error
*git_print_page_nav
format_paging_nav
git_print_header_div
git_print_page_path
*print_local_time
format_local_time
*insert_file
*git_get_link_target
normalize_link_target
git_print_tree_entry
*print_sort_th
format_sort_th

Update 'gitweb/Makefile' to install Gitweb::View alongside gitweb.

---
 gitweb/Makefile           |    1 +
 gitweb/gitweb.perl        |  996 +-------------------------------------------
 gitweb/lib/Gitweb/View.pm | 1022 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1024 insertions(+), 995 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/View.pm
gitweb/Makefile +1 -0
index 726f393..ce9f372 100644
@@ -117,6 +117,7 @@ GITWEB_MODULES += lib/Gitweb/Config.pm
 GITWEB_MODULES += lib/Gitweb/Request.pm
 GITWEB_MODULES += lib/Gitweb/Escape.pm
 GITWEB_MODULES += lib/Gitweb/RepoConfig.pm
+GITWEB_MODULES += lib/Gitweb/View.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +1 -995

1,053 lines not on this page · raw message

gitweb/lib/Gitweb/View.pm new file +1022 -0

1,022 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#18 lore raw

Re: [PATCHv2 GSOC 08/11] gitweb: Create Gitweb::View module

Quoted 3 lines · Pavan Kumar Sunkara

Create Gitweb::View module in 'gitweb/lib/Gitweb/View.pm' to store the subroutines related to the HTML output for gitweb.

If it contains subroutines related only to HTML output, why isn't it called Gitweb::HTML then? If it contains some subroutines which are not strictly about HTML, please state it in the commit message.

Quoted 5 lines

This module depends on Git.pm, Config.pm, Request.pm, Escape.pm and RepoConfig.pm. Action specific HTML div subroutines are not included in this module due to unmet dependencies of Gitweb::Parse and Gitweb::Format.

Whether you use Gitweb::Git or Git.pm, you should be consistent in the naming you use: either Git.pm, or Gitweb::Parse.

Do I understand correctly trhat Gitweb::Parse and Gitweb::Format are to be added in subsequent patches? Please state this fact in the commit message.

Quoted 20 lines

Subroutines moved:
*href
get_feed_info
*chop_str
chop_and_escape_str
*age_class
age_string
*S_ISGITLINK
mode_str
file_type
file_type_long
*get_page_title
git_header_html
git_footer_html
die_error
*git_print_page_nav
format_paging_nav
git_print_header_div
git_print_page_path

Quoted 8 lines

*print_local_time
format_local_time
*insert_file
*git_get_link_target
normalize_link_target
git_print_tree_entry
*print_sort_th
format_sort_th

Nitpick: my first thought was "why some of those subroutines are marked with a star?". If you want to divide this list of subroutines into groups by function, you should leave a space between '*' and name of subroutine (i.e. '* href'), and perhaps also leave empty lines between groups, though this might make commit this list overly long.

I guess that this separation of subroutines into Gitweb::View module was a matter of some compromise: between having too large modules (containing only barely related subroutines) and having too many modules.

Quoted 4 lines

Update 'gitweb/Makefile' to install Gitweb::View alongside gitweb.

I have not checked the diff itself...

Signature · 2 lines
Jakub Narebski
Poland
#19 lore raw

PATCH v2 9/11 gitweb: Create Gitweb::Util module

In reply to Pavan Kumar Sunkara

Create Gitweb::Util module in 'gitweb/lib/Gitweb/Util.pm' to store the git utility subroutines related to gitweb.

This module include subroutines in various categories such as git utility subs invoking git commands, git utility subs accessing git repository, mimetype related subs and HTML output utility subs.

Subroutines moved:
git_get_head_hash
git_get_full_hash
git_get_short_hash
git_get_hash
git_get_type
git_get_hash_by_path
git_get_path_by_hash
git_get_last_activity
git_get_references
git_get_rev_name_tags
git_get_heads_list
git_get_tags_list
mimetype_guess_file
mimetype_guess
blob_mimetype
blob_contenttype
guess_file_syntax
run_highlighter
fill_from_file_info
is_deleted
is_patch_split

Update 'gitweb/Makefile' to install Gitweb::Util alongside gitweb.

---
 gitweb/Makefile           |    1 +
 gitweb/gitweb.perl        |  420 +------------------------------------------
 gitweb/lib/Gitweb/Util.pm |  447 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 449 insertions(+), 419 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Util.pm
gitweb/Makefile +1 -0
index ce9f372..1c37609 100644
@@ -118,6 +118,7 @@ GITWEB_MODULES += lib/Gitweb/Request.pm
 GITWEB_MODULES += lib/Gitweb/Escape.pm
 GITWEB_MODULES += lib/Gitweb/RepoConfig.pm
 GITWEB_MODULES += lib/Gitweb/View.pm
+GITWEB_MODULES += lib/Gitweb/Util.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +1 -419

444 lines not on this page · raw message

gitweb/lib/Gitweb/Util.pm new file +447 -0

447 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#20 lore raw

Re: [PATCHv2 GSOC 09/11] gitweb: Create Gitweb::Util module

Quoted 7 lines · Pavan Kumar Sunkara

Create Gitweb::Util module in 'gitweb/lib/Gitweb/Util.pm' to store the git utility subroutines related to gitweb.

This module include subroutines in various categories such as git utility subs invoking git commands, git utility subs accessing git repository, mimetype related subs and HTML output utility subs.

O.K. so the theme is small helper subroutines, isn't it?

Quoted 15 lines

Subroutines moved:
git_get_head_hash
git_get_full_hash
git_get_short_hash
git_get_hash
git_get_type
git_get_hash_by_path
git_get_path_by_hash
git_get_last_activity
git_get_references
git_get_rev_name_tags
git_get_heads_list
git_get_tags_list
mimetype_guess_file

Quoted 8 lines

mimetype_guess
blob_mimetype
blob_contenttype
guess_file_syntax
run_highlighter
fill_from_file_info
is_deleted
is_patch_split

Just a question: shouldn't git_get_last_activity subroutine be in Gitweb::RepoConfig module? Or is Gitweb::RepoConfig only about "static" properties of a repository?

Quoted 5 lines

Update 'gitweb/Makefile' to install Gitweb::Util alongside gitweb.

---

I have not checked the patch, but is should be mainly straightforward code movement plus some boilerplate.

Signature · 2 lines
Jakub Narebski
Poland
#21 lore raw

PATCH v2 10/11 gitweb: Create Gitweb::Format module

In reply to Pavan Kumar Sunkara

Create Gitweb::Format module in 'gitweb/lib/Gitweb/Format.pm' to store the subroutines related to formatting of HTML fragments required for gitweb.

This module depends on Config.pm, View.pm, Escape.pm, Util.pm and Request.pm. It mainly contain functions returning short HTML fragments or transforming HTML fragments. Also include subroutines regarding avatar formatting.

Subroutines moved:
format_log_line_html
format_ref_marker
format_subject_html
picon_url
gravatar_url
git_get_avatar
format_search_author
format_author_html
format_git_diff_header_line
format_extended_diff_header_line
format_diff_from_to_header
format_diff_cc_simplified
format_diff_line
format_snapshot_links

Update 'gitweb/Makefile' to install Gitweb::Format alongside gitweb.

---
 gitweb/Makefile             |    1 +
 gitweb/gitweb.perl          |  512 +----------------------------------------
 gitweb/lib/Gitweb/Format.pm |  537 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 539 insertions(+), 511 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Format.pm
gitweb/Makefile +1 -0
index 1c37609..f1803f5 100644
@@ -119,6 +119,7 @@ GITWEB_MODULES += lib/Gitweb/Escape.pm
 GITWEB_MODULES += lib/Gitweb/RepoConfig.pm
 GITWEB_MODULES += lib/Gitweb/View.pm
 GITWEB_MODULES += lib/Gitweb/Util.pm
+GITWEB_MODULES += lib/Gitweb/Format.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +1 -511

524 lines not on this page · raw message

gitweb/lib/Gitweb/Format.pm new file +537 -0

537 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#22 lore raw

Re: [PATCHv2 GSOC 10/11] gitweb: Create Gitweb::Format module

Quoted 3 lines · Pavan Kumar Sunkara

Create Gitweb::Format module in 'gitweb/lib/Gitweb/Format.pm' to store the subroutines related to formatting of HTML fragments required for gitweb.

What is the criterion of choosing whether to put given subroutine in Gitweb::View / Gitweb::HTML and in Gitweb::Format (this module)?

Quoted 3 lines

This module depends on Config.pm, View.pm, Escape.pm, Util.pm and Request.pm.

O.K., although we should decide consistently through the series if we want to use the Config.pm form for describing dependencies in the commit message, or would it be better to use Gitweb::Config, i.e. the module name.

Quoted 3 lines

It mainly contain functions returning
short HTML fragments or transforming HTML fragments. Also include subroutines regarding avatar formatting.

I think you should say aomething about _why_ did you pur avatar formatting in this module; I guess that is because git_get_avatar returns also short HTML fragment.

Quoted 17 lines

Subroutines moved:
format_log_line_html
format_ref_marker
format_subject_html
picon_url
gravatar_url
git_get_avatar
format_search_author
format_author_html
format_git_diff_header_line
format_extended_diff_header_line
format_diff_from_to_header
format_diff_cc_simplified
format_diff_line
format_snapshot_links

Quoted 4 lines

Update 'gitweb/Makefile' to install Gitweb::Format alongside gitweb.

---

I have not checked patch itself.

Signature · 2 lines
Jakub Narebski
Poland
#23 lore raw

PATCH v2 11/11 gitweb: Create Gitweb::Parse module

In reply to Pavan Kumar Sunkara

Create Gitweb::Parse module in 'gitweb/lib/Gitweb/Parse.pm' to store the subroutines which related to parsing functions required for gitweb.

This module depends on Git.pm, Escape.pm, View.pm and Util.pm.

Subroutines moved:
unquote
parse_date
parse_tag
parse_commit_text
parse_commit
parse_commits
parse_difftree_raw_line
parsed_difftree_line
parse_ls_tree_line
parse_from_to_diffinfo

Update 'gitweb/Makefile' to install Gitweb::Parse alongside gitweb.

---
 gitweb/Makefile            |    1 +
 gitweb/gitweb.perl         |  392 +-----------------------------------------
 gitweb/lib/Gitweb/Parse.pm |  414 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 416 insertions(+), 391 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Parse.pm
gitweb/Makefile +1 -0
index f1803f5..1c1bdca 100644
@@ -120,6 +120,7 @@ GITWEB_MODULES += lib/Gitweb/RepoConfig.pm
 GITWEB_MODULES += lib/Gitweb/View.pm
 GITWEB_MODULES += lib/Gitweb/Util.pm
 GITWEB_MODULES += lib/Gitweb/Format.pm
+GITWEB_MODULES += lib/Gitweb/Parse.pm
 
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
gitweb/gitweb.perl +1 -391

404 lines not on this page · raw message

gitweb/lib/Gitweb/Parse.pm new file +414 -0

414 lines not on this page · raw message

Signature · 1 line
1.7.1.455.g8f441
#24 lore raw

Re: [PATCHv2 GSOC 11/11] gitweb: Create Gitweb::Parse module

Quoted 3 lines · Pavan Kumar Sunkara

Create Gitweb::Parse module in 'gitweb/lib/Gitweb/Parse.pm' to store the subroutines which related to parsing functions required for gitweb.

O.K., that is nicely defined module, although you would probably want to add _what_ those functions parse: most of them (or all of them) parse or help parsing output of git commands.

By the way, in the future we might want to move those subroutines to Git::Parse (or individual Git::Commit, Git::Tag, etc. modules). By "in the future" I mean here when we move to using Git.pm in gitweb... which currently would require some functionality that is just not present in Git.pm.

Quoted 2 lines

This module depends on Git.pm, Escape.pm, View.pm and Util.pm.

Usual notice: Git.pm or Gitweb::Git, etc.?

Quoted 12 lines

Subroutines moved:
unquote
parse_date
parse_tag
parse_commit_text
parse_commit
parse_commits
parse_difftree_raw_line
parsed_difftree_line
parse_ls_tree_line
parse_from_to_diffinfo

One of those is not like the other. parsed_difftree_line is really an utility (helper) function, but I guess it is here and not in Gitweb::Util because of its dependency on parse_difftree_raw_line, and therefore it would add circular dependency of Gitweb::Parse to Gitweb::Util.

Quoted 10 lines

Update 'gitweb/Makefile' to install Gitweb::Parse alongside gitweb.

---
 gitweb/Makefile            |    1 +
 gitweb/gitweb.perl         |  392 +-----------------------------------------
 gitweb/lib/Gitweb/Parse.pm |  414 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 416 insertions(+), 391 deletions(-)
 create mode 100644 gitweb/lib/Gitweb/Parse.pm

[...]

gitweb/lib/Gitweb/Parse.pm line 3

Quoted 9 lines
gitweb/lib/Gitweb/Parse.pm new file +3 -0
new file mode 100644
index 0000000..6eeef2c
@@ -0,0 +1,414 @@
+#!/usr/bin/perl
+#
+# Gitweb::Parse -- gitweb's parse_* subs package

Wouldn't "subroutines related to parsing output of git commands, required by gitweb" be a better description here?

gitweb/lib/Gitweb/Parse.pm line 5

Quoted 2 lines
gitweb/lib/Gitweb/Parse.pm new file +2 -0
+#
+# This program is licensed under the GPLv2

Sidenote: do we want "GPLv2" or "GPLv2 or later", or even "GPLv2 or later, at discretion of Junio C Hamano"?

gitweb/lib/Gitweb/Parse.pm line 15

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+
+package Gitweb::Parse;
+
+use strict;
+use warnings;
+use Exporter qw(import);
+
+our @EXPORT = qw(parse_date parse_tag parse_commit_text parse_commit
+                 parse_commits parse_difftree_raw_line parsed_difftree_line
+                 parse_ls_tree_line parse_from_to_diffinfo unquote);

Sidenote: in the future commit we might want to not export 'unquote' by default (but still be able to export it / export it with ':all' tag). I don't think we use it outside subroutines defined in this module. But I guess it is better left for a later commit.

gitweb/lib/Gitweb/Parse.pm line 21

Quoted 6 lines
gitweb/lib/Gitweb/Parse.pm new file +6 -0
+
+use Gitweb::Git qw(git_cmd);
+use Gitweb::Request qw(@extra_options $hash $hash_parent);
+use Gitweb::Escape qw(to_utf8);
+use Gitweb::View qw(href chop_str age_string die_error);
+use Gitweb::Util qw(fill_from_file_info is_deleted);

While at it, lets review those subroutines.

All those comments are meant for a future commit, and are not in any way requirement for Pavan. Splitting should in my opinion be just simple code movement / code reorganization, without any changes.

Quoted 17 lines
gitweb/lib/Gitweb/Parse.pm new file +17 -0
+# git may return quoted and escaped filenames
+sub unquote {
+	my $str = shift;
+
+	sub unq {
+		my $seq = shift;
+		my %es = ( # character escape codes, aka escape sequences
+			't' => "\t",   # tab            (HT, TAB)
+			'n' => "\n",   # newline        (NL)
+			'r' => "\r",   # return         (CR)
+			'f' => "\f",   # form feed      (FF)
+			'b' => "\b",   # backspace      (BS)
+			'a' => "\a",   # alarm (bell)   (BEL)
+			'e' => "\e",   # escape         (ESC)
+			'v' => "\013", # vertical tab   (VT)
+		);
+

gitweb/lib/Gitweb/Parse.pm line 49

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+		if ($seq =~ m/^[0-7]{1,3}$/) {
+			# octal char sequence
+			return chr(oct($seq));
+		} elsif (exists $es{$seq}) {
+			# C escape sequence, aka character escape code
+			return $es{$seq};
+		}
+		# quoted ordinary character
+		return $seq;
+	}

Sidenote: I wonder if it wouldn't be better to move definition of 'unq' subroutine to outside of 'unquote', i.e. do not nest subroutines.

gitweb/lib/Gitweb/Parse.pm line 54

Quoted 5 lines
gitweb/lib/Gitweb/Parse.pm new file +5 -0
+
+	if ($str =~ m/^"(.*)"$/) {
+		# needs unquoting
+		$str = $1;
+		$str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;

Sidenote: hmmm... aren't digit escape sequences always three digits long, with exception of '\0' for NUL byte? I mean, wouldn't it be better to use

  +		$str =~ s/\\([^0-7]|0|[0-7]{3})/unq($1)/eg;

gitweb/lib/Gitweb/Parse.pm line 61

Quoted 7 lines
gitweb/lib/Gitweb/Parse.pm new file +7 -0
+	}
+	return $str;
+}
+
+## ----------------------------------------------------------------------
+## parse to hash functions
+

Sidenote: we would probably want to add description of this subroutine later (in subsequent commits). This subroutine takes e.g. authortime as returned by git (epoch + numerical timezone), parses its and _formats_ to rfc2822, mday-time, ISO 8601 and other formats... hmmm... perhaps we should separate parsing from formatting...

But all of this should be left for later commit.

Quoted 28 lines
gitweb/lib/Gitweb/Parse.pm new file +28 -0
+sub parse_date {
+	my $epoch = shift;
+	my $tz = shift || "-0000";
+
+	my %date;
+	my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
+	my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
+	my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
+	$date{'hour'} = $hour;
+	$date{'minute'} = $min;
+	$date{'mday'} = $mday;
+	$date{'day'} = $days[$wday];
+	$date{'month'} = $months[$mon];
+	$date{'rfc2822'}   = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
+	                     $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
+	$date{'mday-time'} = sprintf "%d %s %02d:%02d",
+	                     $mday, $months[$mon], $hour ,$min;
+	$date{'iso-8601'}  = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
+	                     1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
+
+	$tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
+	my $local = $epoch + ((int $1 + ($2/60)) * 3600);
+	($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
+	$date{'hour_local'} = $hour;
+	$date{'minute_local'} = $min;
+	$date{'tz_local'} = $tz;
+	$date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
+	                          1900+$year, $mon+1, $mday,

gitweb/lib/Gitweb/Parse.pm line 99

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+	                          $hour, $min, $sec, $tz);
+	return %date;
+}
+
+sub parse_tag {
+	my $tag_id = shift;
+	my %tag;
+	my @comment;
+
+	open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;

In the future, when we move to using Git.pm (the "use Git", not "use Gitweb::Git"), it could be

  +	$repo->get_object_with_type("tag", $tag_id) or return;

Or not. Or something like that.

Quoted 9 lines
gitweb/lib/Gitweb/Parse.pm new file +9 -0
+	$tag{'id'} = $tag_id;
+	while (my $line = <$fd>) {
+		chomp $line;
+		if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
+			$tag{'object'} = $1;
+		} elsif ($line =~ m/^type (.+)$/) {
+			$tag{'type'} = $1;
+		} elsif ($line =~ m/^tag (.+)$/) {
+			$tag{'name'} = $1;

gitweb/lib/Gitweb/Parse.pm line 118

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+		} elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
+			$tag{'author'} = $1;
+			$tag{'author_epoch'} = $2;
+			$tag{'author_tz'} = $3;
+			if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
+				$tag{'author_name'}  = $1;
+				$tag{'author_email'} = $2;
+			} else {
+				$tag{'author_name'} = $tag{'author'};
+			}

Sidenote: I wonder if parsing name + email out of author / comitter / / tagger info shouldn't be moved to a separate subroutine, or is it not worth it...

Again, better left for later commit.

gitweb/lib/Gitweb/Parse.pm line 121

Quoted 3 lines
gitweb/lib/Gitweb/Parse.pm new file +3 -0
+		} elsif ($line =~ m/--BEGIN/) {
+			push @comment, $line;
+			last;

Sidenote: WTF is that? The (ASCII armored) signature block can occur only in the tag message (tag "payload"), and coun't be in heder, could it?

But fix of this issue should be left for later commit.

gitweb/lib/Gitweb/Parse.pm line 126

Quoted 5 lines
gitweb/lib/Gitweb/Parse.pm new file +5 -0
+		} elsif ($line eq "") {
+			last;
+		}
+	}
+	push @comment, <$fd>;
  +	my @comment = <$fd>;

Again, this is better left for later commit.

gitweb/lib/Gitweb/Parse.pm line 130

Quoted 4 lines
gitweb/lib/Gitweb/Parse.pm new file +4 -0
+	$tag{'comment'} = \@comment;
+	close $fd or return;
+	if (!defined $tag{'name'}) {
+		return

+ return;

Fix (I guess), better left for later commit.

gitweb/lib/Gitweb/Parse.pm line 132

Quoted 2 lines
gitweb/lib/Gitweb/Parse.pm new file +2 -0
+	};
+	return %tag

+ return %tag;

Same.

gitweb/lib/Gitweb/Parse.pm line 133

Quoted 2 lines
gitweb/lib/Gitweb/Parse.pm new file +2 -0
+}
+

Sidenote: we should probably add description of this subroutine in a later commit.

gitweb/lib/Gitweb/Parse.pm line 136

Quoted 2 lines
gitweb/lib/Gitweb/Parse.pm new file +2 -0
+sub parse_commit_text {
+	my ($commit_text, $withparents) = @_;

Sidenote: I wonder if using "named parameters" here wouldn't make for a better API, i.e.

  +	my ($commit_text, %opts) = @_;
  +	my $withparents = $opts{'-with-parents'};
Quoted 4 lines
gitweb/lib/Gitweb/Parse.pm new file +4 -0
+	my @commit_lines = split '\n', $commit_text;
+	my %co;
+
+	pop @commit_lines; # Remove '\0'

gitweb/lib/Gitweb/Parse.pm line 150

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+
+	if (! @commit_lines) {
+		return;
+	}
+
+	my $header = shift @commit_lines;
+	if ($header !~ m/^[0-9a-fA-F]{40}/) {
+		return;
+	}
+	($co{'id'}, my @parents) = split ' ', $header;

Those five lines above very much depend that the output is generated by 'git rev-list --parents ...", i.e. that there is line with SHA-1 of commit, and then line with _effective_ parents of a commit.

gitweb/lib/Gitweb/Parse.pm line 151

Quoted 1 line
gitweb/lib/Gitweb/Parse.pm new file +1 -0
+	while (my $line = shift @commit_lines) {

Sidenote: parse_tag 'chomp's each line first.

gitweb/lib/Gitweb/Parse.pm line 156

Quoted 5 lines
gitweb/lib/Gitweb/Parse.pm new file +5 -0
+		last if $line eq "\n";
+		if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
+			$co{'tree'} = $1;
+		} elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
+			push @parents, $1;

Sidenote: we would probably want to distinguish between real / original parents (as recorded in the object) and effective parents (history simplification e.g. in 'history' view, and grafts).

gitweb/lib/Gitweb/Parse.pm line 166

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+		} elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
+			$co{'author'} = to_utf8($1);
+			$co{'author_epoch'} = $2;
+			$co{'author_tz'} = $3;
+			if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
+				$co{'author_name'}  = $1;
+				$co{'author_email'} = $2;
+			} else {
+				$co{'author_name'} = $co{'author'};
+			}

Sidenote: again, perhaps parsing of aithor info should be refactored into a separate subroutine, to avoid code duplication.

gitweb/lib/Gitweb/Parse.pm line 177

Quoted 11 lines
gitweb/lib/Gitweb/Parse.pm new file +11 -0
+		} elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
+			$co{'committer'} = to_utf8($1);
+			$co{'committer_epoch'} = $2;
+			$co{'committer_tz'} = $3;
+			if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
+				$co{'committer_name'}  = $1;
+				$co{'committer_email'} = $2;
+			} else {
+				$co{'committer_name'} = $co{'committer'};
+			}
+		}

Same.

gitweb/lib/Gitweb/Parse.pm line 184

Quoted 7 lines
gitweb/lib/Gitweb/Parse.pm new file +7 -0
+	}
+	if (!defined $co{'tree'}) {
+		return;
+	};
+	$co{'parents'} = \@parents;
+	$co{'parent'} = $parents[0];
+

This foreach skips initial (leading) empty lines.

Quoted 12 lines
gitweb/lib/Gitweb/Parse.pm new file +12 -0
+	foreach my $title (@commit_lines) {
+		$title =~ s/^    //;
+		if ($title ne "") {
+			$co{'title'} = chop_str($title, 80, 5);
+			# remove leading stuff of merges to make the interesting part visible
+			if (length($title) > 50) {
+				$title =~ s/^Automatic //;
+				$title =~ s/^merge (of|with) /Merge ... /i;
+				if (length($title) > 50) {
+					$title =~ s/(http|rsync):\/\///;
+				}
+				if (length($title) > 50) {

gitweb/lib/Gitweb/Parse.pm line 206

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+					$title =~ s/(master|www|rsync)\.//;
+				}
+				if (length($title) > 50) {
+					$title =~ s/kernel.org:?//;
+				}
+				if (length($title) > 50) {
+					$title =~ s/\/pub\/scm//;
+				}
+			}
+			$co{'title_short'} = chop_str($title, 50, 5);

Sidenote: this simplification for 'title_short' should probably be refactored into separate subroutine, and improved. But that's a matter for a later commit, if any.

gitweb/lib/Gitweb/Parse.pm line 216

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+			last;
+		}
+	}
+	if (! defined $co{'title'} || $co{'title'} eq "") {
+		$co{'title'} = $co{'title_short'} = '(no commit message)';
+	}
+	# remove added spaces
+	foreach my $line (@commit_lines) {
+		$line =~ s/^    //;
+	}

Using 'map' would be probably more idiomatic:

  +	# remove added spaces
  +	map { s/^[ ]{4}// } @commit_lines;
Quoted 4 lines
gitweb/lib/Gitweb/Parse.pm new file +4 -0
+	$co{'comment'} = \@commit_lines;
+
+	my $age = time - $co{'committer_epoch'};
+	$co{'age'} = $age;

gitweb/lib/Gitweb/Parse.pm line 229

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +9 -0
+	$co{'age_string'} = age_string($age);
 
+	my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
+	if ($age > 60*60*24*7*2) {
+		$co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
+		$co{'age_string_age'} = $co{'age_string'};
+	} else {
+		$co{'age_string_date'} = $co{'age_string'};
+		$co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
+	}

Sidenote: the above block should be probably refactored in a later commit.

Quoted 7 lines
gitweb/lib/Gitweb/Parse.pm new file +7 -0
+	return %co;
+}
+
+sub parse_commit {
+	my ($commit_id) = @_;
+	my %co;
+

gitweb/lib/Gitweb/Parse.pm line 246

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+	local $/ = "\0";
+
+	open my $fd, "-|", git_cmd(), "rev-list",
+		"--parents",
+		"--header",
+		"--max-count=1",
+		$commit_id,
+		"--",
+		or die_error(500, "Open git-rev-list failed");
+	%co = parse_commit_text(<$fd>, 1);

With new API (see above) it would be

  +	%co = parse_commit_text(<$fd>, -with-parents => 1);

gitweb/lib/Gitweb/Parse.pm line 253

Quoted 7 lines
gitweb/lib/Gitweb/Parse.pm new file +7 -0
+	close $fd;
+
+	return %co;
+}
+
+sub parse_commits {
+	my ($commit_id, $maxcount, $skip, $filename, @args) = @_;

Here a weakness (I think) of Perl way of passing subroutine arguments is shown: it is impossible to have both slurpy @args and named parameters i.e. %opts, unless we pass optional / named parameters in hashref, i.e.

  +	my ($commit_id, @args) = @_;
  +	my %opts = ('-max-count' => 1, '-skip' => 0);
  +	%opts = (%opts, %{ shift @args }) if ref($args[ 0]) eq 'HASH';
  +	%opts = (%opts, %{ pop   @args }) if ref($args[-1]) eq 'HASH';

or something like that, and then using $opts{'-max-count'} and $opts{'-skip'} in place of $maxcount and $skip, etc.

gitweb/lib/Gitweb/Parse.pm line 254

Quoted 1 line
gitweb/lib/Gitweb/Parse.pm new file +1 -0
+	my @cos;

Errrr... @commits or @commit_list.

Quoted 7 lines
gitweb/lib/Gitweb/Parse.pm new file +7 -0
+
+	$maxcount ||= 1;
+	$skip ||= 0;
+
+	local $/ = "\0";
+
+	open my $fd, "-|", git_cmd(), "rev-list",

gitweb/lib/Gitweb/Parse.pm line 271

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+		"--header",
+		@args,
+		("--max-count=" . $maxcount),
+		("--skip=" . $skip),
+		@extra_options,
+		$commit_id,
+		"--",
+		($filename ? ($filename) : ())
+		or die_error(500, "Open git-rev-list failed");
+	while (my $line = <$fd>) {

Hmmm... should it be called '$line' if it is "\0" separated chunk, i.e. single commit? $commit_text could be better name, and if we 'chomp'ed it, we wouldn't have to 'pop' trailing "\0" in parse_commit_text.

gitweb/lib/Gitweb/Parse.pm line 277

Quoted 6 lines
gitweb/lib/Gitweb/Parse.pm new file +6 -0
+		my %co = parse_commit_text($line);
+		push @cos, \%co;
+	}
+	close $fd;
+
+	return wantarray ? @cos : \@cos;

Nowadays I really wonder if it is such a good idea, and if it wouldn't be better to just always return @cos (i.e. @commits / @commit_list).

We are a bit inconsistent WRT. context sensitivity.

Quoted 29 lines
gitweb/lib/Gitweb/Parse.pm new file +29 -0
+}
+
+# parse line of git-diff-tree "raw" output
+sub parse_difftree_raw_line {
+	my $line = shift;
+	my %res;
+
+	# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M	ls-files.c'
+	# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M	rev-tree.c'
+	if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
+		$res{'from_mode'} = $1;
+		$res{'to_mode'} = $2;
+		$res{'from_id'} = $3;
+		$res{'to_id'} = $4;
+		$res{'status'} = $5;
+		$res{'similarity'} = $6;
+		if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
+			($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
+		} else {
+			$res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
+		}
+	}
+	# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR	git-gui/git-gui.sh'
+	# combined diff (for merge commit)
+	elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
+		$res{'nparents'}  = length($1);
+		$res{'from_mode'} = [ split(' ', $2) ];
+		$res{'to_mode'} = pop @{$res{'from_mode'}};
+		$res{'from_id'} = [ split(' ', $3) ];

gitweb/lib/Gitweb/Parse.pm line 316

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+		$res{'to_id'} = pop @{$res{'from_id'}};
+		$res{'status'} = [ split('', $4) ];
+		$res{'to_file'} = unquote($5);
+	}
+	# 'c512b523472485aef4fff9e57b229d9d243c967f'
+	elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
+		$res{'commit'} = $1;
+	}
+
+	return wantarray ? %res : \%res;

Same here.

Quoted 36 lines
gitweb/lib/Gitweb/Parse.pm new file +36 -0
+}
+
+# wrapper: return parsed line of git-diff-tree "raw" output
+# (the argument might be raw line, or parsed info)
+sub parsed_difftree_line {
+	my $line_or_ref = shift;
+
+	if (ref($line_or_ref) eq "HASH") {
+		# pre-parsed (or generated by hand)
+		return $line_or_ref;
+	} else {
+		return parse_difftree_raw_line($line_or_ref);
+	}
+}
+
+# parse line of git-ls-tree output
+sub parse_ls_tree_line {
+	my $line = shift;
+	my %opts = @_;
+	my %res;
+
+	if ($opts{'-l'}) {
+		#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa   16717	panic.c'
+		$line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
+
+		$res{'mode'} = $1;
+		$res{'type'} = $2;
+		$res{'hash'} = $3;
+		$res{'size'} = $4;
+		if ($opts{'-z'}) {
+			$res{'name'} = $5;
+		} else {
+			$res{'name'} = unquote($5);
+		}
+	} else {
+		#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa	panic.c'

gitweb/lib/Gitweb/Parse.pm line 362

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+		$line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
+
+		$res{'mode'} = $1;
+		$res{'type'} = $2;
+		$res{'hash'} = $3;
+		if ($opts{'-z'}) {
+			$res{'name'} = $4;
+		} else {
+			$res{'name'} = unquote($4);
+		}

Hmmm... not all parse_* subroutines that can support '-z' named option do it.

gitweb/lib/Gitweb/Parse.pm line 316

Quoted 3 lines
gitweb/lib/Gitweb/Parse.pm new file +3 -0
+	}
+
+	return wantarray ? %res : \%res;

Same issue about context sensitivity here.

Quoted 37 lines
gitweb/lib/Gitweb/Parse.pm new file +37 -0
+}
+
+# generates _two_ hashes, references to which are passed as 2 and 3 argument
+sub parse_from_to_diffinfo {
+	my ($diffinfo, $from, $to, @parents) = @_;
+
+	if ($diffinfo->{'nparents'}) {
+		# combined diff
+		$from->{'file'} = [];
+		$from->{'href'} = [];
+		fill_from_file_info($diffinfo, @parents)
+			unless exists $diffinfo->{'from_file'};
+		for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
+			$from->{'file'}[$i] =
+				defined $diffinfo->{'from_file'}[$i] ?
+				        $diffinfo->{'from_file'}[$i] :
+				        $diffinfo->{'to_file'};
+			if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
+				$from->{'href'}[$i] = href(action=>"blob",
+				                           hash_base=>$parents[$i],
+				                           hash=>$diffinfo->{'from_id'}[$i],
+				                           file_name=>$from->{'file'}[$i]);
+			} else {
+				$from->{'href'}[$i] = undef;
+			}
+		}
+	} else {
+		# ordinary (not combined) diff
+		$from->{'file'} = $diffinfo->{'from_file'};
+		if ($diffinfo->{'status'} ne "A") { # not new (added) file
+			$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
+			                       hash=>$diffinfo->{'from_id'},
+			                       file_name=>$from->{'file'});
+		} else {
+			delete $from->{'href'};
+		}
+	}

gitweb/lib/Gitweb/Parse.pm line 412

Quoted 10 lines
gitweb/lib/Gitweb/Parse.pm new file +10 -0
+
+	$to->{'file'} = $diffinfo->{'to_file'};
+	if (!is_deleted($diffinfo)) { # file exists in result
+		$to->{'href'} = href(action=>"blob", hash_base=>$hash,
+		                     hash=>$diffinfo->{'to_id'},
+		                     file_name=>$to->{'file'});
+	} else {
+		delete $to->{'href'};
+	}
+}

Hmmm... this subroutine is not exactly like the other. I wonder if it wouldn't be better to leave it together with git_patchset_body. Or with fill_from_file_info.

Quoted 4 lines

+
+1;

Signature · 1 line
1.7.1.455.g8f441
Signature · 2 lines
Jakub Narebski
Poland
#25 lore raw
In reply to Pavan Kumar Sunkara

Heya,

Quoted 2 lines · Pavan Kumar Sunkara

10 patches out of the 11 patches in this patch series split gitweb into several small sized modules

What is the status of this series? Is anyone going to carry it forward? I remember multiple people wishing for gitweb to be more modular to make it easier to hack on? What shape is the series in, is it almost done, or will it need a lot more work?

Signature · 3 lines
Cheers,

Sverre Rabbelier
#26 lore raw
Quoted 9 lines · Sverre Rabbelier
Quoted 2 lines · Pavan Kumar Sunkara

10 patches out of the 11 patches in this patch series split gitweb into several small sized modules

What is the status of this series? Is anyone going to carry it forward? I remember multiple people wishing for gitweb to be more modular to make it easier to hack on? What shape is the series in, is it almost done, or will it need a lot more work?

It is almost done. The only major thing seems to be the "Prepare for splitting gitweb" patch, which should be I think replaced by updated version that uses shell loop in place of make's $(foreach ...) function to avoid possibility with generating a command line that exceeded the maximum argument list length. Might be unnecessary.

Most if not all comments that I have to this version of series was about commit messages, not the content of the patch itself.

If Pavan would not do re-roll of this series in a few days time, I will pick it up myself, and resubmit.

Quoted 2 lines

Pavan Kumar Sunkara (11):
  gitweb: fix esc_url

Comitted: 109988f (gitweb: fix esc_url, 2010-07-15)

Quoted 1 line

  gitweb: Prepare for splitting gitweb

To be replaced by new version of my "gitweb: Prepare for splitting gitweb" patch:

"[PATCHv3/RFC] gitweb: Prepare for splitting gitweb"
Message-ID: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/150463/focus=150544

Also it would need explanation that moving from

install SOURCE DEST

to

install SOURCE DIRECTORY

was done for security reason (I think), and because we cannot use portably -T' / --no-target-directory' option to install, as 1.) it is GNU-ism, 2.) it is not present in older GNU install.

Quoted 1 line

  gitweb: Create Gitweb::Git module

There was an issue about where to put descriptions of build-time
variables: in gitweb.perl or in individual modules. I think the issue was addressed somewhat in later commit, but I think it should be addressed here too.

Quoted 1 line

  gitweb: Create Gitweb::Config module

Here it would be nice to have description which related subroutines were not included, and why.

Quoted 1 line

  gitweb: Create Gitweb::Request module

It is quite strange for me that evaluate_query_params is in this module, but evaluate_path_info is not.

Also this module needs to be updated to newer codebase (lacks reset_timer subroutine).

Quoted 1 line

  gitweb: Create Gitweb::Escape module

ACK-ed.

Quoted 1 line

  gitweb: Create Gitweb::RepoConfig module

I'd like to have here better description of the intent behind this module, i.e. what kinds of subroutines it is to contain.

Here, and in later commits, the modules it depends on are named like Git.pm instead of Gitweb::Git in the commit message. This is a minor issue.

Quoted 1 line

  gitweb: Create Gitweb::View module

If it contains subroutines related only to HTML output, why isn't it called Gitweb::HTML then? If it contains some subroutines which are not strictly about HTML, it should be stated so in the commit message.

Also in the commit messages dividing moved subroutines into groups should be done better.

Quoted 1 line

  gitweb: Create Gitweb::Util module

Just a question: shouldn't git_get_last_activity subroutine be in Gitweb::RepoConfig module? Or is Gitweb::RepoConfig only about "static" properties of a repository?

This is result of not well enough described goal of Gitweb::RepoConfig module, see above.

Quoted 1 line

  gitweb: Create Gitweb::Format module

Straighforward moving of format_* subroutines and avatar formatting. The only thing that could be improved is describing why avatar related subroutines were put there.

Quoted 1 line

  gitweb: Create Gitweb::Parse module

The commit message might be improved by stating that it is output of git commands that gets parsed. There is also odd duck of parsed_difftree_line subroutine.

Signature · 2 lines
Jakub Narebski
Poland