git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 2/5] gitweb: Prepare for splitting gitweb

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 3, 2012, 17:57 UTC
Message-ID
<1330797423-22926-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1330797423-22926-1-git-send-email-jnareb@gmail.com>

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.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch is the beginning of splitting gitweb (with its 8000+
lines, and more than 240kB) into modules, and is useful independently
of being in this patch series.
Sidenote: it is needed for __DIR__ only here.
 gitweb/Makefile    |   14 +++++++++++++-
 gitweb/gitweb.perl |    8 ++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/gitweb/Makefile b/gitweb/Makefile
index cd194d0..549e7dc 100644
--- a/gitweb/Makefile
+++ b/gitweb/Makefile
@@ -59,6 +59,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))#'
@@ -178,12 +179,23 @@ test-installed:
 
 ### Installation rules
 
-install: all
+install: all install-modules
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)'
 	$(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
 	$(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
 
+install-modules:
+	install_dirs="$(sort $(dir $(GITWEB_MODULES)))" && \
+	for dir in $$install_dirs; do \
+		test -d '$(DESTDIR_SQ)$(gitwebdir_SQ)/$$dir' || \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)/$$dir'; \
+	done
+	gitweb_modules="$(GITWEB_MODULES)" && \
+	for mod in $$gitweb_modules; do \
+		$(INSTALL) -m 644 $$mod '$(DESTDIR_SQ)$(gitwebdir_SQ)/$$(dirname $$mod)'; \
+	done
+
 ### Cleaning rules
 
 clean:
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2cca2cd..22efec2 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -10,6 +10,14 @@
 use 5.008;
 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);
-- 
1.7.9
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 7 in “gitweb: Proof of concept of PSGI interface”
  1. 0/5 gitweb: Proof of concept of PSGI interfaceJakub Narebski, Mar 3, 2012
  2. 1/5 gitweb: Jump do DONE_REQUEST not DONE_GITWEB on errorJakub Narebski, Mar 3, 2012
  3. 2/5 gitweb: Prepare for splitting gitwebJakub Narebski, Mar 3, 2012
  4. 3/5 gitweb: Enable running gitweb as PSGI app, via CGI::Emulate::PSGIJakub Narebski, Mar 3, 2012
  5. 4/5 gitweb.psgi: Allow passing arguments to Plack::RunnerJakub Narebski, Mar 3, 2012
  6. 5/5 git-instaweb: Use new PSGI interface mode of gitwebJakub Narebski, Mar 3, 2012
  7. 6/5 gitweb.psgi: Use installed static files, if they are availableJakub Narebski, Mar 8, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.