From cdd4037d7053647c97139ac77d4319124f17d47e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 30 Jun 2006 18:54:32 -0700 Subject: gitweb: optimize per-file history generation The rev-list command that is recent enough can filter commits based on paths they touch, so use it instead of generating the full list and limiting it by passing it with diff-tree --stdin. [jc: The patch originally came from Luben Tuikov but the it was corrupt, but it was short enough to be applied by hand. I added the --full-history to make the output compatible with the original while doing so.] Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 035e76d0a3..1007742153 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -2295,16 +2295,13 @@ sub git_history { "\n"; print "
/" . esc_html($file_name) . "
\n"; - open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'"; - my $commit; + open my $fd, "-|", + "$gitbin/git-rev-list --full-history $hash -- \'$file_name\'"; print "\n"; my $alternate = 0; while (my $line = <$fd>) { if ($line =~ m/^([0-9a-fA-F]{40})/){ - $commit = $1; - next; - } - if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) { + my $commit = $1; my %co = git_read_commit($commit); if (!%co) { next; @@ -2336,7 +2333,6 @@ sub git_history { } print "\n" . "\n"; - undef $commit; } } print "
\n"; -- cgit v1.2.3 From 85b7cfb1036b4218d13cbc215729ad083a61a0ea Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Fri, 30 Jun 2006 19:11:18 -0700 Subject: gitweb: Enable tree (directory) history display This patch allows history display of whole trees/directories a la "git-rev-list HEAD -- ". I find this useful especially when a project lives in its own subdirectory, as opposed to being all of the GIT repository (i.e. when a sub-project is merged into a super-project). Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 1 + 1 file changed, 1 insertion(+) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 1007742153..efffc8d078 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1676,6 +1676,7 @@ sub git_tree { "\n" . "" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . "\n"; } print "\n"; -- cgit v1.2.3 From 4a87b43e374626a95c14362f21c9ca1023638a2c Mon Sep 17 00:00:00 2001 From: Dennis Stosberg Date: Wed, 21 Jun 2006 15:07:08 +0200 Subject: gitweb: Declare global variables with "our" Variables declared with "my" in the file scope cannot be accessed from subroutines with mod_perl. Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index efffc8d078..3e2790c5d6 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -16,21 +16,21 @@ use Encode; use Fcntl ':mode'; binmode STDOUT, ':utf8'; -my $cgi = new CGI; -my $version = "267"; -my $my_url = $cgi->url(); -my $my_uri = $cgi->url(-absolute => 1); -my $rss_link = ""; +our $cgi = new CGI; +our $version = "267"; +our $my_url = $cgi->url(); +our $my_uri = $cgi->url(-absolute => 1); +our $rss_link = ""; # location of the git-core binaries -my $gitbin = "/usr/bin"; +our $gitbin = "/usr/bin"; # absolute fs-path which will be prepended to the project path -#my $projectroot = "/pub/scm"; -my $projectroot = "/home/kay/public_html/pub/scm"; +#our $projectroot = "/pub/scm"; +our $projectroot = "/home/kay/public_html/pub/scm"; # version of the git-core binaries -my $git_version = qx($gitbin/git --version); +our $git_version = qx($gitbin/git --version); if ($git_version =~ m/git version (.*)$/) { $git_version = $1; } else { @@ -38,32 +38,31 @@ if ($git_version =~ m/git version (.*)$/) { } # location for temporary files needed for diffs -my $git_temp = "/tmp/gitweb"; +our $git_temp = "/tmp/gitweb"; # target of the home link on top of all pages -my $home_link = $my_uri; +our $home_link = $my_uri; # html text to include at home page -my $home_text = "indextext.html"; +our $home_text = "indextext.html"; # URI of default stylesheet -my $stylesheet = "gitweb.css"; +our $stylesheet = "gitweb.css"; # source of projects list -#my $projects_list = $projectroot; -my $projects_list = "index/index.aux"; +#our $projects_list = $projectroot; +our $projects_list = "index/index.aux"; # default blob_plain mimetype and default charset for text/plain blob -my $default_blob_plain_mimetype = 'text/plain'; -my $default_text_plain_charset = undef; +our $default_blob_plain_mimetype = 'text/plain'; +our $default_text_plain_charset = undef; # file to use for guessing MIME types before trying /etc/mime.types # (relative to the current git repository) -my $mimetypes_file = undef; - +our $mimetypes_file = undef; # input validation and dispatch -my $action = $cgi->param('a'); +our $action = $cgi->param('a'); if (defined $action) { if ($action =~ m/[^0-9a-zA-Z\.\-_]/) { undef $action; @@ -78,7 +77,7 @@ if (defined $action) { } } -my $order = $cgi->param('o'); +our $order = $cgi->param('o'); if (defined $order) { if ($order =~ m/[^0-9a-zA-Z_]/) { undef $order; @@ -86,7 +85,7 @@ if (defined $order) { } } -my $project = ($cgi->param('p') || $ENV{'PATH_INFO'}); +our $project = ($cgi->param('p') || $ENV{'PATH_INFO'}); if (defined $project) { $project =~ s|^/||; $project =~ s|/$||; $project = validate_input($project); @@ -109,7 +108,7 @@ if (defined $project) { exit; } -my $file_name = $cgi->param('f'); +our $file_name = $cgi->param('f'); if (defined $file_name) { $file_name = validate_input($file_name); if (!defined($file_name)) { @@ -117,7 +116,7 @@ if (defined $file_name) { } } -my $hash = $cgi->param('h'); +our $hash = $cgi->param('h'); if (defined $hash) { $hash = validate_input($hash); if (!defined($hash)) { @@ -125,7 +124,7 @@ if (defined $hash) { } } -my $hash_parent = $cgi->param('hp'); +our $hash_parent = $cgi->param('hp'); if (defined $hash_parent) { $hash_parent = validate_input($hash_parent); if (!defined($hash_parent)) { @@ -133,7 +132,7 @@ if (defined $hash_parent) { } } -my $hash_base = $cgi->param('hb'); +our $hash_base = $cgi->param('hb'); if (defined $hash_base) { $hash_base = validate_input($hash_base); if (!defined($hash_base)) { @@ -141,7 +140,7 @@ if (defined $hash_base) { } } -my $page = $cgi->param('pg'); +our $page = $cgi->param('pg'); if (defined $page) { if ($page =~ m/[^0-9]$/) { undef $page; @@ -149,7 +148,7 @@ if (defined $page) { } } -my $searchtext = $cgi->param('s'); +our $searchtext = $cgi->param('s'); if (defined $searchtext) { if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) { undef $searchtext; -- cgit v1.2.3 From 25b7c18ecd9779158cb1c02572396bab22c6e0cf Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Thu, 6 Jul 2006 23:39:30 -0700 Subject: Add "raw" output option to blobs in "tree" view format Add a "raw" output option to blobs in "tree" view format, so that the user doesn't have to click on "blob", wait for the (binary) file to be uploaded and shown in "blob" mode, and then click on "plain" to download the (binary) file. This is useful when the file is clearly binary and we don't want the browser to upload and display it in "blob" mode, but we just want to download it. Case in point: pdf files, wlg. Note: the "raw" format is equivalent to the blob->plain view, not blob->head view. I.e. the view has the hash of the file as listed by git-ls-tree, not just "HEAD". Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 1 + 1 file changed, 1 insertion(+) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 3e2790c5d6..cce0753e14 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1668,6 +1668,7 @@ sub git_tree { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") . # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") . "\n"; } elsif ($t_type eq "tree") { print "" . -- cgit v1.2.3 From 9af25117963382b5f4c342bc9dbae7b4e60c4a11 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 9 Jul 2006 20:07:27 -0700 Subject: gitweb.cgi: Create $git_temp if it doesn't exist Unless we'd done diffs, $git_temp doesn't exist and then mime lookups fail. Explicitly create it, if it doesn't exist already. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index cce0753e14..2fb2809fbb 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -39,6 +39,9 @@ if ($git_version =~ m/git version (.*)$/) { # location for temporary files needed for diffs our $git_temp = "/tmp/gitweb"; +if (! -d $git_temp) { + mkdir($git_temp, 0700) || die_error("Couldn't mkdir $git_temp"); +} # target of the home link on top of all pages our $home_link = $my_uri; -- cgit v1.2.3 From 930cf7dd7cc6b87d173f182230763e1f1913d319 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 9 Jul 2006 20:18:57 -0700 Subject: gitweb.cgi: Teach "a=blob" action to know the blob/file mime type Now action "blob" knows the file type: if the file type is not "text/*" then action "blob" defaults to "blob_plain", i.e. the file is downloaded raw for the browser to interpret. If the file type is "text/*", then "blob" defaults to the current "cat -n"-like output, from which you can click "plain", to get the "blob_plain" output. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 127 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 67 insertions(+), 60 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2fb2809fbb..2e87de4769 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1458,61 +1458,6 @@ sub git_get_hash_by_path { } } -sub git_blob { - if (!defined $hash && defined $file_name) { - my $base = $hash_base || git_read_head($project); - $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); - } - my $have_blame = git_get_project_config_bool ('blame'); - open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed."); - git_header_html(); - if (defined $hash_base && (my %co = git_read_commit($hash_base))) { - print "
\n" . - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "
\n"; - if (defined $file_name) { - if ($have_blame) { - print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | "; - } - print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "
\n"; - } else { - print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "
\n"; - } - print "
\n". - "
" . - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . - "
\n"; - } else { - print "
\n" . - "

