From: Alexander Gavrilov <angavrilov@gmail.com>
To: Paul Mackerras <paulus@samba.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/7] gitk: Allow starting gui blame for a specific line.
Date: Sat, 25 Oct 2008 20:45:53 +0400 [thread overview]
Message-ID: <200810252045.54010.angavrilov@gmail.com> (raw)
In-Reply-To: <18691.2467.601039.480382@cargo.ozlabs.ibm.com>
On Saturday 25 October 2008 15:57:23 Paul Mackerras wrote:
> > + # 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...
> > + 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]
}
next prev parent reply other threads:[~2008-10-25 16:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-08 7:05 [PATCH 0/7] gitk: UI enhancements Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 1/7] gitk: Enhance UI popup and accelerator handling Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 2/7] gitk: Allow forcing branch creation if it already exists Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 3/7] gitk: Allow starting gui blame for a specific line Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 4/7] gitk: Fix file list context menu for merge commits Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 5/7] gitk: Make cherry-pick call git-citool on conflicts Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 6/7] gitk: Implement a user-friendly Edit View dialog Alexander Gavrilov
2008-10-08 7:05 ` [PATCH 7/7] gitk: Explicitly position popup windows Alexander Gavrilov
2008-10-21 11:41 ` Paul Mackerras
2008-10-21 12:52 ` Alexander Gavrilov
2008-10-09 7:42 ` [PATCH 5/7] gitk: Make cherry-pick call git-citool on conflicts Paul Mackerras
2008-10-09 8:24 ` Alexander Gavrilov
2008-10-09 10:57 ` Paul Mackerras
2008-10-21 11:39 ` [PATCH 4/7] gitk: Fix file list context menu for merge commits Paul Mackerras
2008-10-23 11:58 ` [PATCH 3/7] gitk: Allow starting gui blame for a specific line Paul Mackerras
2008-10-24 8:13 ` Alexander Gavrilov
2008-10-25 11:57 ` Paul Mackerras
2008-10-25 16:45 ` Alexander Gavrilov [this message]
2008-10-26 3:58 ` Paul Mackerras
2008-10-21 11:38 ` [PATCH 2/7] gitk: Allow forcing branch creation if it already exists Paul Mackerras
2008-10-09 0:27 ` [PATCH 1/7] gitk: Enhance UI popup and accelerator handling Paul Mackerras
2008-10-09 8:12 ` Alexander Gavrilov
2008-10-09 11:02 ` Paul Mackerras
2008-10-16 21:55 ` Paul Mackerras
2008-10-16 22:08 ` Alexander Gavrilov
2008-10-21 11:35 ` Paul Mackerras
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=200810252045.54010.angavrilov@gmail.com \
--to=angavrilov@gmail.com \
--cc=git@vger.kernel.org \
--cc=paulus@samba.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).