threads / patch / 26111

patch, 3 partsgitweb: add extensions to highlight feature

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

## tl;dr

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

replies: 6people: 3as markdown or json

Sylvain Rabot· Dec 20, 2010, 19:01 UTC · lore

[PATCH 0/3 v2] minor gitweb modifications

here a three patch serie with minor updates for gitweb based on master.
This serie has been improved regarding the comments of Jakub Narebski <jnareb@gmail.com>
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 +++++++++---------
 gitweb/static/gitweb.css |    4 ++++
 2 files changed, 13 insertions(+), 9 deletions(-)
-- 
1.7.3.4.523.g72f0d.dirty
Sylvain Rabot· Dec 20, 2010, 19:01 UTC · re: Sylvain Rabot · lore
added: sql, php5, phps, bash, zsh, ksh, mk, make
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..a37094e 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 sh pl js tex bib xml awk bat ini spec tcl sql make),
 	# alternate extensions, see /etc/highlight/filetypes.conf
 	'h' => 'c',
+	map { $_ => 'sh'  } qw(bash zsh ksh),
 	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.4.523.g72f0d.dirty
Sylvain Rabot· Dec 20, 2010, 19:01 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 ++++----
 gitweb/static/gitweb.css |    4 ++++
 2 files changed, 8 insertions(+), 4 deletions(-)
Show changes to 2 files +8 −4

gitweb/gitweb.perl, gitweb/static/gitweb.css

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a37094e..c460f27 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("<span class=\"bold\">URL:</span>", $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("<span class=\"bold\">Fetch URL:</span>", $fetch);
+			$urls_table .= format_repo_url("<span class=\"bold\">Push URL:</span>", $push) if defined $push;
 		}
 	} elsif (defined $push) {
-		$urls_table .= format_repo_url("Push URL", $push);
+		$urls_table .= format_repo_url("<span class=\"bold\">Push URL:</span>", $push);
 	} else {
 		$urls_table .= format_repo_url("", "No remote URL");
 	}
diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
index 79d7eeb..ce902f5 100644
--- a/gitweb/static/gitweb.css
+++ b/gitweb/static/gitweb.css
@@ -579,6 +579,10 @@ div.remote {
 	display: inline-block;
 }
 
+.bold {
+	font-weight: bold;
+}
+
 /* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */
 
 /* Highlighting theme definition: */
-- 
1.7.3.4.523.g72f0d.dirty
Jonathan Nieder· Dec 20, 2010, 20:02 UTC · re: Sylvain Rabot · lore

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

