{"thread":{"id":"15419","subject":"[PATCH (GIT-GUI FIX)] git-gui: Fix Blame Parent & Context for working copy lines.","startedAt":"2008-09-08T07:18:52Z","lastAt":"2008-09-08T07:18:52Z","messageCount":1,"participants":["Alexander Gavrilov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"90053","messageId":"200809081118.52705.angavrilov@gmail.com","threadId":"15419","inReplyTo":null,"subject":"[PATCH (GIT-GUI FIX)] git-gui: Fix Blame Parent & Context for working copy lines.","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-09-08T07:18:52Z","receivedAt":"2008-09-08T07:18:52Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"Make Blame Parent Commit and Show History Context work\nproperly for lines blamed on the working copy.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n\n\tCurrently it displays an ugly error box.\n\n\t-- Alexander\n\n git-gui.sh    |    3 +++\n lib/blame.tcl |   29 ++++++++++++++++++++++++++---\n 2 files changed, 29 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 57a0c34..f249b0b 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -1061,6 +1061,9 @@ set current_diff_path {}\n set is_3way_diff 0\n set selected_commit_type new\n \n+set nullid \"0000000000000000000000000000000000000000\"\n+set nullid2 \"0000000000000000000000000000000000000001\"\n+\n ######################################################################\n ##\n ## task management\ndiff --git a/lib/blame.tcl b/lib/blame.tcl\nindex b5fc9fa..84d55b5 100644\n--- a/lib/blame.tcl\n+++ b/lib/blame.tcl\n@@ -939,9 +939,20 @@ method _format_offset_date {base offset} {\n }\n \n method _gitkcommit {} {\n+\tglobal nullid\n+\n \tset dat [_get_click_amov_info $this]\n \tif {$dat ne {}} {\n \t\tset cmit [lindex $dat 0]\n+\n+\t\t# If the line belongs to the working copy, use HEAD instead\n+\t\tif {$cmit eq $nullid} {\n+\t\t\tif {[catch {set cmit [git rev-parse --verify HEAD]} err]} {\n+\t\t\t\terror_popup [strcat [mc \"Cannot find HEAD commit:\"] \"\\n\\n$err\"]\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t}\n+\n \t\tset radius [get_config gui.blamehistoryctx]\n \t\tset cmdline [list --select-commit=$cmit]\n \n@@ -978,12 +989,20 @@ method _gitkcommit {} {\n }\n \n method _blameparent {} {\n+\tglobal nullid\n+\n \tset dat [_get_click_amov_info $this]\n \tif {$dat ne {}} {\n \t\tset cmit [lindex $dat 0]\n \t\tset new_path [lindex $dat 1]\n \n-\t\tif {[catch {set cparent [git rev-parse --verify \"$cmit^\"]}]} {\n+\t\t# Allow using Blame Parent on lines modified in the working copy\n+\t\tif {$cmit eq $nullid} {\n+\t\t\tset parent_ref \"HEAD\"\n+\t\t} else {\n+\t\t\tset parent_ref \"$cmit^\"\n+\t\t}\n+\t\tif {[catch {set cparent [git rev-parse --verify $parent_ref]} err]} {\n \t\t\terror_popup [strcat [mc \"Cannot find parent commit:\"] \"\\n\\n$err\"]\n \t\t\treturn;\n \t\t}\n@@ -993,8 +1012,12 @@ method _blameparent {} {\n \t\t# Generate a diff between the commit and its parent,\n \t\t# and use the hunks to update the line number.\n \t\t# Request zero context to simplify calculations.\n-\t\tif {[catch {set fd [eval git_read diff-tree \\\n-\t\t\t\t--unified=0 $cparent $cmit $new_path]} err]} {\n+\t\tif {$cmit eq $nullid} {\n+\t\t\tset diffcmd [list diff-index --unified=0 $cparent -- $new_path]\n+\t\t} else {\n+\t\t\tset diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]\n+\t\t}\n+\t\tif {[catch {set fd [eval git_read $diffcmd]} err]} {\n \t\t\t$status stop [mc \"Unable to display parent\"]\n \t\t\terror_popup [strcat [mc \"Error loading diff:\"] \"\\n\\n$err\"]\n \t\t\treturn\n-- \n1.6.0.20.g6148bc\n"}]}