git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/7] gitk: Allow starting gui blame for a specific line.

From
Alexander Gavrilov <angavrilov@gmail.com>
Date
Oct 25, 2008, 16:45 UTC
Message-ID
<200810252045.54010.angavrilov@gmail.com>
In-Reply-To
<18691.2467.601039.480382@cargo.ozlabs.ibm.com>
On Saturday 25 October 2008 15:57:23 Paul Mackerras wrote:
Show 13 quoted lines
> > +    # Now scan the lines to determine offset within the hunk
> > +    set parent {}
> > +    set dline 0
> > +    set s_lno [lindex [split $s_lix "."] 0]
> > +
> > +    for {set i $line} {$i > $s_lno} {incr i -1} {
> > +	set c_line [$ctext get $i.0 "$i.0 + 1 lines"]
> > +	# Determine if the line is removed
> > +	set chunk [string range $c_line 0 [llength $base_lines]-2]
> 
> You need an [expr]:
> 
> set chunk [string range $c_line 0 [expr {[llength $base_lines] - 2}]]
Ugh. I guess I'll have to install docs from Tcl 8.4...
 
Show 21 quoted lines
> > +	set removed_idx [string first "-" $chunk]
> > +	# Choose a parent index
> > +	if {$parent eq {}} {
> > +	    if {$removed_idx >= 0} {
> > +		set parent $removed_idx
> > +		incr parent
> > +	    } else {
> > +		set unchanged_idx [string first " " $chunk]
> > +		if {$unchanged_idx >= 0} {
> > +		    set parent $unchanged_idx
> > +		    incr parent
> > +		} else {
> > +		    # blame the current commit
> > +		    set parent 0
> > +		}
> > +	    }
> > +	}
> 
> I like this better than the previous version, but it would turn out a
> bit simpler if you use parent = -1 to indicate that we're blaming the
> current commit, and then increment it right at the end.
Yes, it's probably better to apply the following fixup.
Alexander
diff --git a/gitk b/gitk
index 6fbd6bb..68f07c2 100755
--- a/gitk
+++ b/gitk
@@ -3160,33 +3160,32 @@ proc find_hunk_blamespec {base line} {
 
     # Now scan the lines to determine offset within the hunk
     set parent {}
+    set max_parent [expr {[llength $base_lines]-2}]
     set dline 0
     set s_lno [lindex [split $s_lix "."] 0]
 
     for {set i $line} {$i > $s_lno} {incr i -1} {
 	set c_line [$ctext get $i.0 "$i.0 + 1 lines"]
 	# Determine if the line is removed
-	set chunk [string range $c_line 0 [llength $base_lines]-2]
+	set chunk [string range $c_line 0 $max_parent]
 	set removed_idx [string first "-" $chunk]
 	# Choose a parent index
 	if {$parent eq {}} {
 	    if {$removed_idx >= 0} {
 		set parent $removed_idx
-		incr parent
 	    } else {
 		set unchanged_idx [string first " " $chunk]
 		if {$unchanged_idx >= 0} {
 		    set parent $unchanged_idx
-		    incr parent
 		} else {
 		    # blame the current commit
-		    set parent 0
+		    set parent -1
 		}
 	    }
 	}
 	# then count other lines that belong to it
-	if {$parent > 0} {
-	    set code [string index $c_line $parent-1]
+	if {$parent >= 0} {
+	    set code [string index $c_line $parent]
 	    if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
 		incr dline
 	    }
@@ -3197,7 +3196,8 @@ proc find_hunk_blamespec {base line} {
 	}
     }
 
-    if {$parent eq {}} { set parent 0 }
+    if {$parent eq {}} { set parent -1 }
+    incr parent
     incr dline [lindex $base_lines $parent]
     return [list $parent $dline]
 }
Previous: Paul MackerrasNext: Paul Mackerras
Message 18 of 26 in “gitk: UI enhancements”
  1. 0/7 gitk: UI enhancementsAlexander Gavrilov, Oct 8, 2008
  2. 1/7 gitk: Enhance UI popup and accelerator handling.Alexander Gavrilov, Oct 8, 2008
  3. 2/7 gitk: Allow forcing branch creation if it already exists.Alexander Gavrilov, Oct 8, 2008
  4. 3/7 gitk: Allow starting gui blame for a specific line.Alexander Gavrilov, Oct 8, 2008
  5. 4/7 gitk: Fix file list context menu for merge commits.Alexander Gavrilov, Oct 8, 2008
  6. 5/7 gitk: Make cherry-pick call git-citool on conflicts.Alexander Gavrilov, Oct 8, 2008
  7. 6/7 gitk: Implement a user-friendly Edit View dialog.Alexander Gavrilov, Oct 8, 2008
  8. 7/7 gitk: Explicitly position popup windows.Alexander Gavrilov, Oct 8, 2008
  9. Paul MackerrasOct 21, 2008
  10. Alexander GavrilovOct 21, 2008
  11. Paul MackerrasOct 9, 2008
  12. Alexander GavrilovOct 9, 2008
  13. Paul MackerrasOct 9, 2008
  14. Paul MackerrasOct 21, 2008
  15. Paul MackerrasOct 23, 2008
  16. Alexander GavrilovOct 24, 2008
  17. Paul MackerrasOct 25, 2008
  18. Alexander GavrilovOct 25, 2008
  19. Paul MackerrasOct 26, 2008
  20. Paul MackerrasOct 21, 2008
  21. Paul MackerrasOct 9, 2008
  22. Alexander GavrilovOct 9, 2008
  23. Paul MackerrasOct 9, 2008
  24. Paul MackerrasOct 16, 2008
  25. Alexander GavrilovOct 16, 2008
  26. Paul MackerrasOct 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.