threads / patch / 26085

patch, 3 partsminor gitweb modifications

Subject: [PATCH 0/3] minor gitweb modifications

## tl;dr

12 messages between Nov 16, 2010 and Dec 20, 2010. Diffs are folded; open one to read it.

replies: 11people: 3as markdown or json

Sylvain Rabot· Dec 16, 2010, 21:43 UTC · lore
Hi,
here a three patch serie with minor updates for gitweb based on master.

I'm not really fond of the third patch but it solves a problem I've encountered on several files.

Regards.
Sylvain Rabot (3):
  gitweb: add extensions to highlight feature
  gitweb: decorate a bit more remotes
  gitweb: remove test when closing file descriptor
 gitweb/gitweb.perl |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
-- 
1.7.3.2
Sylvain Rabot· Dec 16, 2010, 21:43 UTC · re: Sylvain Rabot · lore

[PATCH 1/3] gitweb: add extensions to highlight feature

added: sql, php5, phps, bash, zsh, mk
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
---
 gitweb/gitweb.perl |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
Show changes to gitweb/gitweb.perl +4 −3
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d521c93..db18d06 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -250,13 +250,14 @@ our %highlight_ext = (
 	# main extensions, defining name of syntax;
 	# see files in /usr/share/highlight/langDefs/ directory
 	map { $_ => $_ }
-		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
+		qw(py c cpp rb java css php pl js tex bib xml awk bat ini spec tcl sql),
 	# alternate extensions, see /etc/highlight/filetypes.conf
 	'h' => 'c',
+	map { $_ => 'sh'  } qw(bash zsh),
 	map { $_ => 'cpp' } qw(cxx c++ cc),
-	map { $_ => 'php' } qw(php3 php4),
+	map { $_ => 'php' } qw(php3 php4 php5 phps),
 	map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
-	'mak' => 'make',
+	map { $_ => 'make'} qw(mak mk),
 	map { $_ => 'xml' } qw(xhtml html htm),
 );
 
-- 
1.7.3.2
Jakub Narebski· Dec 16, 2010, 22:22 UTC · re: Sylvain Rabot · lore

Re: [PATCH 1/3] gitweb: add extensions to highlight feature

Sylvain Rabot <sylvain@abstraction.fr> writes:
> added: sql, php5, phps, bash, zsh, mk
> 

There is one issue with this patch (see below), but otherwise I like it.

Show 15 quoted lines
> Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> ---
>  gitweb/gitweb.perl |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index d521c93..db18d06 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -250,13 +250,14 @@ our %highlight_ext = (
>  	# main extensions, defining name of syntax;
>  	# see files in /usr/share/highlight/langDefs/ directory
>  	map { $_ => $_ }
> -		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
> +		qw(py c cpp rb java css php pl js tex bib xml awk bat ini spec tcl sql),
Why did you remove 'sh' => 'sh' mapping?  Shouldn't it be
  -		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
  +		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql),
>  	# alternate extensions, see /etc/highlight/filetypes.conf
>  	'h' => 'c',
> +	map { $_ => 'sh'  } qw(bash zsh),
Good idea.
>  	map { $_ => 'cpp' } qw(cxx c++ cc),
> -	map { $_ => 'php' } qw(php3 php4),
> +	map { $_ => 'php' } qw(php3 php4 php5 phps),
Good idea.
>  	map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
> -	'mak' => 'make',
> +	map { $_ => 'make'} qw(mak mk),
Good idea.
Sidenote: git itself uses *.mak extension.  Is *.mk popular?
Show 6 quoted lines
>  	map { $_ => 'xml' } qw(xhtml html htm),
>  );
>  
> -- 
> 1.7.3.2
> 
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Sylvain Rabot· Dec 16, 2010, 22:33 UTC · re: Jakub Narebski · lore

Re: [PATCH 1/3] gitweb: add extensions to highlight feature