Sylvain Rabot wrote:
Show 13 quoted lines
> --- 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("<span class=\"bold\">URL:</span>", $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("<span class=\"bold\">Fetch URL:</span>", $fetch);
> +			$urls_table .= format_repo_url("<span class=\"bold\">Push URL:</span>", $push) if defined $push;

This makes the formatting of the remote URLs table inconsistent with the other projects_list table (namely the

	description	...
	homepage URL	...
	repository URL	...
	owner	...
	last change	...

table on a repository's summary page). Is that the right thing to do?

If so, maybe something like the following would make sense.
-- 8< --
From: Sylvain Rabot <sylvain@abstraction.fr>
Date: Mon, 20 Dec 2010 20:01:20 +0100
Subject: gitweb: decorate a bit more remotes

Put the text "URL" introducing a remote's url in bold and follow it with a colon. This makes the url list easier to visually scan.

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
The justification above is totally made up; I have not checked to
see whether it makes the table easier or harder to read.  Also:
untested.
Maybe the $url part should be esc_url($url)?
 gitweb/gitweb.perl       |   16 ++++++++++------
 gitweb/static/gitweb.css |   13 +++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
Show changes to 2 files +23 −6

gitweb/gitweb.perl, gitweb/static/gitweb.css

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d521c93..b870b56 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3862,7 +3862,11 @@ sub git_print_header_div {
 
 sub format_repo_url {
 	my ($name, $url) = @_;
-	return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
+	my $row = "<tr class=\"metadata_url\">";
+	$row .= ($name eq "" ? "<td></td>" : "<td class=\"metadata_tag\">$name</td>");
+	$row .= "<td>$url</td>";
+	$row .= "</tr>\n";
+	return $row;
 }
 
 # Group output by placing it in a DIV element and adding a header.
@@ -5122,7 +5126,7 @@ sub git_remote_block {
 	my $fetch = $rdata->{'fetch'};
 	my $push = $rdata->{'push'};
 
-	my $urls_table = "<table class=\"projects_list\">\n" ;
+	my $urls_table = "<table class=\"remote_urls\">\n" ;
 
 	if (defined $fetch) {
 		if ($fetch eq $push) {
@@ -5368,10 +5372,10 @@ sub git_summary {
 
 	print "<div class=\"title\">&nbsp;</div>\n";
 	print "<table class=\"projects_list\">\n" .
-	      "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
-	      "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
+	      "<tr id=\"metadata_desc\"><td class=\"metadata_tag\">description</td><td>" . esc_html($descr) . "</td></tr>\n" .
+	      "<tr id=\"metadata_owner\"><td class=\"metadata_tag\">owner</td><td>" . esc_html($owner) . "</td></tr>\n";
 	if (defined $cd{'rfc2822'}) {
-		print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+		print "<tr id=\"metadata_lchange\"><td class=\"metadata_tag\">last change</td><td>$cd{'rfc2822'}</td></tr>\n";
 	}
 
 	# use per project git URL list in $projectroot/$project/cloneurl
@@ -5390,7 +5394,7 @@ sub git_summary {
 	if ($show_ctags) {
 		my $ctags = git_get_project_ctags($project);
 		my $cloud = git_populate_project_tagcloud($ctags);
-		print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
+		print "<tr id=\"metadata_ctags\"><td class=\"metadata_tag\">Content tags:<br />";
 		print "</td>\n<td>" unless %$ctags;
 		print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
 		print "</td>\n<td>" if %$ctags;
diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
index 79d7eeb..feb09e5 100644
--- a/gitweb/static/gitweb.css
+++ b/gitweb/static/gitweb.css
@@ -579,6 +579,19 @@ div.remote {
 	display: inline-block;
 }
 
+/*
+ * <b>URL:</b>	http://www.example.com/
+ * <b>Fetch URL:</b>	http://www.example.com/
+ * <b>Push URL:</b>	http://www.example.com/
+ */
+table.remote_urls tr.metadata_url td.metadata_tag:after {
+	content: ":"
+}
+
+table.remote_urls tr.metadata_url td.metadata_tag {
+	font-weight: bold;
+}
+
 /* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */
 
 /* Highlighting theme definition: */
-- 
1.7.2.3.554.gc9b5c.dirty
Jakub Narebski· Dec 20, 2010, 23:06 UTC · re: Jonathan Nieder · lore

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

On Mon, 20 Dec 2010, Jonathan Nieder wrote:
Show 16 quoted lines
> diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
> index 79d7eeb..feb09e5 100644
> --- a/gitweb/static/gitweb.css
> +++ b/gitweb/static/gitweb.css
> @@ -579,6 +579,19 @@ div.remote {
>         display: inline-block;
>  }
>  
> +/*
> + * <b>URL:</b> http://www.example.com/
> + * <b>Fetch URL:</b>   http://www.example.com/
> + * <b>Push URL:</b>    http://www.example.com/
> + */
> +table.remote_urls tr.metadata_url td.metadata_tag:after {
> +       content: ":"
> +}

I'd rather not use 'content' (pseudo-)property, as not all web browsers implement it,... unless of course not having it doesn't make view worse.

-- 
Jakub Narebski
Poland
Jakub Narebski· Dec 20, 2010, 23:11 UTC · re: Sylvain Rabot · lore

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

Sylvain Rabot <sylvain@abstraction.fr> writes:
> -			$urls_table .= format_repo_url("URL", $fetch);
> +			$urls_table .= format_repo_url("<span class=\"bold\">URL:</span>", $fetch);
[...]
Show 11 quoted lines
> diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
> index 79d7eeb..ce902f5 100644
> --- a/gitweb/static/gitweb.css
> +++ b/gitweb/static/gitweb.css
> @@ -579,6 +579,10 @@ div.remote {
>  	display: inline-block;
>  }
>  
> +.bold {
> +	font-weight: bold;
> +}

<span class="bold"> is not much different from <strong> or <b>; I'd rather you use some semantic name for the class, describing what content it contains rather than what style it uses.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Sylvain Rabot· Dec 20, 2010, 19:01 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. According to perlman the reasons could be:

   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 case we don't mind that close fails.
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 c460f27..8f0d00e 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.4.523.g72f0d.dirty

← back to recent threads