Skip to contentSkip to conversation

instaweb: use minified gitweb.js if available

PATCH In review Mark Rada 2 participants 3 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore

Mark Rada

author
#0 lore raw

PATCH 1/1 instaweb: use minified gitweb.js if available

Makes git-instaweb use gitweb.min.js if it was generated.

---
 Makefile        |   13 +++++++------
 git-instaweb.sh |    1 +
 2 files changed, 8 insertions(+), 6 deletions(-)
Makefile +7 -6
index 7c616f8..1677928 100644
@@ -1551,12 +1551,12 @@ gitweb:
 	$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
  ifdef JSMIN
-OTHER_PROGRAMS += gitweb/gitweb.cgi   gitweb/gitweb.min.js
-gitweb/gitweb.cgi: gitweb/gitweb.perl gitweb/gitweb.min.js
+GITWEB_JS=gitweb/gitweb.min.js
 else
-OTHER_PROGRAMS += gitweb/gitweb.cgi
-gitweb/gitweb.cgi: gitweb/gitweb.perl
+GITWEB_JS=gitweb/gitweb.js
 endif
+OTHER_PROGRAMS += gitweb/gitweb.cgi $(GITWEB_JS)
+gitweb/gitweb.cgi: gitweb/gitweb.perl $(GITWEB_PROGRAMS)
 	$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
  ifdef JSMIN
@@ -1574,12 +1574,13 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.
 	    -e '/@@GITWEB_CGI@@/d' \
 	    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
 	    -e '/@@GITWEB_CSS@@/d' \
-	    -e '/@@GITWEB_JS@@/r gitweb/gitweb.js' \
+	    -e '/@@GITWEB_JS@@/r $(GITWEB_JS)' \
 	    -e '/@@GITWEB_JS@@/d' \
 	    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
 	    [email protected] > $@+ && \
 	chmod +x $@+ && \
-	mv $@+ $@
+	mv $@+ $@ && \
+	sed -i '' -e 's/min\.js/js/' $@
 else # NO_PERL
 $(patsubst %.perl,%,$(SCRIPT_PERL)) git-instaweb: % : unimplemented.sh
 	$(QUIET_GEN)$(RM) $@ $@+ && \
git-instaweb.sh +1 -0
index 6a65f25..72f8c39 100755
@@ -397,6 +397,7 @@ EOFGITWEB
 gitweb_js () {
 	cat > "$1" <<\EOFGITWEB
 @@GITWEB_JS@@
+
 EOFGITWEB
 }
 -- 1.7.0.1.300.gd855a
#1 lore raw
Quoted 20 lines · Mark Rada
Makefile +4 -4
@@ -1551,12 +1551,12 @@ gitweb:
 	$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
  ifdef JSMIN
-OTHER_PROGRAMS += gitweb/gitweb.cgi   gitweb/gitweb.min.js
-gitweb/gitweb.cgi: gitweb/gitweb.perl gitweb/gitweb.min.js
+GITWEB_JS=gitweb/gitweb.min.js
 else
-OTHER_PROGRAMS += gitweb/gitweb.cgi
-gitweb/gitweb.cgi: gitweb/gitweb.perl
+GITWEB_JS=gitweb/gitweb.js
 endif
+OTHER_PROGRAMS += gitweb/gitweb.cgi $(GITWEB_JS)
+gitweb/gitweb.cgi: gitweb/gitweb.perl $(GITWEB_PROGRAMS)
 	$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
  ifdef JSMIN
@@ -1574,12 +1574,13 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.
 	    -e '/@@GITWEB_CGI@@/d' \
 	    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \

Makefile git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb. · line 1583

Quoted 10 lines
Makefile +3 -2
 	    -e '/@@GITWEB_CSS@@/d' \
-	    -e '/@@GITWEB_JS@@/r gitweb/gitweb.js' \
+	    -e '/@@GITWEB_JS@@/r $(GITWEB_JS)' \
 	    -e '/@@GITWEB_JS@@/d' \
 	    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
 	    [email protected] > $@+ && \
 	chmod +x $@+ && \
