{"thread":{"id":"5424","subject":"[PATCH] gitweb: show age and author in blame output","startedAt":"2006-08-29T09:07:03Z","lastAt":"2006-08-29T09:07:03Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"26082","messageId":"7v64gboqq0.fsf@assigned-by-dhcp.cox.net","threadId":"5424","inReplyTo":null,"subject":"[PATCH] gitweb: show age and author in blame output","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-29T09:07:03Z","receivedAt":"2006-08-29T09:07:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The commit object name link on each link uses \"title\", which\nshows the author and age of the particular line when hovered\nover.\n\nThe background of these links are painted on darker color as\nthey become older and the links on younger lines are shown on\nlighter background.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n gitweb/gitweb.css  |    6 ++++++\n gitweb/gitweb.perl |   27 +++++++++++++++++++++++----\n 2 files changed, 29 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex eb9fc38..f3211c2 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -215,6 +215,12 @@ td.sha1 {\n \tfont-family: monospace;\n }\n \n+table.blame td.age-week   { color: #0000ff; background-color: #ffffff; }\n+table.blame td.age-month  { color: #0000ff; background-color: #ddddee; }\n+table.blame td.age-season { color: #0000ff; background-color: #bbbbdd; }\n+table.blame td.age-year   { color: #0000ff; background-color: #9999cc; }\n+table.blame td.age-old    { color: #0000ff; background-color: #7777bb; }\n+\n td.error {\n \tcolor: red;\n \tbackground-color: yellow;\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 5c82d3f..0265a82 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -2171,12 +2171,26 @@ sub git_tag {\n }\n \n sub flush_blame_lines {\n-\tmy ($color, $file_name, @line) = @_;\n+\tmy ($color, $file_name, $now, @line) = @_;\n \tmy $full_rev = shift @line;\n+\n+\tmy ($author, $timestamp, $zone) =\n+\t    ($line[0] =~\n+\t     /^[0-9a-f]{40}\\s\\((.*?)\\s+(\\d+)\\s([-+\\d]{5})\\s+\\d+\\)/);\n+\tmy $age = $now - $timestamp;\n+\tmy $ago = age_string($age);\n+\tmy $pop = 'title=\"' . esc_html(\"$author, $ago\") . '\"';\n+\tmy $agegroup =\n+\t    (($age < 60*60*24*7) ? \"age-week\" :\n+\t     ($age < 60*60*24*30) ? \"age-month\" :\n+\t     ($age < 60*60*24*120) ? \"age-season\" :\n+\t     ($age < 60*60*24*360) ? \"age-year\" : \"age-old\");\n+\n \tmy $rev = substr($full_rev, 0, 8);\n \tmy $cnt = scalar @line;\n \tmy $this = 0;\n \n+\n \tfor (@line) {\n \t\t$this++;\n \t\tunless (/^[0-9a-fA-F]{40}.*?(\\d+)\\)\\s(.*)/) {\n@@ -2188,11 +2202,12 @@ sub flush_blame_lines {\n \t\tprint \"<tr class=\\\"$color\\\">\\n\";\n \n \t\tif ($this == 1) {\n+\t\t\tmy $cls = \"class=\\\"sha1 $agegroup\\\"\";\n \t\t\tif (1 < $cnt) {\n-\t\t\t\tprint \"<td class=\\\"sha1\\\" rowspan=\\\"$cnt\\\">\";\n+\t\t\t\tprint \"<td $cls $pop rowspan=\\\"$cnt\\\">\";\n \t\t\t}\n \t\t\telse {\n-\t\t\t\tprint \"<td class=\\\"sha1\\\">\";\n+\t\t\t\tprint \"<td $cls $pop>\";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"commit\",\n \t\t\t\t\t\t     hash=>$full_rev,\n@@ -2228,7 +2243,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\", '-l', '-t',\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@@ -2242,6 +2258,7 @@ sub git_blame2 {\n \tgit_print_page_path($file_name, $ftype, $hash_base);\n \tmy @rev_color = (qw(light2 dark2));\n \tmy $num_colors = scalar(@rev_color);\n+\tmy $now = time();\n \tmy $current_color = 0;\n \tmy @current_group = ();\n \tprint <<HTML;\n@@ -2260,6 +2277,7 @@ HTML\n \t\t\t\t$current_color = ++$current_color % $num_colors;\n \t\t\t\tflush_blame_lines($rev_color[$current_color],\n \t\t\t\t\t\t  $file_name,\n+\t\t\t\t\t\t  $now,\n \t\t\t\t\t\t  @current_group);\n \t\t\t}\n \t\t\telse {\n@@ -2273,6 +2291,7 @@ HTML\n \t\t$current_color = ++$current_color % $num_colors;\n \t\tflush_blame_lines($rev_color[$current_color],\n \t\t\t\t  $file_name,\n+\t\t\t\t  $now,\n \t\t\t\t  @current_group);\n \t}\n \tprint \"</table>\\n\";\n-- \n1.4.2.g39ee\n"}]}