{"thread":{"id":"27242","subject":"[PATCHv2 0/2] gitweb: Beginnings of splitting gitweb into modules","startedAt":"2011-05-03T14:04:08Z","lastAt":"2011-08-24T02:17:03Z","messageCount":6,"participants":["Jakub Narebski","Sylvain Rabot","J.H.","Pavan Kumar Sunkara"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"166935","messageId":"1304431450-23901-1-git-send-email-jnareb@gmail.com","threadId":"27242","inReplyTo":null,"subject":"[PATCHv2 0/2] gitweb: Beginnings of splitting gitweb into modules","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-05-03T14:04:08Z","receivedAt":"2011-05-03T14:04:08Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Gitweb is currently next to largest file (after gitk) in git sources,\nmore than 225KB with more than 7,000 lines.  Therefore adding any\nlarge feature that would require large amount of code added, like\ngitweb caching by J.H. and my rewrite of it, or \"gitweb admin/write\"\n[failed] GSoC 2010 project by Pavan Kumar Sunkara, would require for\nnew code to be added as a separate module.  Otherwise gitweb would\nfast become unmaintainable.\n\nNote that there is already patch series sent which as one of side\neffects splits the JavaScript side of gitweb into many smaller\nself-contained files:\n\n  [PATCH 03/13] gitweb: Split JavaScript for maintability, combining on build\n  http://thread.gmane.org/gmane.comp.version-control.git/172384/focus=172385\n\nNot in all cases splitting gitweb upfront would be required.  At least\nin the case of gitweb caching it doesn't.  What must be done however\nis preparing the infrastructure for modular gitweb sources; to\nproperly test such infrastructure we need at least one split gitweb\nmodule.  With patch series preparing for splitting or true splitting of\ngitweb sent upfront the future patch series that implements\ncode-extensive feature (like e.g. output caching) would be smaller and\neasier to review.\n\n\nThis series is intended to bring such infrastructure to gitweb, to\nprepare way for adding output caching to gitweb. Alternatively it can\nbe thought as beginning of splitting gitweb into smaller submodules,\nfor better maintainability.\n\nThis patch series was sent to git mailing list as\n\n  [PATCH 0/2] gitweb: Begin splitting gitweb\n  http://thread.gmane.org/gmane.comp.version-control.git/165824\n\nIn the above mentioned first version of this series, the first patch\nthat prepared the way for splitting gitweb was in three versions: A, B\nand C.  In this second version of this series the first patch in\nseries most closely resembles version C in v1 series.\n\nIn this version gitweb uses _both_ 'use lib __DIR__.\"/lib\";' and\n'use lib \"++GITWEBLIBDIR++\";', in correct order (as compared to\nversion C of v1 series), so that __DIR__.\"/lib\" is checked first,\ni.e. modules installed alongside gitweb.cgi win.\n\nPull request:\n~~~~~~~~~~~~~\nThis series is available in the git repository at:\n  git://repo.or.cz/git/jnareb-git.git gitweb/split\n  git://github.com/jnareb/git.git gitweb/split\n\nWell, those patches has a few minor cosmetic fixups...\n\nTable of contents:\n~~~~~~~~~~~~~~~~~~\n* [PATCHv2 1/2] gitweb: Prepare for splitting gitweb\n  [PATCHv2 2/2] gitweb: Create Gitweb::Util module\n\n  First patch implements infrastructure, second proof of concept patch uses\n  this infrastructure, testing it (\"make -C gitweb test-installed\").\n\nShortlog:\n~~~~~~~~~\nJakub Narebski (1):\n  gitweb: Prepare for splitting gitweb\n\nPavan Kumar Sunkara (1):\n  gitweb: Create Gitweb::Util module\n\nDiffstat:\n~~~~~~~~~\n gitweb/INSTALL            |    7 ++\n gitweb/Makefile           |   23 ++++++-\n gitweb/gitweb.perl        |  151 ++++-----------------------------------\n gitweb/lib/Gitweb/Util.pm |  177 +++++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 219 insertions(+), 139 deletions(-)\n create mode 100755 gitweb/lib/Gitweb/Util.pm\n\n-- \n1.7.3\n"},{"id":"166936","messageId":"1304431450-23901-2-git-send-email-jnareb@gmail.com","threadId":"27242","inReplyTo":"1304431450-23901-1-git-send-email-jnareb@gmail.com","subject":"[PATCHv2 1/2 (RFC?)] gitweb: Prepare for splitting gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-05-03T14:04:09Z","receivedAt":"2011-05-03T14:04:09Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Prepare gitweb for being split into modules that would be installed in\n$(gitweblibdir), by default alongside gitweb in 'lib/' subdirectory.\n\nGitweb would search first in 'lib/' subdirectory from where gitweb.cgi\nis installed, via\n\n  use lib __DIR__.'/lib';\n\n(This allow for tests to work with source version of gitweb without\nchanges.)  Then it searches in $(gitweblibdir) directory (set during\nbuild time), by default \"$(gitwebdir)/lib\", via\n\n  use lib \"++GITWEBLIBDIR++\";\n\nwhich is set to requested dir during building of gitweb.cgi.  Note\nthat 'use lib' assures no trailing duplicate entries in @INC.\n\n\nThis preparatory work allows to add new module to gitweb by simply\nadding\n\n  GITWEB_MODULES += <module>\n\nto gitweb/Makefile (assuming that the module is in 'gitweb/lib/'\ndirectory).\n\nWhile at it pass GITWEBLIBDIR in addition to GITWEB_TEST_INSTALLED to\nallow testing installed version of gitweb and installed version of\nmodules (for future tests which would check individual (sub)modules).\n\n\nAt Pavan Kumar Sankara suggestion gitweb/Makefile uses\n\n  install [OPTION]... SOURCE... DIRECTORY\n\nformat (2nd format) with single SOURCE rather than\n\n  install [OPTION]... SOURCE DEST\n\nformat (1st format) because of security reasons (race conditions).\nModern GNU install has `-T' / `--no-target-directory' option, but we\ncannot rely that the $(INSTALL) we are using supports this option.\n\nThe install-modules target in gitweb/Makefile uses shell 'for' loop,\ninstead of make's $(foreach) function, to avoid possible problem with\ngenerating a command line that exceeded the maximum argument list\nlength.\n\nHelped-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>\nHelped-by: Alejandro R. Sedeño <asedeno@mit.edu>\nSigned-off-by: Jakub Narębski <jnareb@gmail.com>\n---\nThis patch is closest to\n\n  [PATCH (version C) 1/2] gitweb: Prepare for splitting gitweb\n  http://thread.gmane.org/gmane.comp.version-control.git/165824/focus=165826\n\nfrom previous (v1) version of this series.\n\n  Advantages:\n  - can run source version of gitweb (gitweb/gitweb.perl) as a script simply\n  - supports relocating gitweb modules (to gitweblibdir)\n  - allow users to simply install extra modules by hand alongside gitweb\n\n  Disadvantages:\n  - most complicated code of all cases\n\nIn this version modules from __DIR__.\"/lib\", i.e. installed alongside\ngitweb.cgi take preference over common modules installed in\n\"++GITWEBLIBDIR++\", as suggested / requested by Alejandro:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/165824/focus=165926  \n\n\nThis patch is marked as possible RFC because I am not sure if\n\"$(gitwebdir)/lib\" directory to install modules alongside gitweb.cgi\nshould be created unconditionally; it might be empty if\n$(gitweblibdir) is changed from its default version.\n\nThis version also include update to gitweb/INSTALL.\n\n\nSide-note: I have thought about adding sanity check for empty\n\"++GITWEBLIBDIR++\" in the form of\n\n  use if \"++GITWEBLIBDIR++\", lib => \"++GITWEBLIBDIR++\";\n\nor\n\n  use lib \"++GITWEBLIBDIR++\" || '.';\n\nBut because default value of \"++GITWEBLIBDIR++\" is never empty, I\ndon't think it is worth complicating code protecting against unlikely\nuser error; Perl would give the following warning:\n\n  Empty compile time value given to use lib\n\n gitweb/INSTALL     |    7 +++++++\n gitweb/Makefile    |   20 ++++++++++++++++++--\n gitweb/gitweb.perl |   11 +++++++++++\n 3 files changed, 36 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/INSTALL b/gitweb/INSTALL\nindex 4964a67..7af343a 100644\n--- a/gitweb/INSTALL\n+++ b/gitweb/INSTALL\n@@ -243,6 +243,13 @@ The following optional Perl modules are required for extra features\n  - HTML::TagCloud - for fancy tag cloud in project list view\n  - HTTP::Date or Time::ParseDate - to support If-Modified-Since for feeds\n \n+Those modules can be installed, in order of search, alongside\n+gitweb.cgi in 'lib/' subdirectory, in '$(gitweblibdir)' directory\n+(given during build), or in one of directories in which Perl looks for\n+library files (PERL5LIB, PERLLIB, standard places, current directory,\n+etc.).  Note that the first two places are by default the same\n+directory; \"$(gitweblibdir)\" is \"$(gitwebdir)/lib\".\n+\n \n Example web server configuration\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ndiff --git a/gitweb/Makefile b/gitweb/Makefile\nindex 0a6ac00..b353d15 100644\n--- a/gitweb/Makefile\n+++ b/gitweb/Makefile\n@@ -13,6 +13,7 @@ all::\n prefix ?= $(HOME)\n bindir ?= $(prefix)/bin\n gitwebdir ?= /var/www/cgi-bin\n+gitweblibdir ?= $(gitwebdir)/lib\n \n RM ?= rm -f\n INSTALL ?= install\n@@ -57,6 +58,7 @@ PERL_PATH  ?= /usr/bin/perl\n bindir_SQ = $(subst ','\\'',$(bindir))#'\n gitwebdir_SQ = $(subst ','\\'',$(gitwebdir))#'\n gitwebstaticdir_SQ = $(subst ','\\'',$(gitwebdir)/static)#'\n+gitweblibdir_SQ = $(subst ','\\'',$(gitweblibdir))#'\n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))#'\n PERL_PATH_SQ  = $(subst ','\\'',$(PERL_PATH))#'\n DESTDIR_SQ    = $(subst ','\\'',$(DESTDIR))#'\n@@ -115,6 +117,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png\n GITWEB_REPLACE = \\\n \t-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \\\n \t-e 's|++GIT_BINDIR++|$(bindir)|g' \\\n+\t-e 's|++GITWEBLIBDIR++|$(gitweblibdir)|g' \\\n \t-e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \\\n \t-e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \\\n \t-e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \\\n@@ -153,20 +156,33 @@ test:\n \n test-installed:\n \tGITWEB_TEST_INSTALLED='$(DESTDIR_SQ)$(gitwebdir_SQ)' \\\n+\tGITWEBLIBDIR='$(DESTDIR_SQ)$(gitweblibdir_SQ)' \\\n \t\t$(MAKE) -C ../t gitweb-test\n \n ### Installation rules\n \n-install: all\n+install: all install-modules\n \t$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)'\n \t$(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)'\n \t$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'\n \t$(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'\n \n+install-modules:\n+\t$(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)/lib'\n+\tinstall_dirs=\"$(sort $(dir $(GITWEB_MODULES)))\" && \\\n+\tfor dir in $$install_dirs; do \\\n+\t\ttest -d '$(DESTDIR_SQ)$(gitweblibdir_SQ)'/\"$$dir\" || \\\n+\t\t$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitweblibdir_SQ)'/\"$$dir\"; \\\n+\tdone\n+\tgitweb_modules=\"$(GITWEB_MODULES)\" && \\\n+\tfor mod in $$gitweb_modules; do \\\n+\t\t$(INSTALL) -m 644 \"lib/$$mod\" '$(DESTDIR_SQ)$(gitweblibdir_SQ)'/\"$$(dirname $$mod)\"; \\\n+\tdone\n+\n ### Cleaning rules\n \n clean:\n \t$(RM) gitweb.cgi static/gitweb.min.js static/gitweb.min.css GITWEB-BUILD-OPTIONS\n \n-.PHONY: all clean install test test-installed .FORCE-GIT-VERSION-FILE FORCE\n+.PHONY: all clean install install-modules test test-installed .FORCE-GIT-VERSION-FILE FORCE\n \ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex ee69ea6..f094471 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -10,6 +10,17 @@\n use 5.008;\n use strict;\n use warnings;\n+\n+use File::Spec;\n+\n+# __DIR__ is excerpt from Dir::Self\n+sub __DIR__ () {\n+\tFile::Spec->rel2abs(join '', (File::Spec->splitpath(__FILE__))[0, 1]);\n+}\n+use lib \"++GITWEBLIBDIR++\";\n+use lib __DIR__ . '/lib';\n+\n+\n use CGI qw(:standard :escapeHTML -nosticky);\n use CGI::Util qw(unescape);\n use CGI::Carp qw(fatalsToBrowser set_message);\n-- \n1.7.3\n"},{"id":"166937","messageId":"1304431450-23901-3-git-send-email-jnareb@gmail.com","threadId":"27242","inReplyTo":"1304431450-23901-1-git-send-email-jnareb@gmail.com","subject":"[PATCHv2 2/2 (PoC)] gitweb: Create Gitweb::Util module","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-05-03T14:04:10Z","receivedAt":"2011-05-03T14:04:10Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>\n\nCreate a Gitweb::Util module, which is meant to contain internal\nutilities used by gitweb.  Currently it includes all the\nquoting/unquoting and escaping subroutines that are used by the\ngitweb.\n\nUpdate gitweb/Makefile to install Gitweb::Util module alongside gitweb\n\nThis was sort of part of [unfinished] Google Summer of Code 2010\nproject \"Splitting gitweb and developing write functionalities\n(Integrated web client for git)\" by Pavan Kumar Sunkara, mentored by\nChristian Couder and co-mentored by Petr Baudis.\n\nSigned-off-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis patch is unchanged from previous version:\n\n  [PATCH (proof of concept) 2/2] gitweb: Create Gitweb::Util module\n  http://thread.gmane.org/gmane.comp.version-control.git/165824/focus=165828\n\n\nThis patch serves two purposes.  First, it serves as test that earlier\n\"gitweb: Prepare for splitting gitweb\" patch actually work correctly.\nThis can be checked by running \"make -C gitweb test-installed\" after\ninstalling gitweb (\"make install-gitweb\" or \"make -C gitweb install\").\n\nSecond, it might be good starting point to splitting gitweb.\nRefactoring well defined parts into separate modules (Perl packages)\ncould be a better, easier way than trying to come with good separation\n(split) into modules upfront.  Such leisure approach to splitting\ngitweb has more chance to be accepted.  Perhaps if such approach were\nproposed on GSoC 2010, maybe \"gitweb write\" project wouldn't fail\nmidterm evaluations...\n\n\nThis module was taken out of unfinished GSoC 2010 project with\nPavan Kumar Sunkara as a student\n\n  git://repo.or.cz/git/gsoc2010-gitweb.git\n\nThe module was renamed from Gitweb::Escape to Gitweb::Util.  Currently\nthe contents is the same, but it might change.\n\nCode was updated to more modern codebase; since then esc_path_info and\nesc_attr were added to gitweb - both of those are now in Gitweb::Util.\n\nThere were also required some changes and conflicts resolved due to\nthe fact that creating Gitweb::Util (formerly Gitweb::Escape) is no\nlonger in the middle of larger patch series.  In particular lack of\nGitweb::Config means that $fallback_encoding needed to be added to\nGitweb::Util module.\n\nWhile at it do not export quot_cec and quot_upr helper subroutines by\ndefault, but mark them exportable nevertheless.\n\n gitweb/Makefile           |    3 +\n gitweb/gitweb.perl        |  140 +-----------------------------------\n gitweb/lib/Gitweb/Util.pm |  177 +++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 183 insertions(+), 137 deletions(-)\n create mode 100644 gitweb/lib/Gitweb/Util.pm\n\ndiff --git a/gitweb/Makefile b/gitweb/Makefile\nindex b353d15..1b35808 100644\n--- a/gitweb/Makefile\n+++ b/gitweb/Makefile\n@@ -114,6 +114,9 @@ endif\n \n GITWEB_FILES += static/git-logo.png static/git-favicon.png\n \n+# Modules: Gitweb::*\n+GITWEB_MODULES += Gitweb/Util.pm\n+\n GITWEB_REPLACE = \\\n \t-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \\\n \t-e 's|++GIT_BINDIR++|$(bindir)|g' \\\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f094471..967ad64 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -24,11 +24,13 @@ use lib __DIR__ . '/lib';\n use CGI qw(:standard :escapeHTML -nosticky);\n use CGI::Util qw(unescape);\n use CGI::Carp qw(fatalsToBrowser set_message);\n-use Encode;\n use Fcntl ':mode';\n use File::Find qw();\n use File::Basename qw(basename);\n use Time::HiRes qw(gettimeofday tv_interval);\n+\n+use Gitweb::Util;\n+\n binmode STDOUT, ':utf8';\n \n our $t0 = [ gettimeofday() ];\n@@ -1391,128 +1393,6 @@ sub validate_refname {\n \treturn $input;\n }\n \n-# decode sequences of octets in utf8 into Perl's internal form,\n-# which is utf-8 with utf8 flag set if needed.  gitweb writes out\n-# in utf-8 thanks to \"binmode STDOUT, ':utf8'\" at beginning\n-sub to_utf8 {\n-\tmy $str = shift;\n-\treturn undef unless defined $str;\n-\tif (utf8::valid($str)) {\n-\t\tutf8::decode($str);\n-\t\treturn $str;\n-\t} else {\n-\t\treturn decode($fallback_encoding, $str, Encode::FB_DEFAULT);\n-\t}\n-}\n-\n-# quote unsafe chars, but keep the slash, even when it's not\n-# correct, but quoted slashes look too horrible in bookmarks\n-sub esc_param {\n-\tmy $str = shift;\n-\treturn undef unless defined $str;\n-\t$str =~ s/([^A-Za-z0-9\\-_.~()\\/:@ ]+)/CGI::escape($1)/eg;\n-\t$str =~ s/ /\\+/g;\n-\treturn $str;\n-}\n-\n-# the quoting rules for path_info fragment are slightly different\n-sub esc_path_info {\n-\tmy $str = shift;\n-\treturn undef unless defined $str;\n-\n-\t# path_info doesn't treat '+' as space (specially), but '?' must be escaped\n-\t$str =~ s/([^A-Za-z0-9\\-_.~();\\/;:@&= +]+)/CGI::escape($1)/eg;\n-\n-\treturn $str;\n-}\n-\n-# quote unsafe chars in whole URL, so some characters cannot be quoted\n-sub esc_url {\n-\tmy $str = shift;\n-\treturn undef unless defined $str;\n-\t$str =~ s/([^A-Za-z0-9\\-_.~();\\/;?:@&= ]+)/CGI::escape($1)/eg;\n-\t$str =~ s/ /\\+/g;\n-\treturn $str;\n-}\n-\n-# quote unsafe characters in HTML attributes\n-sub esc_attr {\n-\n-\t# for XHTML conformance escaping '\"' to '&quot;' is not enough\n-\treturn esc_html(@_);\n-}\n-\n-# replace invalid utf8 character with SUBSTITUTION sequence\n-sub esc_html {\n-\tmy $str = shift;\n-\tmy %opts = @_;\n-\n-\treturn undef unless defined $str;\n-\n-\t$str = to_utf8($str);\n-\t$str = $cgi->escapeHTML($str);\n-\tif ($opts{'-nbsp'}) {\n-\t\t$str =~ s/ /&nbsp;/g;\n-\t}\n-\t$str =~ s|([[:cntrl:]])|(($1 ne \"\\t\") ? quot_cec($1) : $1)|eg;\n-\treturn $str;\n-}\n-\n-# quote control characters and escape filename to HTML\n-sub esc_path {\n-\tmy $str = shift;\n-\tmy %opts = @_;\n-\n-\treturn undef unless defined $str;\n-\n-\t$str = to_utf8($str);\n-\t$str = $cgi->escapeHTML($str);\n-\tif ($opts{'-nbsp'}) {\n-\t\t$str =~ s/ /&nbsp;/g;\n-\t}\n-\t$str =~ s|([[:cntrl:]])|quot_cec($1)|eg;\n-\treturn $str;\n-}\n-\n-# Make control characters \"printable\", using character escape codes (CEC)\n-sub quot_cec {\n-\tmy $cntrl = shift;\n-\tmy %opts = @_;\n-\tmy %es = ( # character escape codes, aka escape sequences\n-\t\t\"\\t\" => '\\t',   # tab            (HT)\n-\t\t\"\\n\" => '\\n',   # line feed      (LF)\n-\t\t\"\\r\" => '\\r',   # carrige return (CR)\n-\t\t\"\\f\" => '\\f',   # form feed      (FF)\n-\t\t\"\\b\" => '\\b',   # backspace      (BS)\n-\t\t\"\\a\" => '\\a',   # alarm (bell)   (BEL)\n-\t\t\"\\e\" => '\\e',   # escape         (ESC)\n-\t\t\"\\013\" => '\\v', # vertical tab   (VT)\n-\t\t\"\\000\" => '\\0', # nul character  (NUL)\n-\t);\n-\tmy $chr = ( (exists $es{$cntrl})\n-\t\t    ? $es{$cntrl}\n-\t\t    : sprintf('\\%2x', ord($cntrl)) );\n-\tif ($opts{-nohtml}) {\n-\t\treturn $chr;\n-\t} else {\n-\t\treturn \"<span class=\\\"cntrl\\\">$chr</span>\";\n-\t}\n-}\n-\n-# Alternatively use unicode control pictures codepoints,\n-# Unicode \"printable representation\" (PR)\n-sub quot_upr {\n-\tmy $cntrl = shift;\n-\tmy %opts = @_;\n-\n-\tmy $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));\n-\tif ($opts{-nohtml}) {\n-\t\treturn $chr;\n-\t} else {\n-\t\treturn \"<span class=\\\"cntrl\\\">$chr</span>\";\n-\t}\n-}\n-\n # git may return quoted and escaped filenames\n sub unquote {\n \tmy $str = shift;\n@@ -1549,20 +1429,6 @@ sub unquote {\n \treturn $str;\n }\n \n-# escape tabs (convert tabs to spaces)\n-sub untabify {\n-\tmy $line = shift;\n-\n-\twhile ((my $pos = index($line, \"\\t\")) != -1) {\n-\t\tif (my $count = (8 - ($pos % 8))) {\n-\t\t\tmy $spaces = ' ' x $count;\n-\t\t\t$line =~ s/\\t/$spaces/;\n-\t\t}\n-\t}\n-\n-\treturn $line;\n-}\n-\n sub project_in_list {\n \tmy $project = shift;\n \tmy @list = git_get_projects_list();\ndiff --git a/gitweb/lib/Gitweb/Util.pm b/gitweb/lib/Gitweb/Util.pm\nnew file mode 100644\nindex 0000000..a213d3f\n--- /dev/null\n+++ b/gitweb/lib/Gitweb/Util.pm\n@@ -0,0 +1,177 @@\n+# Gitweb::Util -- Internal utilities used by gitweb (git web interface)\n+#\n+# This module is licensed under the GPLv2\n+\n+package Gitweb::Util;\n+\n+use strict;\n+use warnings;\n+use Exporter qw(import);\n+\n+our @EXPORT = qw(to_utf8\n+                 esc_param esc_path_info esc_url\n+                 esc_html esc_path esc_attr\n+                 untabify\n+                 $fallback_encoding);\n+our @EXPORT_OK = qw(quot_cec quot_upr);\n+\n+use Encode;\n+use CGI;\n+\n+# ......................................................................\n+# Perl encoding (utf-8)\n+\n+# decode sequences of octets in utf8 into Perl's internal form,\n+# which is utf-8 with utf8 flag set if needed.  gitweb writes out\n+# in utf-8 thanks to \"binmode STDOUT, ':utf8'\" at beginning of gitweb.perl\n+our $fallback_encoding = 'latin1';\n+sub to_utf8 {\n+\tmy $str = shift;\n+\treturn undef unless defined $str;\n+\tif (utf8::valid($str)) {\n+\t\tutf8::decode($str);\n+\t\treturn $str;\n+\t} else {\n+\t\treturn decode($fallback_encoding, $str, Encode::FB_DEFAULT);\n+\t}\n+}\n+\n+# ......................................................................\n+# CGI encoding\n+\n+# quote unsafe chars, but keep the slash, even when it's not\n+# correct, but quoted slashes look too horrible in bookmarks\n+sub esc_param {\n+\tmy $str = shift;\n+\treturn undef unless defined $str;\n+\n+\t$str =~ s/([^A-Za-z0-9\\-_.~()\\/:@ ]+)/CGI::escape($1)/eg;\n+\t$str =~ s/ /\\+/g;\n+\n+\treturn $str;\n+}\n+\n+# the quoting rules for path_info fragment are slightly different\n+sub esc_path_info {\n+\tmy $str = shift;\n+\treturn undef unless defined $str;\n+\n+\t# path_info doesn't treat '+' as space (specially), but '?' must be escaped\n+\t$str =~ s/([^A-Za-z0-9\\-_.~();\\/;:@&= +]+)/CGI::escape($1)/eg;\n+\n+\treturn $str;\n+}\n+\n+# quote unsafe chars in whole URL, so some characters cannot be quoted\n+sub esc_url {\n+\tmy $str = shift;\n+\treturn undef unless defined $str;\n+\n+\t$str =~ s/([^A-Za-z0-9\\-_.~();\\/;?:@&= ]+)/CGI::escape($1)/eg;\n+\t$str =~ s/ /\\+/g;\n+\n+\treturn $str;\n+}\n+\n+# ......................................................................\n+# (X)HTML escaping\n+\n+# replace invalid utf8 character with SUBSTITUTION sequence\n+sub esc_html {\n+\tmy $str = shift;\n+\tmy %opts = @_;\n+\n+\treturn undef unless defined $str;\n+\n+\t$str = to_utf8($str);\n+\t$str = CGI::escapeHTML($str);\n+\tif ($opts{'-nbsp'}) {\n+\t\t$str =~ s/ /&nbsp;/g;\n+\t}\n+\t$str =~ s|([[:cntrl:]])|(($1 ne \"\\t\") ? quot_cec($1) : $1)|eg;\n+\treturn $str;\n+}\n+\n+# quote unsafe characters in HTML attributes\n+sub esc_attr {\n+\n+\t# for XHTML conformance escaping '\"' to '&quot;' is not enough\n+\treturn esc_html(@_);\n+}\n+\n+# quote control characters and escape filename to HTML\n+sub esc_path {\n+\tmy $str = shift;\n+\tmy %opts = @_;\n+\n+\treturn undef unless defined $str;\n+\n+\t$str = to_utf8($str);\n+\t$str = CGI::escapeHTML($str);\n+\tif ($opts{'-nbsp'}) {\n+\t\t$str =~ s/ /&nbsp;/g;\n+\t}\n+\t$str =~ s|([[:cntrl:]])|quot_cec($1)|eg;\n+\treturn $str;\n+}\n+\n+# ......................................................................\n+# Other\n+\n+# escape tabs (convert tabs to spaces)\n+sub untabify {\n+\tmy $line = shift;\n+\n+\twhile ((my $pos = index($line, \"\\t\")) != -1) {\n+\t\tif (my $count = (8 - ($pos % 8))) {\n+\t\t\tmy $spaces = ' ' x $count;\n+\t\t\t$line =~ s/\\t/$spaces/;\n+\t\t}\n+\t}\n+\n+\treturn $line;\n+}\n+\n+# ----------------------------------------------------------------------\n+# Showing \"unprintable\" characters (utility functions)\n+\n+# Make control characters \"printable\", using character escape codes (CEC)\n+sub quot_cec {\n+\tmy $cntrl = shift;\n+\tmy %opts = @_;\n+\tmy %es = ( # character escape codes, aka escape sequences\n+\t\t\"\\t\" => '\\t',   # tab            (HT)\n+\t\t\"\\n\" => '\\n',   # line feed      (LF)\n+\t\t\"\\r\" => '\\r',   # carrige return (CR)\n+\t\t\"\\f\" => '\\f',   # form feed      (FF)\n+\t\t\"\\b\" => '\\b',   # backspace      (BS)\n+\t\t\"\\a\" => '\\a',   # alarm (bell)   (BEL)\n+\t\t\"\\e\" => '\\e',   # escape         (ESC)\n+\t\t\"\\013\" => '\\v', # vertical tab   (VT)\n+\t\t\"\\000\" => '\\0', # nul character  (NUL)\n+\t);\n+\tmy $chr = ( (exists $es{$cntrl})\n+\t\t    ? $es{$cntrl}\n+\t\t    : sprintf('\\%2x', ord($cntrl)) );\n+\tif ($opts{-nohtml}) {\n+\t\treturn $chr;\n+\t} else {\n+\t\treturn \"<span class=\\\"cntrl\\\">$chr</span>\";\n+\t}\n+}\n+\n+# Alternatively use unicode control pictures codepoints,\n+# Unicode \"printable representation\" (PR)\n+sub quot_upr {\n+\tmy $cntrl = shift;\n+\tmy %opts = @_;\n+\n+\tmy $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));\n+\tif ($opts{-nohtml}) {\n+\t\treturn $chr;\n+\t} else {\n+\t\treturn \"<span class=\\\"cntrl\\\">$chr</span>\";\n+\t}\n+}\n+\n+1;\n-- \n1.7.3\n"},{"id":"174120","messageId":"1314131735.3120.3.camel@kheops","threadId":"27242","inReplyTo":"1304431450-23901-1-git-send-email-jnareb@gmail.com","subject":"Re: [PATCHv2 0/2] gitweb: Beginnings of splitting gitweb into modules","fromName":"Sylvain Rabot","fromEmail":"sylvain@abstraction.fr","sentAt":"2011-08-23T20:35:35Z","receivedAt":"2011-08-23T20:35:35Z","isPatch":false,"sender":{"key":"sylvain@abstraction.fr","avatar":"https://avatars.githubusercontent.com/u/153052?v=4"},"body":"Hi,\n\nJust wanted to know what is the current status of splitting gitweb\nsources into modules.\n\nRegards.\n\nOn Tue, 2011-05-03 at 16:04 +0200, Jakub Narebski wrote:\n> Gitweb is currently next to largest file (after gitk) in git sources,\n> more than 225KB with more than 7,000 lines.  Therefore adding any\n> large feature that would require large amount of code added, like\n> gitweb caching by J.H. and my rewrite of it, or \"gitweb admin/write\"\n> [failed] GSoC 2010 project by Pavan Kumar Sunkara, would require for\n> new code to be added as a separate module.  Otherwise gitweb would\n> fast become unmaintainable.\n> \n> Note that there is already patch series sent which as one of side\n> effects splits the JavaScript side of gitweb into many smaller\n> self-contained files:\n> \n>   [PATCH 03/13] gitweb: Split JavaScript for maintability, combining on build\n>   http://thread.gmane.org/gmane.comp.version-control.git/172384/focus=172385\n> \n> Not in all cases splitting gitweb upfront would be required.  At least\n> in the case of gitweb caching it doesn't.  What must be done however\n> is preparing the infrastructure for modular gitweb sources; to\n> properly test such infrastructure we need at least one split gitweb\n> module.  With patch series preparing for splitting or true splitting of\n> gitweb sent upfront the future patch series that implements\n> code-extensive feature (like e.g. output caching) would be smaller and\n> easier to review.\n> \n> \n> This series is intended to bring such infrastructure to gitweb, to\n> prepare way for adding output caching to gitweb. Alternatively it can\n> be thought as beginning of splitting gitweb into smaller submodules,\n> for better maintainability.\n> \n> This patch series was sent to git mailing list as\n> \n>   [PATCH 0/2] gitweb: Begin splitting gitweb\n>   http://thread.gmane.org/gmane.comp.version-control.git/165824\n> \n> In the above mentioned first version of this series, the first patch\n> that prepared the way for splitting gitweb was in three versions: A, B\n> and C.  In this second version of this series the first patch in\n> series most closely resembles version C in v1 series.\n> \n> In this version gitweb uses _both_ 'use lib __DIR__.\"/lib\";' and\n> 'use lib \"++GITWEBLIBDIR++\";', in correct order (as compared to\n> version C of v1 series), so that __DIR__.\"/lib\" is checked first,\n> i.e. modules installed alongside gitweb.cgi win.\n> \n> Pull request:\n> ~~~~~~~~~~~~~\n> This series is available in the git repository at:\n>   git://repo.or.cz/git/jnareb-git.git gitweb/split\n>   git://github.com/jnareb/git.git gitweb/split\n> \n> Well, those patches has a few minor cosmetic fixups...\n> \n> Table of contents:\n> ~~~~~~~~~~~~~~~~~~\n> * [PATCHv2 1/2] gitweb: Prepare for splitting gitweb\n>   [PATCHv2 2/2] gitweb: Create Gitweb::Util module\n> \n>   First patch implements infrastructure, second proof of concept patch uses\n>   this infrastructure, testing it (\"make -C gitweb test-installed\").\n> \n> Shortlog:\n> ~~~~~~~~~\n> Jakub Narebski (1):\n>   gitweb: Prepare for splitting gitweb\n> \n> Pavan Kumar Sunkara (1):\n>   gitweb: Create Gitweb::Util module\n> \n> Diffstat:\n> ~~~~~~~~~\n>  gitweb/INSTALL            |    7 ++\n>  gitweb/Makefile           |   23 ++++++-\n>  gitweb/gitweb.perl        |  151 ++++-----------------------------------\n>  gitweb/lib/Gitweb/Util.pm |  177 +++++++++++++++++++++++++++++++++++++++++++++\n>  4 files changed, 219 insertions(+), 139 deletions(-)\n>  create mode 100755 gitweb/lib/Gitweb/Util.pm\n> \n\n-- \nSylvain Rabot <sylvain@abstraction.fr>\n"},{"id":"174121","messageId":"4E54102D.8060900@eaglescrag.net","threadId":"27242","inReplyTo":"1314131735.3120.3.camel@kheops","subject":"Re: [PATCHv2 0/2] gitweb: Beginnings of splitting gitweb into modules","fromName":"J.H.","fromEmail":"warthog9@eaglescrag.net","sentAt":"2011-08-23T20:40:13Z","receivedAt":"2011-08-23T20:40:13Z","isPatch":false,"sender":{"key":"warthog9@kernel.org","avatar":"https://avatars.githubusercontent.com/u/2334704?v=4"},"body":"Pretty much stalled like most things on gitweb.  I've been knee deep in\na lot of GSoC stuff, conferences and dealing with kernel bugs and Jakub\nhas been busy on other things so we haven't had a solid head bashing\nsession to get this all worked out yet.\n\nMaybe while I'm over in Prague / Europe for KS & Linuxcon we can hash\nthings out.\n\n- John 'Warthog9' Hawley\n\nOn 08/23/2011 01:35 PM, Sylvain Rabot wrote:\n> Hi,\n> \n> Just wanted to know what is the current status of splitting gitweb\n> sources into modules.\n> \n> Regards.\n> \n> On Tue, 2011-05-03 at 16:04 +0200, Jakub Narebski wrote:\n>> Gitweb is currently next to largest file (after gitk) in git sources,\n>> more than 225KB with more than 7,000 lines.  Therefore adding any\n>> large feature that would require large amount of code added, like\n>> gitweb caching by J.H. and my rewrite of it, or \"gitweb admin/write\"\n>> [failed] GSoC 2010 project by Pavan Kumar Sunkara, would require for\n>> new code to be added as a separate module.  Otherwise gitweb would\n>> fast become unmaintainable.\n>>\n>> Note that there is already patch series sent which as one of side\n>> effects splits the JavaScript side of gitweb into many smaller\n>> self-contained files:\n>>\n>>   [PATCH 03/13] gitweb: Split JavaScript for maintability, combining on build\n>>   http://thread.gmane.org/gmane.comp.version-control.git/172384/focus=172385\n>>\n>> Not in all cases splitting gitweb upfront would be required.  At least\n>> in the case of gitweb caching it doesn't.  What must be done however\n>> is preparing the infrastructure for modular gitweb sources; to\n>> properly test such infrastructure we need at least one split gitweb\n>> module.  With patch series preparing for splitting or true splitting of\n>> gitweb sent upfront the future patch series that implements\n>> code-extensive feature (like e.g. output caching) would be smaller and\n>> easier to review.\n>>\n>>\n>> This series is intended to bring such infrastructure to gitweb, to\n>> prepare way for adding output caching to gitweb. Alternatively it can\n>> be thought as beginning of splitting gitweb into smaller submodules,\n>> for better maintainability.\n>>\n>> This patch series was sent to git mailing list as\n>>\n>>   [PATCH 0/2] gitweb: Begin splitting gitweb\n>>   http://thread.gmane.org/gmane.comp.version-control.git/165824\n>>\n>> In the above mentioned first version of this series, the first patch\n>> that prepared the way for splitting gitweb was in three versions: A, B\n>> and C.  In this second version of this series the first patch in\n>> series most closely resembles version C in v1 series.\n>>\n>> In this version gitweb uses _both_ 'use lib __DIR__.\"/lib\";' and\n>> 'use lib \"++GITWEBLIBDIR++\";', in correct order (as compared to\n>> version C of v1 series), so that __DIR__.\"/lib\" is checked first,\n>> i.e. modules installed alongside gitweb.cgi win.\n>>\n>> Pull request:\n>> ~~~~~~~~~~~~~\n>> This series is available in the git repository at:\n>>   git://repo.or.cz/git/jnareb-git.git gitweb/split\n>>   git://github.com/jnareb/git.git gitweb/split\n>>\n>> Well, those patches has a few minor cosmetic fixups...\n>>\n>> Table of contents:\n>> ~~~~~~~~~~~~~~~~~~\n>> * [PATCHv2 1/2] gitweb: Prepare for splitting gitweb\n>>   [PATCHv2 2/2] gitweb: Create Gitweb::Util module\n>>\n>>   First patch implements infrastructure, second proof of concept patch uses\n>>   this infrastructure, testing it (\"make -C gitweb test-installed\").\n>>\n>> Shortlog:\n>> ~~~~~~~~~\n>> Jakub Narebski (1):\n>>   gitweb: Prepare for splitting gitweb\n>>\n>> Pavan Kumar Sunkara (1):\n>>   gitweb: Create Gitweb::Util module\n>>\n>> Diffstat:\n>> ~~~~~~~~~\n>>  gitweb/INSTALL            |    7 ++\n>>  gitweb/Makefile           |   23 ++++++-\n>>  gitweb/gitweb.perl        |  151 ++++-----------------------------------\n>>  gitweb/lib/Gitweb/Util.pm |  177 +++++++++++++++++++++++++++++++++++++++++++++\n>>  4 files changed, 219 insertions(+), 139 deletions(-)\n>>  create mode 100755 gitweb/lib/Gitweb/Util.pm\n>>\n> \n"},{"id":"174136","messageId":"CAK9CXBUsEN=avE1c=RvLVf5ws9B6rZ4tP=gyaWpOPQa=y0qZAw@mail.gmail.com","threadId":"27242","inReplyTo":"4E54102D.8060900@eaglescrag.net","subject":"Re: [PATCHv2 0/2] gitweb: Beginnings of splitting gitweb into modules","fromName":"Pavan Kumar Sunkara","fromEmail":"pavan.sss1991@gmail.com","sentAt":"2011-08-24T02:17:03Z","receivedAt":"2011-08-24T02:17:03Z","isPatch":false,"sender":{"key":"pavan.sss1991@gmail.com","avatar":"https://avatars.githubusercontent.com/u/174703?v=4"},"body":"I can try to restart it. I had a lot of health issues last year, But I\nam free now to finish this series.\n\nOn Wed, Aug 24, 2011 at 2:10 AM, J.H. <warthog9@eaglescrag.net> wrote:\n> Pretty much stalled like most things on gitweb.  I've been knee deep in\n> a lot of GSoC stuff, conferences and dealing with kernel bugs and Jakub\n> has been busy on other things so we haven't had a solid head bashing\n> session to get this all worked out yet.\n>\n> Maybe while I'm over in Prague / Europe for KS & Linuxcon we can hash\n> things out.\n>\n> - John 'Warthog9' Hawley\n>\n> On 08/23/2011 01:35 PM, Sylvain Rabot wrote:\n>> Hi,\n>>\n>> Just wanted to know what is the current status of splitting gitweb\n>> sources into modules.\n>>\n>> Regards.\n>>\n>> On Tue, 2011-05-03 at 16:04 +0200, Jakub Narebski wrote:\n>>> Gitweb is currently next to largest file (after gitk) in git sources,\n>>> more than 225KB with more than 7,000 lines.  Therefore adding any\n>>> large feature that would require large amount of code added, like\n>>> gitweb caching by J.H. and my rewrite of it, or \"gitweb admin/write\"\n>>> [failed] GSoC 2010 project by Pavan Kumar Sunkara, would require for\n>>> new code to be added as a separate module.  Otherwise gitweb would\n>>> fast become unmaintainable.\n>>>\n>>> Note that there is already patch series sent which as one of side\n>>> effects splits the JavaScript side of gitweb into many smaller\n>>> self-contained files:\n>>>\n>>>   [PATCH 03/13] gitweb: Split JavaScript for maintability, combining on build\n>>>   http://thread.gmane.org/gmane.comp.version-control.git/172384/focus=172385\n>>>\n>>> Not in all cases splitting gitweb upfront would be required.  At least\n>>> in the case of gitweb caching it doesn't.  What must be done however\n>>> is preparing the infrastructure for modular gitweb sources; to\n>>> properly test such infrastructure we need at least one split gitweb\n>>> module.  With patch series preparing for splitting or true splitting of\n>>> gitweb sent upfront the future patch series that implements\n>>> code-extensive feature (like e.g. output caching) would be smaller and\n>>> easier to review.\n>>>\n>>>\n>>> This series is intended to bring such infrastructure to gitweb, to\n>>> prepare way for adding output caching to gitweb. Alternatively it can\n>>> be thought as beginning of splitting gitweb into smaller submodules,\n>>> for better maintainability.\n>>>\n>>> This patch series was sent to git mailing list as\n>>>\n>>>   [PATCH 0/2] gitweb: Begin splitting gitweb\n>>>   http://thread.gmane.org/gmane.comp.version-control.git/165824\n>>>\n>>> In the above mentioned first version of this series, the first patch\n>>> that prepared the way for splitting gitweb was in three versions: A, B\n>>> and C.  In this second version of this series the first patch in\n>>> series most closely resembles version C in v1 series.\n>>>\n>>> In this version gitweb uses _both_ 'use lib __DIR__.\"/lib\";' and\n>>> 'use lib \"++GITWEBLIBDIR++\";', in correct order (as compared to\n>>> version C of v1 series), so that __DIR__.\"/lib\" is checked first,\n>>> i.e. modules installed alongside gitweb.cgi win.\n>>>\n>>> Pull request:\n>>> ~~~~~~~~~~~~~\n>>> This series is available in the git repository at:\n>>>   git://repo.or.cz/git/jnareb-git.git gitweb/split\n>>>   git://github.com/jnareb/git.git gitweb/split\n>>>\n>>> Well, those patches has a few minor cosmetic fixups...\n>>>\n>>> Table of contents:\n>>> ~~~~~~~~~~~~~~~~~~\n>>> * [PATCHv2 1/2] gitweb: Prepare for splitting gitweb\n>>>   [PATCHv2 2/2] gitweb: Create Gitweb::Util module\n>>>\n>>>   First patch implements infrastructure, second proof of concept patch uses\n>>>   this infrastructure, testing it (\"make -C gitweb test-installed\").\n>>>\n>>> Shortlog:\n>>> ~~~~~~~~~\n>>> Jakub Narebski (1):\n>>>   gitweb: Prepare for splitting gitweb\n>>>\n>>> Pavan Kumar Sunkara (1):\n>>>   gitweb: Create Gitweb::Util module\n>>>\n>>> Diffstat:\n>>> ~~~~~~~~~\n>>>  gitweb/INSTALL            |    7 ++\n>>>  gitweb/Makefile           |   23 ++++++-\n>>>  gitweb/gitweb.perl        |  151 ++++-----------------------------------\n>>>  gitweb/lib/Gitweb/Util.pm |  177 +++++++++++++++++++++++++++++++++++++++++++++\n>>>  4 files changed, 219 insertions(+), 139 deletions(-)\n>>>  create mode 100755 gitweb/lib/Gitweb/Util.pm\n>>>\n>>\n>\n>\n\n\n\n-- \n- Pavan Kumar Sunkara\n"}]}