-	mv $@+ $@
+	mv $@+ $@ && \
+	sed -i '' -e 's/min\.js/js/' $@

sed -i is not portable. But do you need it at all? Can't you add this change to the -e list above?

git-instaweb.sh EOFGITWEB · line 403

Quoted 10 lines
git-instaweb.sh +1 -0
@@ -397,6 +397,7 @@ EOFGITWEB
 gitweb_js () {
 	cat > "$1" <<\EOFGITWEB
 @@GITWEB_JS@@
+
 EOFGITWEB
 }
 -- 1.7.0.1.300.gd855a

This new blank line is an accident, isn't it?

-- Hannes

author
#2 lore raw
Quoted 26 lines · Johannes Sixt
Quoted 25 lines · Mark Rada
Makefile +5 -5
@@ -1551,12 +1551,12 @@ gitweb:
 	$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
  ifdef JSMIN
-OTHER_PROGRAMS += gitweb/gitweb.cgi   gitweb/gitweb.min.js
-gitweb/gitweb.cgi: gitweb/gitweb.perl gitweb/gitweb.min.js
+GITWEB_JS=gitweb/gitweb.min.js
 else
-OTHER_PROGRAMS += gitweb/gitweb.cgi
-gitweb/gitweb.cgi: gitweb/gitweb.perl
+GITWEB_JS=gitweb/gitweb.js
 endif
+OTHER_PROGRAMS += gitweb/gitweb.cgi $(GITWEB_JS)
+gitweb/gitweb.cgi: gitweb/gitweb.perl $(GITWEB_PROGRAMS)
 	$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
  ifdef JSMIN
@@ -1574,12 +1574,13 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.
 	    -e '/@@GITWEB_CGI@@/d' \
 	    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
 	    -e '/@@GITWEB_CSS@@/d' \
-	    -e '/@@GITWEB_JS@@/r gitweb/gitweb.js' \
+	    -e '/@@GITWEB_JS@@/r $(GITWEB_JS)' \
 	    -e '/@@GITWEB_JS@@/d' \
 	    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
Quoted 8 lines

Makefile git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb. · line 1583

Quoted 5 lines
Makefile +2 -1
 	    [email protected] > $@+ && \
 	chmod +x $@+ && \
-	mv $@+ $@
+	mv $@+ $@ && \
+	sed -i '' -e 's/min\.js/js/' $@

sed -i is not portable. But do you need it at all? Can't you add this change to the -e list above?

Hmm, the reason I made the change in a separate command was that the only place that min.js needed to be modified was in gitweb.cgi and only after it has been copied into git-instaweb.

We want to leave the actual gitweb.cgi as using gitweb.min.js, but the way instaweb creates the gitweb directory makes it create a gitweb.js no matter what (this is a bug if you create a minified gitweb.js because gitweb.cgi will look for a non-existant gitweb.min.js).

I figured that the smallest solution was to just edit the copied gitweb.cgi to use gitweb.js again, but since it is not portable I will have to either have messier code to do the same thing or make git-instaweb change the name of gitweb.js only in the case that we are using a minified gitweb.js.

Since I see no advantage or disadvantage to either, I'll flip a coin to decide this later on when I have some time.

Quoted 4 lines
Quoted 4 lines
git-instaweb.sh +0 -0
@@ -397,6 +397,7 @@ EOFGITWEB
 gitweb_js () {
Quoted 8 lines

git-instaweb.sh EOFGITWEB · line 403

Quoted 6 lines
git-instaweb.sh +1 -0
 	cat > "$1" <<\EOFGITWEB
 @@GITWEB_JS@@
+
 EOFGITWEB
 }
 -- 1.7.0.1.300.gd855a

This new blank line is an accident, isn't it?

Nope, this new line is here because the minifier I used cut the extra new line from the end of gitweb.js and then the EOFGITWEB token ended up on the same line as gitweb.js.

Quoted 6 lines

-- Hannes

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Mark Rada (ferrous26)
[email protected]