Skip to contentSkip to conversation

gitk: fix a corner case when switching views

PATCH New Michele Ballabio 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitk: fix a corner case when switching views

Switching from a view that shows no commit ("No commits selected") to another view, back and forth, can trigger an error like:

can't read "yscreen": no such variable
can't read "yscreen": no such variable
while executing
"expr {[yc $row] - $yscreen}"
(procedure "showview" line 91)
invoked from within
"showview 2"
invoked from within
".#bar.#bar#view invoke active"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list $w invoke active]"
(procedure "tk::MenuInvoke" line 50)
invoked from within
"tk::MenuInvoke .#bar.#bar#view 1"
(command bound to event)

This patch avoids this with a check on yscreen and ytop in procedure showview.

---
 gitk |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
gitk +8 -4
index f1f21e9..371654f 100755
@@ -2124,11 +2124,15 @@ proc showview {n} {
 	set row $commitrow($n,$selid)
 	# try to get the selected row in the same position on the screen
 	set ymax [lindex [$canv cget -scrollregion] 3]
-	set ytop [expr {[yc $row] - $yscreen}]
-	if {$ytop < 0} {
-	    set ytop 0
+	if {[info exists yscreen]} {
+	    set ytop [expr {[yc $row] - $yscreen}]
+	}
+	if {[info exists ytop]} {
+	    if {$ytop < 0} {
+		set ytop 0
+	    }
+	    set yf [expr {$ytop * 1.0 / $ymax}]
 	}
-	set yf [expr {$ytop * 1.0 / $ymax}]
     }
     allcanvs yview moveto $yf
     drawvisible
Signature · 1 line
1.5.4.3