{"thread":{"id":"5827","subject":"[PATCH 6/6] gitweb: use blame --porcelain","startedAt":"2006-10-05T21:07:58Z","lastAt":"2006-10-05T21:48:13Z","messageCount":3,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"28253","messageId":"7vwt7ebhe9.fsf@assigned-by-dhcp.cox.net","threadId":"5827","inReplyTo":null,"subject":"[PATCH 6/6] gitweb: use blame --porcelain","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-05T21:07:58Z","receivedAt":"2006-10-05T21:07:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This makes gitweb (git_blame2) to use \"blame --porcelain\", which\nlets the caller to figure out which line in the original version\neach line comes from.  Using this information, change the\nbehaviour of clicking the line number to go to the line of the\nblame output for the original commit.\n\nBefore, clicking the line number meant \"scoll up to show this\nline at the beginning of the page\", which was not all that\nuseful.  The new behaviour lets you click on the line you are\ninterested in to view the line in the context it was introduced,\nand keep digging deeper as you examine it.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * I've tested this only very lightly but it seems to be quite\n   pleasant to use.\n\n gitweb/gitweb.perl |   65 +++++++++++++++++++++++++++++++++++----------------\n 1 files changed, 44 insertions(+), 21 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex d217187..29a56c3 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -971,6 +971,9 @@ sub parse_date {\n \t$date{'hour_local'} = $hour;\n \t$date{'minute_local'} = $min;\n \t$date{'tz_local'} = $tz;\n+\t$date{'iso-tz'} = sprintf (\"%04d-%02d-%02d %02d:%02d:%02d %s\",\n+\t\t\t\t   1900+$year, $mon+1, $mday,\n+\t\t\t\t   $hour, $min, $sec, $tz);\n \treturn %date;\n }\n \n@@ -2496,7 +2499,8 @@ sub git_blame2 {\n \tif ($ftype !~ \"blob\") {\n \t\tdie_error(\"400 Bad Request\", \"Object is not a blob\");\n \t}\n-\topen ($fd, \"-|\", git_cmd(), \"blame\", '-l', '--', $file_name, $hash_base)\n+\topen ($fd, \"-|\", git_cmd(), \"blame\", '--porcelain', '--',\n+\t      $file_name, $hash_base)\n \t\tor die_error(undef, \"Open git-blame failed\");\n \tgit_header_html();\n \tmy $formats_nav =\n@@ -2520,33 +2524,52 @@ sub git_blame2 {\n <table class=\"blame\">\n <tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n HTML\n-\twhile (<$fd>) {\n-\t\tmy ($full_rev, $author, $date, $lineno, $data) =\n-\t\t\t/^([0-9a-f]{40}).*?\\s\\((.*?)\\s+([-\\d]+ [:\\d]+ [-+\\d]+)\\s+(\\d+)\\)\\s(.*)/;\n+\tmy %metainfo = ();\n+\twhile (1) {\n+\t\t$_ = <$fd>;\n+\t\tlast unless defined $_;\n+\t\tmy ($full_rev, $lineno, $orig_lineno, $group_size) =\n+\t\t    /^([0-9a-f]{40}) (\\d+) (\\d+)(?: (\\d+))?$/;\n+\t\tif (!exists $metainfo{$full_rev}) {\n+\t\t\t$metainfo{$full_rev} = {};\n+\t\t}\n+\t\tmy $meta = $metainfo{$full_rev};\n+\t\twhile (<$fd>) {\n+\t\t\tlast if (s/^\\t//);\n+\t\t\tif (/^(\\S+) (.*)$/) {\n+\t\t\t\t$meta->{$1} = $2;\n+\t\t\t}\n+\t\t}\n+\t\tmy $data = $_;\n \t\tmy $rev = substr($full_rev, 0, 8);\n-\t\tmy $print_c8 = 0;\n-\n-\t\tif (!defined $last_rev) {\n-\t\t\t$last_rev = $full_rev;\n-\t\t\t$print_c8 = 1;\n-\t\t} elsif ($last_rev ne $full_rev) {\n-\t\t\t$last_rev = $full_rev;\n+\t\tmy $author = $meta->{'author'};\n+\t\tmy %date = parse_date($meta->{'author-time'},\n+\t\t\t\t      $meta->{'author-tz'});\n+\t\tmy $date = $date{'iso-tz'};\n+\t\tif ($group_size) {\n \t\t\t$current_color = ++$current_color % $num_colors;\n-\t\t\t$print_c8 = 1;\n \t\t}\n \t\tprint \"<tr class=\\\"$rev_color[$current_color]\\\">\\n\";\n-\t\tprint \"<td class=\\\"sha1\\\"\";\n-\t\tif ($print_c8 == 1) {\n+\t\tif ($group_size) {\n+\t\t\tprint \"<td class=\\\"sha1\\\"\";\n \t\t\tprint \" title=\\\"$author, $date\\\"\";\n-\t\t}\n-\t\tprint \">\";\n-\t\tif ($print_c8 == 1) {\n-\t\t\tprint $cgi->a({-href => href(action=>\"commit\", hash=>$full_rev, file_name=>$file_name)},\n+\t\t\tprint \" rowspan=\\\"$group_size\\\"\" if ($group_size > 1);\n+\t\t\tprint \">\";\n+\t\t\tprint $cgi->a({-href => href(action=>\"commit\",\n+\t\t\t\t\t\t     hash=>$full_rev,\n+\t\t\t\t\t\t     file_name=>$file_name)},\n \t\t\t\t      esc_html($rev));\n+\t\t\tprint \"</td>\\n\";\n \t\t}\n-\t\tprint \"</td>\\n\";\n-\t\tprint \"<td class=\\\"linenr\\\"><a id=\\\"l$lineno\\\" href=\\\"#l$lineno\\\" class=\\\"linenr\\\">\" .\n-\t\t      esc_html($lineno) . \"</a></td>\\n\";\n+\t\tmy $blamed = href(action => 'blame',\n+\t\t\t\t  file_name => $meta->{'filename'},\n+\t\t\t\t  hash_base => $full_rev);\n+\t\tprint \"<td class=\\\"linenr\\\">\";\n+\t\tprint $cgi->a({ -href => \"$blamed#l$lineno\",\n+\t\t\t\t-id => \"l$lineno\",\n+\t\t\t\t-class => \"linenr\" },\n+\t\t\t      esc_html($lineno));\n+\t\tprint \"</td>\";\n \t\tprint \"<td class=\\\"pre\\\">\" . esc_html($data) . \"</td>\\n\";\n \t\tprint \"</tr>\\n\";\n \t}\n-- \n1.4.2.3.g866f3\n"},{"id":"28256","messageId":"7vlknubgwj.fsf@assigned-by-dhcp.cox.net","threadId":"5827","inReplyTo":"7vwt7ebhe9.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 6/6] gitweb: use blame --porcelain","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-05T21:18:36Z","receivedAt":"2006-10-05T21:18:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Side note.\n\nThis change does not give any more information (other than the\nlink to the corresponding line in the original version) than the\ncurrent gitweb in \"next\", but \"blame --porcelain\" returns richer\ninformation than it used to be available, most notably the\nsummary line.  It might be interesting to enhance the title pop-up\nmechanism to show them on mouse-over, but I was too lazy ;-).\n\nI've considered making the commit-8 link to link not to the\ncommit page for the originating commit but to the corresponding\nline in the blame page for it, but opted to take over the line\nnumber link, which was serving far less useful purpose.  Your\nkeyboard has PgUp and PgDn to let you navigate within the same\nblame output.\n\nAs I noted in the log message for [3/6], I suspect that the\ncurent implementation to show the original line number is\nunnecessarily inefficient.  Improvement is much encouraged.\nAgain, I am too lazy to look into it right now.\n"},{"id":"28259","messageId":"7v4puibfj6.fsf@assigned-by-dhcp.cox.net","threadId":"5827","inReplyTo":"7vwt7ebhe9.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 6/6] gitweb: use blame --porcelain","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-05T21:48:13Z","receivedAt":"2006-10-05T21:48:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Found a stupid typo...\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex feb768f..8b97357 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -2589,7 +2589,7 @@ HTML\n \t\t\t\t  file_name => $meta->{'filename'},\n \t\t\t\t  hash_base => $full_rev);\n \t\tprint \"<td class=\\\"linenr\\\">\";\n-\t\tprint $cgi->a({ -href => \"$blamed#l$lineno\",\n+\t\tprint $cgi->a({ -href => \"$blamed#l$orig_lineno\",\n \t\t\t\t-id => \"l$lineno\",\n \t\t\t\t-class => \"linenr\" },\n \t\t\t      esc_html($lineno));\n"}]}