On Thu, 2010-12-16 at 14:22 -0800, Jakub Narebski wrote:
Show 29 quoted lines
> Sylvain Rabot <sylvain@abstraction.fr> writes:
> 
> > added: sql, php5, phps, bash, zsh, mk
> > 
> 
> There is one issue with this patch (see below), but otherwise I like
> it.
> 
> > Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> > ---
> >  gitweb/gitweb.perl |    7 ++++---
> >  1 files changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> > index d521c93..db18d06 100755
> > --- a/gitweb/gitweb.perl
> > +++ b/gitweb/gitweb.perl
> > @@ -250,13 +250,14 @@ our %highlight_ext = (
> >  	# main extensions, defining name of syntax;
> >  	# see files in /usr/share/highlight/langDefs/ directory
> >  	map { $_ => $_ }
> > -		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
> > +		qw(py c cpp rb java css php pl js tex bib xml awk bat ini spec tcl sql),
> 
> Why did you remove 'sh' => 'sh' mapping?  Shouldn't it be
> 
>   -		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
>   +		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql),
> 

I removed it on purpose but should have not, I was thinking the mapping made below would be enough but no, you're right.

Show 5 quoted lines
> >  	# alternate extensions, see /etc/highlight/filetypes.conf
> >  	'h' => 'c',
> > +	map { $_ => 'sh'  } qw(bash zsh),
> 
> Good idea.
Does ksh, csh can be highlighted as sh too ?
Show 14 quoted lines
> 
> >  	map { $_ => 'cpp' } qw(cxx c++ cc),
> > -	map { $_ => 'php' } qw(php3 php4),
> > +	map { $_ => 'php' } qw(php3 php4 php5 phps),
> 
> Good idea.
> 
> >  	map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
> > -	'mak' => 'make',
> > +	map { $_ => 'make'} qw(mak mk),
> 
> Good idea.
> 
> Sidenote: git itself uses *.mak extension.  Is *.mk popular?

Don't know but mk is mapped to Makefiles in the gtksourceview lib so I added it here.

Show 8 quoted lines
> 
> >  	map { $_ => 'xml' } qw(xhtml html htm),
> >  );
> >  
> > -- 
> > 1.7.3.2
> > 
> 
-- 
Sylvain Rabot <sylvain@abstraction.fr>
Jakub Narebski· Dec 17, 2010, 11:17 UTC · re: Sylvain Rabot · lore

Re: [PATCH 1/3] gitweb: add extensions to highlight feature

On Thu, 16 Dec 2010, Sylvain Rabot wrote:
> On Thu, 2010-12-16 at 14:22 -0800, Jakub Narebski wrote:
> > Sylvain Rabot <sylvain@abstraction.fr> writes:
Show 7 quoted lines
> > >  	# alternate extensions, see /etc/highlight/filetypes.conf
> > >  	'h' => 'c',
> > > +	map { $_ => 'sh'  } qw(bash zsh),
> > 
> > Good idea.
> 
> Does ksh, csh can be highlighted as sh too ?
My /etc/highlight/filetypes.conf does include only
  $ext(sh)=bash

All of bash, zsh and ksh are POSIX shell (sh) compatibile, so sh syntax (which is according to my /usr/share/highlight/langDefs/sh.lang file "Bash script language definition file" ;-)) should work. csh IIRC isn't. So therefore I am not sure if csh can be highlighted correctly using sh syntax.

-- 
Jakub Narebski
Poland
Sylvain Rabot· Dec 16, 2010, 21:43 UTC · re: Sylvain Rabot · lore