\n" . - "
$hash
\n"; - } - if (defined $file_name) { - print "
" . esc_html($file_name) . "
\n"; - } - print "
\n"; - my $nr; - while (my $line = <$fd>) { - chomp $line; - $nr++; - while ((my $pos = index($line, "\t")) != -1) { - if (my $count = (8 - ($pos % 8))) { - my $spaces = ' ' x $count; - $line =~ s/\t/$spaces/; - } - } - printf "
%4i %s
\n", $nr, $nr, $nr, esc_html($line); - } - close $fd or print "Reading blob failed.\n"; - print "
"; - git_footer_html(); -} - sub mimetype_guess_file { my $filename = shift; my $mimemap = shift; @@ -1551,14 +1496,14 @@ sub git_blob_plain_mimetype { my $fd = shift; my $filename = shift; - # just in case - return $default_blob_plain_mimetype unless $fd; - if ($filename) { my $mime = mimetype_guess($filename); $mime and return $mime; } + # just in case + return $default_blob_plain_mimetype unless $fd; + if (-T $fd) { return 'text/plain' . ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : ''); @@ -1576,8 +1521,10 @@ sub git_blob_plain_mimetype { } sub git_blob_plain { - open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return; - my $type = git_blob_plain_mimetype($fd, $file_name); + my $type = shift; + open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash"); + + $type ||= git_blob_plain_mimetype($fd, $file_name); # save as filename, even when no $file_name is given my $save_as = "$hash"; @@ -1596,6 +1543,66 @@ sub git_blob_plain { close $fd; } +sub git_blob { + if (!defined $hash && defined $file_name) { + my $base = $hash_base || git_read_head($project); + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); + } + my $have_blame = git_get_project_config_bool ('blame'); + open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed."); + my $mimetype = git_blob_plain_mimetype($fd, $file_name); + if ($mimetype !~ m/^text\//) { + close $fd; + return git_blob_plain($mimetype); + } + git_header_html(); + if (defined $hash_base && (my %co = git_read_commit($hash_base))) { + print "
\n" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "
\n"; + if (defined $file_name) { + if ($have_blame) { + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | "; + } + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "
\n"; + } else { + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "
\n"; + } + print "
\n". + "
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . + "
\n"; + } else { + print "
\n" . + "

