From 391862e34571c0e7e88a5f6e84211b7b8bf55440 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 25 Nov 2006 09:43:59 +0100 Subject: [PATCH 1/6] gitweb: Do not use esc_html in esc_path Do not use esc_html in esc_path subroutine to avoid double quoting; expand esc_html body (except quoting) in esc_path. Move esc_path before quot_cec and quot_upr. Add some comments. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 6ae7e80351..38c94372f5 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -585,7 +585,21 @@ sub esc_html ($;%) { return $str; } -# Make control characterss "printable". +# quote control characters and escape filename to HTML +sub esc_path { + my $str = shift; + my %opts = @_; + + $str = to_utf8($str); + $str = escapeHTML($str); + if ($opts{'-nbsp'}) { + $str =~ s/ / /g; + } + $str =~ s|([[:cntrl:]])|quot_cec($1)|eg; + return $str; +} + +# Make control characters "printable", using character escape codes (CEC) sub quot_cec { my $cntrl = shift; my %es = ( # character escape codes, aka escape sequences @@ -605,22 +619,14 @@ sub quot_cec { return "$chr"; } -# Alternatively use unicode control pictures codepoints. +# Alternatively use unicode control pictures codepoints, +# Unicode "printable representation" (PR) sub quot_upr { my $cntrl = shift; my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl)); return "$chr"; } -# quote control characters and escape filename to HTML -sub esc_path { - my $str = shift; - - $str = esc_html($str); - $str =~ s|([[:cntrl:]])|quot_cec($1)|eg; - return $str; -} - # git may return quoted and escaped filenames sub unquote { my $str = shift; From 28b9d9f7c67cfd199c4bc9e1ac5197cb17349b15 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 25 Nov 2006 11:32:08 +0100 Subject: [PATCH 2/6] gitweb: Use git-show-ref instead of git-peek-remote Use "git show-ref --dereference" instead of "git peek-remote $projectroot/project" in git_get_references. git-show-ref is faster than git-peek-remote (40ms vs 56ms user+sys for git.git repository); even faster is reading info/refs file (if it exists), but the information in info/refs can be stale; that and the fact that info/refs is meant for dumb protocol transports, not for gitweb. git-show-ref is available since v1.4.4; the output format is slightly different than git-peek-remote output format, but we accept both. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 38c94372f5..26fc3a689d 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1154,14 +1154,15 @@ sub git_get_last_activity { sub git_get_references { my $type = shift || ""; my %refs; - # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 - # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} - open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/" + # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 + # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} + open my $fd, "-|", git_cmd(), "show-ref", "--dereference", + ($type ? ("--", "refs/$type") : ()) # use -- if $type or return; while (my $line = <$fd>) { chomp $line; - if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) { + if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) { if (defined $refs{$1}) { push @{$refs{$1}}, $2; } else { From ba00b8c1edafcc414cfe13f8a4addac3893c2a29 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 25 Nov 2006 15:54:32 +0100 Subject: [PATCH 3/6] gitweb: Add author and committer email extraction to parse_commit Extract author email to 'author_email' key, and comitter mail to 'committer_mail' key; uniquify committer and author lines handling by the way. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 26fc3a689d..85a896b619 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1294,8 +1294,9 @@ sub parse_commit { $co{'author'} = $1; $co{'author_epoch'} = $2; $co{'author_tz'} = $3; - if ($co{'author'} =~ m/^([^<]+) ]*)>/) { + $co{'author_name'} = $1; + $co{'author_email'} = $2; } else { $co{'author_name'} = $co{'author'}; } @@ -1304,7 +1305,12 @@ sub parse_commit { $co{'committer_epoch'} = $2; $co{'committer_tz'} = $3; $co{'committer_name'} = $co{'committer'}; - $co{'committer_name'} =~ s/ <.*//; + if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) { + $co{'committer_name'} = $1; + $co{'committer_email'} = $2; + } else { + $co{'committer_name'} = $co{'committer'}; + } } } if (!defined $co{'tree'}) { From ab23c19d67d283567fdf18966e347a78ade56c22 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 25 Nov 2006 15:54:33 +0100 Subject: [PATCH 4/6] gitweb: Add author and contributor email to Atom feed Add author email (from 'author_email') and contributor email (from 'committer_email') to items in the Atom format gitweb feed. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 85a896b619..fb7026d321 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4323,9 +4323,19 @@ XML print "\n" . "" . esc_html($co{'title'}) . "\n" . "$cd{'iso-8601'}\n" . - "" . esc_html($co{'author_name'}) . "\n" . + "\n" . + " " . esc_html($co{'author_name'}) . "\n"; + if ($co{'author_email'}) { + print " " . esc_html($co{'author_email'}) . "\n"; + } + print "\n" . # use committer for contributor - "" . esc_html($co{'committer_name'}) . "\n" . + "\n" . + " " . esc_html($co{'committer_name'}) . "\n"; + if ($co{'committer_email'}) { + print " " . esc_html($co{'committer_email'}) . "\n"; + } + print "\n" . "$cd{'iso-8601'}\n" . "\n" . "$co_url\n" . From 91fd2bf3fdc72351532a8fd74cdd0da37b036ed1 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 25 Nov 2006 15:54:34 +0100 Subject: [PATCH 5/6] gitweb: Use author_epoch for pubdate in gitweb feeds Use creation date (author_epoch) instead of former commit date (committer_epoch) as publish date in gitweb feeds (RSS, Atom). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index fb7026d321..1c5b85443b 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4201,7 +4201,7 @@ sub git_feed { } if (defined($revlist[0])) { %latest_commit = parse_commit($revlist[0]); - %latest_date = parse_date($latest_commit{'committer_epoch'}); + %latest_date = parse_date($latest_commit{'author_epoch'}); print $cgi->header( -type => $content_type, -charset => 'utf-8', @@ -4294,10 +4294,10 @@ XML my $commit = $revlist[$i]; my %co = parse_commit($commit); # we read 150, we always show 30 and the ones more recent than 48 hours - if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) { + if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) { last; } - my %cd = parse_date($co{'committer_epoch'}); + my %cd = parse_date($co{'author_epoch'}); # get list of changed files open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, From e88ce8a45656f750551ee21abf3be5576f6b0be4 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 26 Nov 2006 02:18:26 +0100 Subject: [PATCH 6/6] gitweb: Make project description in projects list link to summary view Make (shortened) project description in the "projects list" view hyperlink to the "summary" view of the project. Project names are sometimes short; having project description be hyperling gives larger are to click. While at it, display full description on mouseover via 'title' attribute to introduced link. Additionally, fix whitespace usage in modified git_project_list_body subroutine: tabs are for indent, spaces are for align. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 1c5b85443b..093bd72058 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2441,6 +2441,7 @@ sub git_project_list_body { ($pr->{'age'}, $pr->{'age_string'}) = @aa; if (!defined $pr->{'descr'}) { my $descr = git_get_project_description($pr->{'path'}) || ""; + $pr->{'descr_long'} = to_utf8($descr); $pr->{'descr'} = chop_str($descr, 25, 5); } if (!defined $pr->{'owner'}) { @@ -2476,7 +2477,7 @@ sub git_project_list_body { } else { print "" . $cgi->a({-href => href(project=>undef, order=>'project'), - -class => "header"}, "Project") . + -class => "header"}, "Project") . "\n"; } if ($order eq "descr") { @@ -2485,7 +2486,7 @@ sub git_project_list_body { } else { print "" . $cgi->a({-href => href(project=>undef, order=>'descr'), - -class => "header"}, "Description") . + -class => "header"}, "Description") . "\n"; } if ($order eq "owner") { @@ -2494,7 +2495,7 @@ sub git_project_list_body { } else { print "" . $cgi->a({-href => href(project=>undef, order=>'owner'), - -class => "header"}, "Owner") . + -class => "header"}, "Owner") . "\n"; } if ($order eq "age") { @@ -2503,7 +2504,7 @@ sub git_project_list_body { } else { print "" . $cgi->a({-href => href(project=>undef, order=>'age'), - -class => "header"}, "Last Change") . + -class => "header"}, "Last Change") . "\n"; } print "\n" . @@ -2528,7 +2529,9 @@ sub git_project_list_body { } print "" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), -class => "list"}, esc_html($pr->{'path'})) . "\n" . - "" . esc_html($pr->{'descr'}) . "\n" . + "" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), + -class => "list", -title => $pr->{'descr_long'}}, + esc_html($pr->{'descr'})) . "\n" . "" . chop_str($pr->{'owner'}, 15) . "\n"; print "{'age'}) . "\">" . $pr->{'age_string'} . "\n" .