{"thread":{"id":"8206","subject":"[PATCH] gitweb: Extra columns in blame","startedAt":"2007-05-18T19:17:25Z","lastAt":"2007-05-19T02:10:52Z","messageCount":5,"participants":["Petr Baudis","Junio C Hamano","A Large Angry SCM"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"42509","messageId":"20070518191725.10460.83338.stgit@rover","threadId":"8206","inReplyTo":null,"subject":"[PATCH] gitweb: Extra columns in blame","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-05-18T19:17:25Z","receivedAt":"2007-05-18T19:17:25Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch adds extra columns to blame output, containing\nline author and creation date. These columns are by default hidden by\ndisplay: none but by clicking on the expansion \"button\" you can display\nthem (and hide again). I think seeing this information without tooltips\nfishing can give much better overview of the content evolution.\n\nThis patch depends on the interactive blame patch (but can be factored out;\nthe common required parts are just the blame.js infrastructure).\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n gitweb/blame.js    |   45 ++++++++++++++++++++++++++++++++++++++++++++-\n gitweb/gitweb.css  |    5 +++++\n gitweb/gitweb.perl |   23 +++++++++++++++++++----\n 3 files changed, 68 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/blame.js b/gitweb/blame.js\nindex 88b6499..438bc9c 100644\n--- a/gitweb/blame.js\n+++ b/gitweb/blame.js\n@@ -1,4 +1,41 @@\n // Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>\n+// Copyright (C) 2007, Petr Baudis <pasky@suse.cz>\n+\n+\n+// blame extra columns\n+\n+// I would like to note here that JavaScript is utterly stupid.\n+function findStyleRule(styleName) {\n+\tfor (i = 0; i < document.styleSheets.length; i++) { \n+\t\tfor (j = 0; j < document.styleSheets[i].cssRules.length; j++) {\n+\t\t\tvar rule = document.styleSheets[i].cssRules[j];\n+\t\t\tif (rule.selectorText == styleName) {\n+\t\t\t\treturn rule;\n+\t\t\t}\n+\t\t}     \n+\t}\n+}\n+var extra_column_rule;\n+\n+var extra_columns = 0;\n+function extra_blame_columns() {\n+\tif (!extra_column_rule)\n+\t\textra_column_rule = findStyleRule(\"th.extra_column, td.extra_column\");\n+\n+\tif (!extra_columns) {\n+\t\tdocument.getElementById(\"columns_expander\").innerHTML = \"[-]\";\n+\t\textra_column_rule.style.cssText = extra_column_rule.style.cssText.replace(\"none\", \"table-cell\");\n+\t\textra_columns = 1;\n+\t} else {\n+\t\tdocument.getElementById(\"columns_expander\").innerHTML = \"[+]\";\n+\t\textra_column_rule.style.cssText = extra_column_rule.style.cssText.replace(\"table-cell\", \"none\");\n+\t\textra_columns = 0;\n+\t}\n+}\n+\n+\n+// blame_interactive\n+\n \n var DEBUG = 0;\n function debug(str)\n@@ -72,14 +109,20 @@ function handleLine(commit)\n             zeroPad(date.getUTCSeconds());\n         tr.firstChild.title = commit.author + ', ' + dateStr + ' ' + timeStr;\n         var shaAnchor = tr.firstChild.firstChild;\n+\tvar authorField = tr.firstChild.nextSibling;\n+\tvar dateField = tr.firstChild.nextSibling.nextSibling;\n         if (i == 0) {\n             shaAnchor.href = baseUrl + ';a=commit;h=' + commit.sha1;\n             shaAnchor.innerHTML = commit.sha1.substr(0, 8);\n+\t    authorField.innerHTML = commit.author;\n+\t    dateField.innerHTML = dateStr + ' ' + timeStr;\n         } else {\n             shaAnchor.innerHTML = '';\n+            authorField.innerHTML = '';\n+            dateField.innerHTML = '';\n         }\n \n-        var lineAnchor = tr.firstChild.nextSibling.firstChild;\n+        var lineAnchor = tr.firstChild.nextSibling.nextSibling.nextSibling.firstChild;\n         lineAnchor.href = baseUrl + ';a=blame;hb=' + commit.sha1 +\n             ';f=' + commit.filename + '#l' + commit.srcline;\n         resline++;\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex 9f0822f..b76e839 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -488,3 +488,8 @@ span.match {\n div.binary {\n \tfont-style: italic;\n }\n+\n+/* This selector is hardcoded in gitweb.perl */\n+th.extra_column, td.extra_column {\n+\tdisplay: none;\n+}\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex cc671b1..2dc7be8 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3671,9 +3671,14 @@ sub git_blame_incremental {\n \tmy $last_rev;\n \tprint \"<script type=\\\"text/javascript\\\" src=\\\"$blamejs\\\"></script>\\n\";\n \tprint <<HTML;\n+\n <div class=\"page_body\">\n <table class=\"blame\">\n-<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n+<tr><th>Commit&nbsp;<a href=\"javascript:extra_blame_columns()\" id=\"columns_expander\">[+]</a></th>\n+<th class=\"extra_column\">Author</th>\n+<th class=\"extra_column\">Date</th>\n+<th>Line</th>\n+<th>Data</th></tr>\n HTML\n \tmy %metainfo = ();\n \tmy $linenr = 0;\n@@ -3682,6 +3687,8 @@ HTML\n \t\t$linenr += 1;\n \t\tprint \"<tr id=\\\"l$linenr\\\" class=\\\"light2\\\">\";\n \t\tprint '<td class=\"sha1\"><a href=\"\"></a></td>';\n+\t\tprint \"<td class=\\\"extra_column\\\"></td>\";\n+\t\tprint \"<td class=\\\"extra_column\\\"></td>\";\n \t\tprint \"<td class=\\\"linenr\\\"><a class=\\\"linenr\\\" href=\\\"\\\">$linenr</a></td><td class=\\\"pre\\\">\" . esc_html($_) . \"</td>\\n\";\n \t\tprint \"</tr>\\n\"\n \t}\n@@ -3738,10 +3745,16 @@ sub git_blame2 {\n \tmy $num_colors = scalar(@rev_color);\n \tmy $current_color = 0;\n \tmy $last_rev;\n+\tprint \"<script type=\\\"text/javascript\\\" src=\\\"$blamejs\\\"></script>\\n\";\n \tprint <<HTML;\n+\n <div class=\"page_body\">\n <table class=\"blame\">\n-<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n+<tr><th>Commit&nbsp;<a href=\"javascript:extra_blame_columns()\" id=\"columns_expander\">[+]</a></th>\n+<th class=\"extra_column\">Author</th>\n+<th class=\"extra_column\">Date</th>\n+<th>Line</th>\n+<th>Data</th></tr>\n HTML\n \tmy %metainfo = ();\n \twhile (1) {\n@@ -3771,15 +3784,17 @@ HTML\n \t\t}\n \t\tprint \"<tr class=\\\"$rev_color[$current_color]\\\">\\n\";\n \t\tif ($group_size) {\n+\t\t\tmy $rowspan = $group_size > 1 ? \" rowspan=\\\"$group_size\\\"\" : \"\";\n \t\t\tprint \"<td class=\\\"sha1\\\"\";\n \t\t\tprint \" title=\\\"\". esc_html($author) . \", $date\\\"\";\n-\t\t\tprint \" rowspan=\\\"$group_size\\\"\" if ($group_size > 1);\n-\t\t\tprint \">\";\n+\t\t\tprint \"$rowspan>\";\n \t\t\tprint $cgi->a({-href => href(action=>\"commit\",\n \t\t\t                             hash=>$full_rev,\n \t\t\t                             file_name=>$file_name)},\n \t\t\t              esc_html($rev));\n \t\t\tprint \"</td>\\n\";\n+\t\t\tprint \"<td class=\\\"extra_column\\\" $rowspan>\". esc_html($author) . \"</td>\";\n+\t\t\tprint \"<td class=\\\"extra_column\\\" $rowspan>\". $date . \"</td>\";\n \t\t}\n \t\topen (my $dd, \"-|\", git_cmd(), \"rev-parse\", \"$full_rev^\")\n \t\t\tor die_error(undef, \"Open git-rev-parse failed\");\n"},{"id":"42533","messageId":"7vy7jl4zjm.fsf@assigned-by-dhcp.cox.net","threadId":"8206","inReplyTo":"20070518191725.10460.83338.stgit@rover","subject":"Re: [PATCH] gitweb: Extra columns in blame","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-18T21:01:01Z","receivedAt":"2007-05-18T21:01:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Good job, except that I think you should also show the filename\nespecially as you seem to run with -C (I haven't looked at the\ncode yet, though).\n\nE.g.\n\nhttp://repo.or.cz/w/linux-2.6.git?a=blame_incremental;f=block/ll_rw_blk.c;h=6b5173ac81313d8adb5c1d7b521559f565bb209b;hb=347b4599dd6ffef27e18c227532d1ec66556000b\n\nthe first few hunks that came from 1da177e4 are from a different\nfile, drivers/block/ll_rw_blk.c.\n\nAlso the incremental thing using JavaScript does not seem to\nwork for me incrementally for some reason, although if I wait\nlong enough I get the fully blamed picture that seems to match\nnonincremental one.  While I am waiting, the browser goes silent\nand does not even let me switch to other tabs, so it is not all\nthat useful to me in its current shape.\n"},{"id":"42542","messageId":"20070518221916.GZ4489@pasky.or.cz","threadId":"8206","inReplyTo":"7vy7jl4zjm.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] gitweb: Extra columns in blame","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-05-18T22:19:16Z","receivedAt":"2007-05-18T22:19:16Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Fri, May 18, 2007 at 11:01:01PM CEST, Junio C Hamano wrote:\n> Good job, except that I think you should also show the filename\n> especially as you seem to run with -C (I haven't looked at the\n> code yet, though).\n> \n> E.g.\n> \n> http://repo.or.cz/w/linux-2.6.git?a=blame_incremental;f=block/ll_rw_blk.c;h=6b5173ac81313d8adb5c1d7b521559f565bb209b;hb=347b4599dd6ffef27e18c227532d1ec66556000b\n> \n> the first few hunks that came from 1da177e4 are from a different\n> file, drivers/block/ll_rw_blk.c.\n\nI don't use git-blame -C - I pass virtually no extra parameters to\ngit-blame (except some output controlling). Passing -C to git-blame\nmight be an interesting idea but the possible performance hit is a bit\nscary; when the dust settles and this gets merged or something, I can\nexperiment with it a bit further...\n\n(Also, I fear a bit about making it _too_ wide even with the extra\ncolumns; there should be reasonable portion of line still visible on\nusual resolutions with usual font sizes. Might be nice UI challenge.\n\n> Also the incremental thing using JavaScript does not seem to\n> work for me incrementally for some reason, although if I wait\n> long enough I get the fully blamed picture that seems to match\n> nonincremental one.  While I am waiting, the browser goes silent\n> and does not even let me switch to other tabs, so it is not all\n> that useful to me in its current shape.\n\nStrange, what browser are you using?\n\nThe trouble is, I'm not really very good at this kind of web development\nbecause I have access only to a rather narrow portion of the browser\nmarket - Firefox at Linux, at work also Galeon, Epiphany and Konqueror,\nand of course ELinks. I have theoretical access to MSIE at work but it's\nquite a hassle. With all browser I've tested it with, it worked without\na problem, so I'm not sure how much will I be able to debug it (and I'm\nreally bad at debugging javascript anyway).\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nEver try. Ever fail. No matter. // Try again. Fail again. Fail better.\n\t\t-- Samuel Beckett\n"},{"id":"42569","messageId":"7vy7jl3bu5.fsf@assigned-by-dhcp.cox.net","threadId":"8206","inReplyTo":"20070518221916.GZ4489@pasky.or.cz","subject":"Re: [PATCH] gitweb: Extra columns in blame","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-19T00:18:26Z","receivedAt":"2007-05-19T00:18:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n>> Also the incremental thing using JavaScript does not seem to\n>> work for me incrementally for some reason, although if I wait\n>> long enough I get the fully blamed picture that seems to match\n>> nonincremental one.  While I am waiting, the browser goes silent\n>> and does not even let me switch to other tabs, so it is not all\n>> that useful to me in its current shape.\n>\n> Strange, what browser are you using?\n\nFirefox (I think it is 2.0) running on a W2k box behind two http\nproxies.\n"},{"id":"42580","messageId":"464E5CAC.1040303@gmail.com","threadId":"8206","inReplyTo":"7vy7jl3bu5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] gitweb: Extra columns in blame","fromName":"A Large Angry SCM","fromEmail":"gitzilla@gmail.com","sentAt":"2007-05-19T02:10:52Z","receivedAt":"2007-05-19T02:10:52Z","isPatch":true,"sender":{"key":"gitzilla@gmail.com","avatar":"https://gravatar.com/avatar/354625c442439908ff3dd99757dee330e29e9df7847472384faf7a00add247fb?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Petr Baudis <pasky@suse.cz> writes:\n> \n>>> Also the incremental thing using JavaScript does not seem to\n>>> work for me incrementally for some reason, although if I wait\n>>> long enough I get the fully blamed picture that seems to match\n>>> nonincremental one.  While I am waiting, the browser goes silent\n>>> and does not even let me switch to other tabs, so it is not all\n>>> that useful to me in its current shape.\n>> Strange, what browser are you using?\n> \n> Firefox (I think it is 2.0) running on a W2k box behind two http\n> proxies.\n\nSame symptoms with FireFox 1.5.0.10 running on Suse 9.3.\n"}]}