\n" . + "
$hash
\n"; + } + if (defined $file_name) { + print "
" . esc_html($file_name) . "
\n"; + } + print "
\n"; + my $nr; + while (my $line = <$fd>) { + chomp $line; + $nr++; + while ((my $pos = index($line, "\t")) != -1) { + if (my $count = (8 - ($pos % 8))) { + my $spaces = ' ' x $count; + $line =~ s/\t/$spaces/; + } + } + printf "
%4i %s
\n", $nr, $nr, $nr, esc_html($line); + } + close $fd or print "Reading blob failed.\n"; + print "
"; + git_footer_html(); +} + sub git_tree { if (!defined $hash) { $hash = git_read_head($project); -- cgit v1.2.3 From f6801d669ee11f0d5e67b2e86aec270d2a225224 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Tue, 11 Jul 2006 11:19:34 +0100 Subject: gitweb: Send XHTML as 'application/xhtml+xml' where possible "The 'text/html' media type [RFC2854] is primarily for HTML, not for XHTML. In general, this media type is NOT suitable for XHTML." This patch makes gitweb use content negotiation to conservatively send pages as Content-Type 'application/xhtml+xml' when the user agent explicitly claims to support it. It falls back to 'text/html' even if the user agent appears to implicitly support 'application/xhtml+xml' due to a '*/*' glob, working around an insidious bug in Internet Explorer where sending the correct media type prevents the page from being displayed. Signed-off-by: Alp Toker Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2e87de4769..bd9b9de88c 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -293,7 +293,17 @@ sub git_header_html { } } } - print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires); + my $content_type; + # require explicit support from the UA if we are to send the page as + # 'application/xhtml+xml', otherwise send it as plain old 'text/html'. + # we have to do this because MSIE sometimes globs '*/*', pretending to + # support xhtml+xml but choking when it gets what it asked for. + if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') != 0) { + $content_type = 'application/xhtml+xml'; + } else { + $content_type = 'text/html'; + } + print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires); print < @@ -301,7 +311,7 @@ sub git_header_html { - + $title -- cgit v1.2.3 From 49da1dafc075e353c0eb3869de4acf600c594621 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Tue, 11 Jul 2006 21:10:26 +0100 Subject: gitweb: Include a site name in page titles This helps users tell one 'git' bookmark apart from the other in their browser and improves the indexing of gitweb sites in Web search engines. The title defaults to the SERVER_NAME environment variable, often given by the webserver. Signed-off-by: Alp Toker Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index bd9b9de88c..3d9fa4456e 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -46,6 +46,10 @@ if (! -d $git_temp) { # target of the home link on top of all pages our $home_link = $my_uri; +# name of your site or organization to appear in page titles +# replace this with something more descriptive for clearer bookmarks +our $site_name = $ENV{'SERVER_NAME'} || "Untitled"; + # html text to include at home page our $home_text = "indextext.html"; @@ -280,7 +284,7 @@ sub git_header_html { my $status = shift || "200 OK"; my $expires = shift; - my $title = "git"; + my $title = "$site_name git"; if (defined $project) { $title .= " - $project"; if (defined $action) { @@ -1770,7 +1774,7 @@ sub git_opml { print "\n". "\n". "". - " Git OPML Export\n". + " $site_name Git OPML Export\n". "\n". "\n". "\n"; -- cgit v1.2.3 From e130ddaaf3451d0bd60860cb0019e47c9f421442 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Wed, 12 Jul 2006 23:55:10 +0100 Subject: gitweb: Make command invocations go through the git wrapper This patch makes invocations of core git commands go through the 'git' binary itself, which improves readability and might help system administrators lock down their CGI environment for security. Signed-off-by: Alp Toker Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 62 ++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 3d9fa4456e..2fd1e5f78e 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -22,20 +22,16 @@ our $my_url = $cgi->url(); our $my_uri = $cgi->url(-absolute => 1); our $rss_link = ""; -# location of the git-core binaries -our $gitbin = "/usr/bin"; +# core git executable to use +# this can just be "git" if your webserver has a sensible PATH +our $GIT = "/usr/bin/git"; # absolute fs-path which will be prepended to the project path #our $projectroot = "/pub/scm"; our $projectroot = "/home/kay/public_html/pub/scm"; -# version of the git-core binaries -our $git_version = qx($gitbin/git --version); -if ($git_version =~ m/git version (.*)$/) { - $git_version = $1; -} else { - $git_version = "unknown"; -} +# version of the core git binary +our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown"; # location for temporary files needed for diffs our $git_temp = "/tmp/gitweb"; @@ -392,7 +388,7 @@ sub die_error { sub git_get_type { my $hash = shift; - open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return; + open my $fd, "-|", "$GIT cat-file -t $hash" or return; my $type = <$fd>; close $fd or return; chomp $type; @@ -404,7 +400,7 @@ sub git_read_head { my $oENV = $ENV{'GIT_DIR'}; my $retval = undef; $ENV{'GIT_DIR'} = "$projectroot/$project"; - if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") { + if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") { my $head = <$fd>; close $fd; if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) { @@ -444,7 +440,7 @@ sub git_read_tag { my %tag; my @comment; - open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return; + open my $fd, "-|", "$GIT cat-file tag $tag_id" or return; $tag{'id'} = $tag_id; while (my $line = <$fd>) { chomp $line; @@ -516,7 +512,7 @@ sub git_read_commit { @commit_lines = @$commit_text; } else { $/ = "\0"; - open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return; + open my $fd, "-|", "$GIT rev-list --header --parents --max-count=1 $commit_id" or return; @commit_lines = split '\n', <$fd>; close $fd or return; $/ = "\n"; @@ -614,7 +610,7 @@ sub git_diff_print { if (defined $from) { $from_tmp = "$git_temp/gitweb_" . $$ . "_from"; open my $fd2, "> $from_tmp"; - open my $fd, "-|", "$gitbin/git-cat-file blob $from"; + open my $fd, "-|", "$GIT cat-file blob $from"; my @file = <$fd>; print $fd2 @file; close $fd2; @@ -625,7 +621,7 @@ sub git_diff_print { if (defined $to) { $to_tmp = "$git_temp/gitweb_" . $$ . "_to"; open my $fd2, "> $to_tmp"; - open my $fd, "-|", "$gitbin/git-cat-file blob $to"; + open my $fd, "-|", "$GIT cat-file blob $to"; my @file = <$fd>; print $fd2 @file; close $fd2; @@ -844,7 +840,7 @@ sub git_get_project_config { $key =~ s/^gitweb\.//; return if ($key =~ m/\W/); - my $val = qx($gitbin/git-repo-config --get gitweb.$key); + my $val = qx($GIT repo-config --get gitweb.$key); return ($val); } @@ -1066,7 +1062,7 @@ sub git_summary { "owner$owner\n" . "last change$cd{'rfc2822'}\n" . "\n"; - open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed."); my (@revlist) = map { chomp; $_ } <$fd>; close $fd; print "
\n" . @@ -1254,7 +1250,7 @@ sub git_blame { $hash = git_get_hash_by_path($hash_base, $file_name, "blob") or die_error(undef, "Error lookup file."); } - open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base) + open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base) or die_error(undef, "Open failed."); git_header_html(); print "
\n" . @@ -1449,7 +1445,7 @@ sub git_get_hash_by_path { my $tree = $base; my @parts = split '/', $path; while (my $part = shift @parts) { - open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed."); + open my $fd, "-|", "$GIT ls-tree $tree" or die_error(undef, "Open git-ls-tree failed."); my (@entries) = map { chomp; $_ } <$fd>; close $fd or return undef; foreach my $line (@entries) { @@ -1536,7 +1532,7 @@ sub git_blob_plain_mimetype { sub git_blob_plain { my $type = shift; - open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash"); + open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash"); $type ||= git_blob_plain_mimetype($fd, $file_name); @@ -1563,7 +1559,7 @@ sub git_blob { $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); } my $have_blame = git_get_project_config_bool ('blame'); - open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed."); my $mimetype = git_blob_plain_mimetype($fd, $file_name); if ($mimetype !~ m/^text\//) { close $fd; @@ -1629,7 +1625,7 @@ sub git_tree { } } $/ = "\0"; - open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed."); + open my $fd, "-|", "$GIT ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed."); chomp (my (@entries) = <$fd>); close $fd or die_error(undef, "Reading tree failed."); $/ = "\n"; @@ -1712,7 +1708,7 @@ sub git_tree { sub git_rss { # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ - open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed."); my (@revlist) = map { chomp; $_ } <$fd>; close $fd or die_error(undef, "Reading rev-list failed."); print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); @@ -1732,7 +1728,7 @@ sub git_rss { last; } my %cd = date_str($co{'committer_epoch'}); - open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next; + open $fd, "-|", "$GIT diff-tree -r $co{'parent'} $co{'id'}" or next; my @difftree = map { chomp; $_ } <$fd>; close $fd or next; print "\n" . @@ -1820,7 +1816,7 @@ sub git_log { " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "
\n"; my $limit = sprintf("--max-count=%i", (100 * ($page+1))); - open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed."); my (@revlist) = map { chomp; $_ } <$fd>; close $fd; @@ -1911,7 +1907,7 @@ sub git_commit { $root = " --root"; $parent = ""; } - open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed."); @difftree = map { chomp; $_ } <$fd>; close $fd or die_error(undef, "Reading diff-tree failed."); @@ -2153,7 +2149,7 @@ sub git_commitdiff { if (!defined $hash_parent) { $hash_parent = $co{'parent'}; } - open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed."); my (@difftree) = map { chomp; $_ } <$fd>; close $fd or die_error(undef, "Reading diff-tree failed."); @@ -2243,14 +2239,14 @@ sub git_commitdiff { sub git_commitdiff_plain { mkdir($git_temp, 0700); - open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed."); my (@difftree) = map { chomp; $_ } <$fd>; close $fd or die_error(undef, "Reading diff-tree failed."); # try to figure out the next tag after this commit my $tagname; my $refs = read_info_ref("tags"); - open $fd, "-|", "$gitbin/git-rev-list HEAD"; + open $fd, "-|", "$GIT rev-list HEAD"; chomp (my (@commits) = <$fd>); close $fd; foreach my $commit (@commits) { @@ -2321,7 +2317,7 @@ sub git_history { print "
/" . esc_html($file_name) . "
\n"; open my $fd, "-|", - "$gitbin/git-rev-list --full-history $hash -- \'$file_name\'"; + "$GIT rev-list --full-history $hash -- \'$file_name\'"; print "\n"; my $alternate = 0; while (my $line = <$fd>) { @@ -2408,7 +2404,7 @@ sub git_search { my $alternate = 0; if ($commit_search) { $/ = "\0"; - open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next; + open my $fd, "-|", "$GIT rev-list --header --parents $hash" or next; while (my $commit_text = <$fd>) { if (!grep m/$searchtext/i, $commit_text) { next; @@ -2458,7 +2454,7 @@ sub git_search { if ($pickaxe_search) { $/ = "\n"; - open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'"; + open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'"; undef %co; my @files; while (my $line = <$fd>) { @@ -2529,7 +2525,7 @@ sub git_shortlog { " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "
\n"; my $limit = sprintf("--max-count=%i", (100 * ($page+1))); - open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed."); + open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed."); my (@revlist) = map { chomp; $_ } <$fd>; close $fd; -- cgit v1.2.3 From c6e1d9ed509265a66fe9d155b1a66aa954cce675 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:26:30 -0700 Subject: gitweb.cgi: Teach git_history() to read hash from $hash_base Teach git_history() to take its hash argument from the hb parameter, i.e. from $hash_base. Also change all "a=history" actions to pass "hb=" instead of "h=". Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2fd1e5f78e..d976d4adca 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1687,7 +1687,7 @@ sub git_tree { "\n"; } elsif ($t_type eq "tree") { @@ -1696,7 +1696,7 @@ sub git_tree { "\n" . "\n"; } print "\n"; @@ -2041,7 +2041,7 @@ sub git_commit { "\n" . "\n" } elsif ($status eq "M" || $status eq "T") { my $mode_chnge = ""; @@ -2072,7 +2072,7 @@ sub git_commit { if ($to_id ne $from_id) { print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff"); } - print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n"; + print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n"; print "\n"; } elsif ($status eq "R") { my ($from_file, $to_file) = split "\t", $file; @@ -2293,10 +2293,10 @@ sub git_commitdiff_plain { } sub git_history { - if (!defined $hash) { - $hash = git_read_head($project); + if (!defined $hash_base) { + $hash_base = git_read_head($project); } - my %co = git_read_commit($hash); + my %co = git_read_commit($hash_base); if (!%co) { die_error(undef, "Unknown commit object."); } @@ -2306,18 +2306,18 @@ sub git_history { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "

\n" . "\n"; print "
\n" . - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . "
\n"; print "
/" . esc_html($file_name) . "
\n"; open my $fd, "-|", - "$GIT rev-list --full-history $hash -- \'$file_name\'"; + "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; print "
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") . # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") . "" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . "
[deleted " . file_type($from_mode). "]" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "
\n"; my $alternate = 0; while (my $line = <$fd>) { @@ -2345,7 +2345,7 @@ sub git_history { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob"); - my $blob = git_get_hash_by_path($hash, $file_name); + my $blob = git_get_hash_by_path($hash_base, $file_name); my $blob_parent = git_get_hash_by_path($commit, $file_name); if (defined $blob && defined $blob_parent && $blob ne $blob_parent) { print " | " . -- cgit v1.2.3 From cff0771bfbc8a8c1a432a99bc297a52a5ba94304 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:28:55 -0700 Subject: gitweb.cgi: Include direct link to "raw" files from "history" In "history" view, the "page_path" is now also a URL link to the "raw" format of the file, which will always give you the latest version in the repository. This is helpful for externally linking files, such that the latest version is always referenced and in "raw" format. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index d976d4adca..7a61de4a77 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1531,6 +1531,14 @@ sub git_blob_plain_mimetype { } sub git_blob_plain { + if (!defined $hash) { + if (defined $file_name) { + my $base = $hash_base || git_read_head($project); + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); + } else { + die_error(undef, "No file name defined."); + } + } my $type = shift; open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash"); @@ -1554,10 +1562,14 @@ sub git_blob_plain { } sub git_blob { - if (!defined $hash && defined $file_name) { - my $base = $hash_base || git_read_head($project); - $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); - } + if (!defined $hash) { + if (defined $file_name) { + my $base = $hash_base || git_read_head($project); + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); + } else { + die_error(undef, "No file name defined."); + } + } my $have_blame = git_get_project_config_bool ('blame'); open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed."); my $mimetype = git_blob_plain_mimetype($fd, $file_name); @@ -1687,7 +1699,7 @@ sub git_tree { "\n"; } elsif ($t_type eq "tree") { @@ -2314,7 +2326,18 @@ sub git_history { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . "
\n"; - print "
/" . esc_html($file_name) . "
\n"; + if (defined $hash) { + my $ftype = git_get_type($hash); + + if ($ftype =~ "blob") { + print "
/" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($file_name)) . "
\n"; + } else { + print "
/" . esc_html($file_name) . "
\n"; + } + } else { + print "
/" . esc_html($file_name) . "
\n"; + } open my $fd, "-|", "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; -- cgit v1.2.3 From 1f2857ea32fa82ba6039b7fd298dc763b1e6c112 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:34:55 -0700 Subject: gitweb.cgi: git_blame2: an alternative simple working git blame This patch adds an alternative simple working git-blame called git_blame2(). Simple, because it displays just three columns: the commit, the line number and the line of code. Alternative, because the original git_blame() is left untouched. Lines of code are printed html escaped, but as-is. git_blame2() uses git-blame as opposed to git-annotate used by git_blame(). Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 4106cb8eb6..57f4a2e263 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -227,7 +227,7 @@ if (!defined $action || $action eq "summary") { git_tag(); exit; } elsif ($action eq "blame") { - git_blame(); + git_blame2(); exit; } else { undef $action; @@ -1252,6 +1252,75 @@ sub git_tag { git_footer_html(); } +sub git_read_blame_line { + my %bl; + $_ = shift; + + ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; + + return %bl; +} + +sub git_blame2 { + my $fd; + my $ftype; + die_error(undef, "Permission denied.") if (!git_get_project_config_bool ('blame')); + die_error('404 Not Found', "File name not defined") if (!$file_name); + $hash_base ||= git_read_head($project); + die_error(undef, "Reading commit failed") unless ($hash_base); + my %co = git_read_commit($hash_base) + or die_error(undef, "Reading commit failed"); + if (!defined $hash) { + $hash = git_get_hash_by_path($hash_base, $file_name, "blob") + or die_error(undef, "Error looking up file"); + } + $ftype = git_get_type($hash); + if ($ftype !~ "blob") { + die_error("400 Bad Request", "object is not a blob"); + } + open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base) + or die_error(undef, "Open failed"); + git_header_html(); + print "
\n" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "
\n"; + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "
\n"; + print "
\n". + "
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . + "
\n"; + git_print_page_path($file_name, $ftype); + + print "
\n"; + + print "
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") . # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") . "
\n"; + print "\n"; + while (my $line = <$fd>) { + my %blame_line = git_read_blame_line($line); + my $full_rev = $blame_line{'hash'}; + my $rev = substr($full_rev, 0, 8); + my $lineno = $blame_line{'lineno'}; + my $data = $blame_line{'data'}; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + } + print "
CommitLineData
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "" . esc_html($lineno) . "" . esc_html($data) . "
\n"; + print "
"; + + close $fd or print "Reading blob failed\n"; + git_footer_html(); +} + sub git_blame { my $fd; die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame')); -- cgit v1.2.3 From 4f7b34c98f6f3853c6b82a85f3e49121c59180f7 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:36:32 -0700 Subject: gitweb.cgi: git_blame2: Allow back-trekking through commits This patch adds the capability of back-trekking through commits from git_blame2() as follows: blame2->commit->blame2->commit->blame2->...->initial commit. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 57f4a2e263..2c2d9c8d8f 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -2022,7 +2022,13 @@ sub git_commit { print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff"); } print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" . - "

\n"; + "
\n"; + if (defined $file_name && defined $co{'parent'}) { + my $parent = $co{'parent'}; + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame") . "\n"; + } + print "
\n"; + if (defined $co{'parent'}) { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" . -- cgit v1.2.3 From 93d5f0619ccf10d7a16834b9e3be38871d2aae6c Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:30:08 -0700 Subject: gitweb.cgi: Show "raw" head of project link even when $hash is not defined Some callers of git_history() do not set $hash of $file_name. Add code to find it, if it is not defined. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 7a61de4a77..c04283ba58 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -2326,6 +2326,9 @@ sub git_history { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . "
\n"; + if (!defined $hash && defined $file_name) { + $hash = git_get_hash_by_path($hash_base, $file_name); + } if (defined $hash) { my $ftype = git_get_type($hash); -- cgit v1.2.3 From cc1bf97e24129db2b8c4634bc733ae0a16b2beba Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:37:53 -0700 Subject: gitweb.cgi: git_blame2: Revision blocks now have alternating colors A revision block is the largest number of adjacent lines of code originating from the same revision. This patch adds color to git_blame2(), in that no two adjacent revision blocks have the same color. The color alternates between light and dark. As we annotate the code lines, we alternate the color (light, dark) of code lines _per revision_. This makes it easier to see line conglomerations per revision. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2c2d9c8d8f..16340f2106 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1295,9 +1295,11 @@ sub git_blame2 { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "
\n"; git_print_page_path($file_name, $ftype); - + my @rev_color = (qw(light dark)); + my $num_colors = scalar(@rev_color); + my $current_color = 0; + my $last_rev; print "
\n"; - print "\n"; print "\n"; while (my $line = <$fd>) { @@ -1307,7 +1309,13 @@ sub git_blame2 { my $lineno = $blame_line{'lineno'}; my $data = $blame_line{'data'}; - print "\n"; + if (!defined $last_rev) { + $last_rev = $full_rev; + } elsif ($last_rev ne $full_rev) { + $last_rev = $full_rev; + $current_color = ++$current_color % $num_colors; + } + print "\n"; print "\n"; print "\n"; @@ -1316,7 +1324,6 @@ sub git_blame2 { } print "
CommitLineData
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "" . esc_html($lineno) . "
\n"; print "
"; - close $fd or print "Reading blob failed\n"; git_footer_html(); } -- cgit v1.2.3 From 634331061599a82968daddae2d2c0896b6137d4c Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:31:15 -0700 Subject: gitweb.cgi: Centralize printing of the page path Centralize printing of the page path so that if the entity is a blob, we can set the page path to be the link to the HEAD revision of the "raw" blob. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index c04283ba58..4106cb8eb6 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1199,6 +1199,20 @@ sub git_summary { git_footer_html(); } +sub git_print_page_path { + my $name = shift; + my $type = shift; + + if (!defined $name) { + print "
/
\n"; + } elsif ($type =~ "blob") { + print "
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($name)) . "
\n"; + } else { + print "
" . esc_html($name) . "
\n"; + } +} + sub git_tag { my $head = git_read_head($project); git_header_html(); @@ -1266,7 +1280,7 @@ sub git_blame { "
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "
\n"; - print "
" . esc_html($file_name) . "
\n"; + git_print_page_path($file_name); print "
\n"; print < @@ -1604,9 +1618,7 @@ sub git_blob { "

