diff --git a/gitk b/gitk
index b61e138268f..9c435873f90 100755
--- a/gitk
+++ b/gitk
@@ -1304,17 +1304,21 @@ proc drawparentlinks {id row col olds} {
     # rmx = right-most X coord used
     set rmx 0
     foreach p $olds {
+	set i [lsearch -exact $ids $p]
+	if {$i < 0} {
+	    puts "oops, parent $p of $id not in list"
+	    continue
+	}
+	set x2 [xc $row2 $i]
+	if {$x2 > $rmx} {
+	    set rmx $x2
+	}
 	if {[info exists idrowranges($p)] &&
 	    $row2 == [lindex $idrowranges($p) 0] &&
 	    $row2 < [lindex $idrowranges($p) 1]} {
 	    # drawlineseg will do this one for us
 	    continue
 	}
-	set i [lsearch -exact $ids $p]
-	if {$i < 0} {
-	    puts "oops, parent $p of $id not in list"
-	    continue
-	}
 	assigncolor $p
 	# should handle duplicated parents here...
 	set coords [list $x $y]
@@ -1323,10 +1327,6 @@ proc drawparentlinks {id row col olds} {
 	} elseif {$i > $col + 1} {
 	    lappend coords [xc $row [expr {$i - 1}]] $y
 	}
-	set x2 [xc $row2 $i]
-	if {$x2 > $rmx} {
-	    set rmx $x2
-	}
 	lappend coords $x2 $y2
 	set t [$canv create line $coords -width [linewidth $p] \
 		   -fill $colormap($p) -tags lines.$p]