git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Gavrilov <angavrilov@gmail.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>
Subject: [PATCH (GIT-GUI FIX)] git-gui: Fix Blame Parent & Context for working copy lines.
Date: Mon, 8 Sep 2008 11:18:52 +0400	[thread overview]
Message-ID: <200809081118.52705.angavrilov@gmail.com> (raw)

Make Blame Parent Commit and Show History Context work
properly for lines blamed on the working copy.

Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>
---

	Currently it displays an ugly error box.

	-- Alexander

 git-gui.sh    |    3 +++
 lib/blame.tcl |   29 ++++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index 57a0c34..f249b0b 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1061,6 +1061,9 @@ set current_diff_path {}
 set is_3way_diff 0
 set selected_commit_type new
 
+set nullid "0000000000000000000000000000000000000000"
+set nullid2 "0000000000000000000000000000000000000001"
+
 ######################################################################
 ##
 ## task management
diff --git a/lib/blame.tcl b/lib/blame.tcl
index b5fc9fa..84d55b5 100644
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
@@ -939,9 +939,20 @@ method _format_offset_date {base offset} {
 }
 
 method _gitkcommit {} {
+	global nullid
+
 	set dat [_get_click_amov_info $this]
 	if {$dat ne {}} {
 		set cmit [lindex $dat 0]
+
+		# If the line belongs to the working copy, use HEAD instead
+		if {$cmit eq $nullid} {
+			if {[catch {set cmit [git rev-parse --verify HEAD]} err]} {
+				error_popup [strcat [mc "Cannot find HEAD commit:"] "\n\n$err"]
+				return;
+			}
+		}
+
 		set radius [get_config gui.blamehistoryctx]
 		set cmdline [list --select-commit=$cmit]
 
@@ -978,12 +989,20 @@ method _gitkcommit {} {
 }
 
 method _blameparent {} {
+	global nullid
+
 	set dat [_get_click_amov_info $this]
 	if {$dat ne {}} {
 		set cmit [lindex $dat 0]
 		set new_path [lindex $dat 1]
 
-		if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
+		# Allow using Blame Parent on lines modified in the working copy
+		if {$cmit eq $nullid} {
+			set parent_ref "HEAD"
+		} else {
+			set parent_ref "$cmit^"
+		}
+		if {[catch {set cparent [git rev-parse --verify $parent_ref]} err]} {
 			error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
 			return;
 		}
@@ -993,8 +1012,12 @@ method _blameparent {} {
 		# Generate a diff between the commit and its parent,
 		# and use the hunks to update the line number.
 		# Request zero context to simplify calculations.
-		if {[catch {set fd [eval git_read diff-tree \
-				--unified=0 $cparent $cmit $new_path]} err]} {
+		if {$cmit eq $nullid} {
+			set diffcmd [list diff-index --unified=0 $cparent -- $new_path]
+		} else {
+			set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
+		}
+		if {[catch {set fd [eval git_read $diffcmd]} err]} {
 			$status stop [mc "Unable to display parent"]
 			error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
 			return
-- 
1.6.0.20.g6148bc

                 reply	other threads:[~2008-09-08  7:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200809081118.52705.angavrilov@gmail.com \
    --to=angavrilov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).