\n" . "
$hash
\n"; } - if (defined $file_name) { - print "
" . esc_html($file_name) . "
\n"; - } + git_print_page_path($file_name, "blob"); print "
\n"; my $nr; while (my $line = <$fd>) { @@ -1671,10 +1683,8 @@ sub git_tree { } if (defined $file_name) { $base = esc_html("$file_name/"); - print "
/" . esc_html($file_name) . "
\n"; - } else { - print "
/
\n"; } + git_print_page_path($file_name); print "
\n"; print "\n"; my $alternate = 0; @@ -2132,9 +2142,7 @@ sub git_blobdiff { "

\n" . "
$hash vs $hash_parent
\n"; } - if (defined $file_name) { - print "
/" . esc_html($file_name) . "
\n"; - } + git_print_page_path($file_name, "blob"); print "
\n" . "
blob:" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) . @@ -2308,6 +2316,7 @@ sub git_history { if (!defined $hash_base) { $hash_base = git_read_head($project); } + my $ftype; my %co = git_read_commit($hash_base); if (!%co) { die_error(undef, "Unknown commit object."); @@ -2330,17 +2339,9 @@ sub git_history { $hash = git_get_hash_by_path($hash_base, $file_name); } if (defined $hash) { - my $ftype = git_get_type($hash); - - if ($ftype =~ "blob") { - print "
/" . - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($file_name)) . "
\n"; - } else { - print "
/" . esc_html($file_name) . "
\n"; - } - } else { - print "
/" . esc_html($file_name) . "
\n"; + $ftype = git_get_type($hash); } + git_print_page_path($file_name, $ftype); open my $fd, "-|", "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; -- cgit v1.2.3 From acb0f6f33760b43c1fc9617a45346ab3738f021a Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 14:17:48 -0700 Subject: gitweb.cgi: git_blame2: slight optimization reading the blame lines Eliminate git_read_blame_line() -- move that code inline and optimize it. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 16340f2106..7fbfc0d226 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1252,15 +1252,6 @@ sub git_tag { git_footer_html(); } -sub git_read_blame_line { - my %bl; - $_ = shift; - - ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; - - return %bl; -} - sub git_blame2 { my $fd; my $ftype; @@ -1302,12 +1293,12 @@ sub git_blame2 { print "
\n"; print "
\n"; print "\n"; - while (my $line = <$fd>) { - my %blame_line = git_read_blame_line($line); - my $full_rev = $blame_line{'hash'}; + while (<$fd>) { + /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; + my $full_rev = $1; my $rev = substr($full_rev, 0, 8); - my $lineno = $blame_line{'lineno'}; - my $data = $blame_line{'data'}; + my $lineno = $2; + my $data = $3; if (!defined $last_rev) { $last_rev = $full_rev; -- cgit v1.2.3 From 143c89b00348759d2768003d57e0f506d281dc61 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Mon, 24 Jul 2006 23:07:23 +0100 Subject: gitweb: escape tag comments I have a tag with a comment which includes an & character. Firefox wouldn't display my gitweb summary page due to malformed XML. This solves the problem. Signed-off-by: Daniel Drake Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2fd1e5f78e..5acd66dd6c 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1138,7 +1138,7 @@ sub git_summary { "\n" . "\n" . "
CommitLineData
"; if (defined($comment)) { - print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment); + print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, esc_html($comment)); } print ""; -- cgit v1.2.3 From 4325b4ad16821e936cb619f5e25d273c281bdeeb Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 16:58:35 +0200 Subject: gitweb: fix two warnings These warnings cluttered up my log. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gitweb/gitweb.cgi') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 5acd66dd6c..30cb624b2a 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -795,7 +795,7 @@ sub git_read_projects { if (-d $projects_list) { # search in directory my $dir = $projects_list; - opendir my $dh, $dir or return undef; + opendir my ($dh), $dir or return undef; while (my $dir = readdir($dh)) { if (-e "$projectroot/$dir/HEAD") { my $pr = { @@ -810,7 +810,7 @@ sub git_read_projects { # 'git%2Fgit.git Linus+Torvalds' # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' - open my $fd , $projects_list or return undef; + open my ($fd), $projects_list or return undef; while (my $line = <$fd>) { chomp $line; my ($path, $owner) = split ' ', $line; -- cgit v1.2.3