[PATCH 2/3] gitweb: decorate a bit more remotes

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
---
 gitweb/gitweb.perl |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Show changes to gitweb/gitweb.perl +4 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index db18d06..9398475 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5127,13 +5127,13 @@ sub git_remote_block {
 
 	if (defined $fetch) {
 		if ($fetch eq $push) {
-			$urls_table .= format_repo_url("URL", $fetch);
+			$urls_table .= format_repo_url("<strong>URL:</strong>", $fetch);
 		} else {
-			$urls_table .= format_repo_url("Fetch URL", $fetch);
-			$urls_table .= format_repo_url("Push URL", $push) if defined $push;
+			$urls_table .= format_repo_url("<strong>Fetch URL:</strong>", $fetch);
+			$urls_table .= format_repo_url("<strong>Push URL:</strong>", $push) if defined $push;
 		}
 	} elsif (defined $push) {
-		$urls_table .= format_repo_url("Push URL", $push);
+		$urls_table .= format_repo_url("<strong>Push URL:</strong>", $push);
 	} else {
 		$urls_table .= format_repo_url("", "No remote URL");
 	}
-- 
1.7.3.2
Jakub Narebski· Dec 16, 2010, 22:23 UTC · re: Sylvain Rabot · lore

Re: [PATCH 2/3] gitweb: decorate a bit more remotes

Sylvain Rabot <sylvain@abstraction.fr> writes:
Show 15 quoted lines
> Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> ---
>  gitweb/gitweb.perl |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index db18d06..9398475 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -5127,13 +5127,13 @@ sub git_remote_block {
>  
>  	if (defined $fetch) {
>  		if ($fetch eq $push) {
> -			$urls_table .= format_repo_url("URL", $fetch);
> +			$urls_table .= format_repo_url("<strong>URL:</strong>", $fetch);
I would really prefer to use CSS for that...
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Drew Northup· Dec 20, 2010, 12:04 UTC · re: Jakub Narebski · lore

Re: [PATCH 2/3] gitweb: decorate a bit more remotes

On Thu, 2010-12-16 at 14:23 -0800, Jakub Narebski wrote:
Show 19 quoted lines
> Sylvain Rabot <sylvain@abstraction.fr> writes:
> 
> > Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> > ---
> >  gitweb/gitweb.perl |    8 ++++----
> >  1 files changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> > index db18d06..9398475 100755
> > --- a/gitweb/gitweb.perl
> > +++ b/gitweb/gitweb.perl
> > @@ -5127,13 +5127,13 @@ sub git_remote_block {
> >  
> >  	if (defined $fetch) {
> >  		if ($fetch eq $push) {
> > -			$urls_table .= format_repo_url("URL", $fetch);
> > +			$urls_table .= format_repo_url("<strong>URL:</strong>", $fetch);
> 
> I would really prefer to use CSS for that...

Agreed; <span class="repo_url">URL:</span> is far more appropriate in my opinion.

-- 
-Drew Northup N1XIM
   AKA RvnPhnx on OPN
________________________________________________
"As opposed to vegetable or mineral error?"
-John Pescatore, SANS NewsBites Vol. 12 Num. 59
Sylvain Rabot· Dec 16, 2010, 21:43 UTC · re: Sylvain Rabot · lore

[PATCH 3/3] gitweb: remove test when closing file descriptor

it happens that closing file descriptor fails whereas the blob is perfectly readable.

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
---
 gitweb/gitweb.perl |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
Show changes to gitweb/gitweb.perl +1 −2
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9398475..9a885b1 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3450,8 +3450,7 @@ sub run_highlighter {
 	my ($fd, $highlight, $syntax) = @_;
 	return $fd unless ($highlight && defined $syntax);
 
-	close $fd
-		or die_error(404, "Reading blob failed");
+	close $fd;
 	open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
 	          quote_command($highlight_bin).
 	          " --xhtml --fragment --syntax $syntax |"
-- 
1.7.3.2
Jakub Narebski· Dec 16, 2010, 22:30 UTC · re: Sylvain Rabot · lore

Re: [PATCH 3/3] gitweb: remove test when closing file descriptor

Sylvain Rabot <sylvain@abstraction.fr> writes:
Show 19 quoted lines
> it happens that closing file descriptor fails whereas
> the blob is perfectly readable.
> 
> Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> ---
>  gitweb/gitweb.perl |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 9398475..9a885b1 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -3450,8 +3450,7 @@ sub run_highlighter {
>  	my ($fd, $highlight, $syntax) = @_;
>  	return $fd unless ($highlight && defined $syntax);
>  
> -	close $fd
> -		or die_error(404, "Reading blob failed");
> +	close $fd;

Actually what I think happens is the following. "close $fh" cannot usually fail, unless (`perldoc -f close`):

   If the file handle came from a piped open, "close" will additionally
   return false if one of the other system calls involved fails, or if the
   program exits with non-zero status.  (If the only problem was that the
   program exited non-zero, $! will be set to 0.)  Closing a pipe also waits
   for the process executing on the pipe to complete, in case you want to
   look at the output of the pipe afterwards, and implicitly puts the exit
   status value of that command into $?.
   Prematurely closing the read end of a pipe (i.e. before the process writ-
   ing to it at the other end has closed it) will result in a SIGPIPE being
   delivered to the writer.  If the other end can't handle that, be sure to
   read all the data before closing the pipe.

In this place we close read end of pipe after at most reading a few bytes (what -T test does), so what might happen is that writer got SIGPIPE and "failed". But we are not interested in this, so we can safely ignore return from 'close'.

I think that some from above explanation should make it to commit message.

>  	open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
>  	          quote_command($highlight_bin).
>  	          " --xhtml --fragment --syntax $syntax |"

P.S. A better solution would be to redirect opened $fd to highlighter, instead of closing and reopening a pipe... but I'm not sure how it could be implemented.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Sylvain Rabot· Dec 16, 2010, 22:37 UTC · re: Jakub Narebski · lore

Re: [PATCH 3/3] gitweb: remove test when closing file descriptor

On Thu, 2010-12-16 at 14:30 -0800, Jakub Narebski wrote:
Show 45 quoted lines
> Sylvain Rabot <sylvain@abstraction.fr> writes:
> 
> > it happens that closing file descriptor fails whereas
> > the blob is perfectly readable.
> > 
> > Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> > ---
> >  gitweb/gitweb.perl |    3 +--
> >  1 files changed, 1 insertions(+), 2 deletions(-)
> > 
> > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> > index 9398475..9a885b1 100755
> > --- a/gitweb/gitweb.perl
> > +++ b/gitweb/gitweb.perl
> > @@ -3450,8 +3450,7 @@ sub run_highlighter {
> >  	my ($fd, $highlight, $syntax) = @_;
> >  	return $fd unless ($highlight && defined $syntax);
> >  
> > -	close $fd
> > -		or die_error(404, "Reading blob failed");
> > +	close $fd;
> 
> Actually what I think happens is the following.  "close $fh" cannot
> usually fail, unless (`perldoc -f close`):
> 
>    If the file handle came from a piped open, "close" will additionally
>    return false if one of the other system calls involved fails, or if the
>    program exits with non-zero status.  (If the only problem was that the
>    program exited non-zero, $! will be set to 0.)  Closing a pipe also waits
>    for the process executing on the pipe to complete, in case you want to
>    look at the output of the pipe afterwards, and implicitly puts the exit
>    status value of that command into $?.
> 
>    Prematurely closing the read end of a pipe (i.e. before the process writ-
>    ing to it at the other end has closed it) will result in a SIGPIPE being
>    delivered to the writer.  If the other end can't handle that, be sure to
>    read all the data before closing the pipe.
> 
> In this place we close read end of pipe after at most reading a few
> bytes (what -T test does), so what might happen is that writer got
> SIGPIPE and "failed".  But we are not interested in this, so we can
> safely ignore return from 'close'.
> 
> I think that some from above explanation should make it to commit
> message.

Thanks for explaining it, I did not have any idea why it was failing. Can I use your explanation as commit message ?

Show 8 quoted lines
> 
> >  	open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
> >  	          quote_command($highlight_bin).
> >  	          " --xhtml --fragment --syntax $syntax |"
> 
> P.S. A better solution would be to redirect opened $fd to highlighter,
> instead of closing and reopening a pipe... but I'm not sure how it
> could be implemented.
I don't know either.
> 
-- 
Sylvain Rabot <sylvain@abstraction.fr>
Jakub Narebski· Nov 16, 2010, 23:02 UTC · re: Sylvain Rabot · lore

Re: [PATCH 3/3] gitweb: remove test when closing file descriptor

On Thu, 16 Dec 2010, Sylvain Rabot wrote:
Show 8 quoted lines
> On Thu, 2010-12-16 at 14:30 -0800, Jakub Narebski wrote:
> > Sylvain Rabot <sylvain@abstraction.fr> writes:
> > 
> > > it happens that closing file descriptor fails whereas
> > > the blob is perfectly readable.
> > > 
> > > Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
> > > ---
[...]
> > > -	close $fd
> > > -		or die_error(404, "Reading blob failed");
> > > +	close $fd;
[...]
Show 10 quoted lines
> > In this place we close read end of pipe after at most reading a few
> > bytes (what -T test does), so what might happen is that writer got
> > SIGPIPE and "failed".  But we are not interested in this, so we can
> > safely ignore return from 'close'.
> > 
> > I think that some from above explanation should make it to commit
> > message.
> 
> Thanks for explaining it, I did not have any idea why it was failing.
> Can I use your explanation as commit message ?
Of course.
Though I am not sure if it is really the reason, it looks reasonable.
-- 
Jakub Narebski
Poland

← back to recent threads