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

[PATCH] gitk: fix a corner case when switching views

From
Michele Ballabio <barra_cuda@katamail.com>
Date
Mar 3, 2008, 19:59 UTC
Message-ID
<200803032059.52960.barra_cuda@katamail.com>

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.

Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
 gitk |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/gitk b/gitk
index f1f21e9..371654f 100755
--- a/gitk
+++ b/gitk
@@ -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
-- 
1.5.4.3
Message 1 of 1 in “gitk: fix a corner case when switching views”
  1. gitk: fix a corner case when switching viewsMichele Ballabio, Mar 3, 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.