Code

Merge branch 'master' into dev
[git.git] / gitk
diff --git a/gitk b/gitk
index 86dd575ca71655606c1be4293d0bcd6e0cdb34ef..0dacfdadf1b17df160718b53ef39f441cd53515c 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -170,9 +170,17 @@ proc updatecommits {} {
     global curview viewargs viewfiles viewincl viewinstances
     global viewactive viewcomplete loginstance tclencoding mainheadid
     global varcid startmsecs commfd showneartags showlocalchanges leftover
+    global mainheadid
 
-    if {$showlocalchanges && [commitinview $mainheadid $curview]} {
-       dodiffindex
+    set oldmainid $mainheadid
+    rereadrefs
+    if {$showlocalchanges} {
+       if {$mainheadid ne $oldmainid} {
+           dohidelocalchanges
+       }
+       if {[commitinview $mainheadid $curview]} {
+           dodiffindex
+       }
     }
     set view $curview
     set commits [exec git rev-parse --default HEAD --revs-only \
@@ -218,8 +226,6 @@ proc updatecommits {} {
     incr viewactive($view)
     set viewcomplete($view) 0
     nowbusy $view "Reading"
-    readrefs
-    changedrefs
     if {$showneartags} {
        getallcommits
     }
@@ -228,7 +234,7 @@ proc updatecommits {} {
 proc reloadcommits {} {
     global curview viewcomplete selectedline currentid thickerline
     global showneartags treediffs commitinterest cached_commitrow
-    global progresscoords
+    global progresscoords targetid
 
     if {!$viewcomplete($curview)} {
        stop_rev_list $curview
@@ -248,6 +254,7 @@ proc reloadcommits {} {
     clear_display
     catch {unset commitinterest}
     catch {unset cached_commitrow}
+    catch {unset targetid}
     setcanvscroll
     getcommits
 }
@@ -455,8 +462,8 @@ proc renumbervarc {a v} {
            set tok $oldtok
        }
        set ka 0
-       if {[llength $children($v,$id)] > 0} {
-           set kid [lindex $children($v,$id) end]
+       set kid [last_real_child $v,$id]
+       if {$kid ne {}} {
            set k $varcid($v,$kid)
            if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
                set ki $kid
@@ -555,7 +562,7 @@ proc fix_reversal {p a v} {
 
 proc insertrow {id p v} {
     global varcid varccommits parents children cmitlisted
-    global commitidx varctok vtokmod
+    global commitidx varctok vtokmod targetid targetrow
 
     set a $varcid($v,$p)
     set i [lsearch -exact $varccommits($v,$a) $p]
@@ -574,12 +581,18 @@ proc insertrow {id p v} {
     if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
        modify_arc $v $a $i
     }
+    if {[info exists targetid]} {
+       if {![comes_before $targetid $p]} {
+           incr targetrow
+       }
+    }
     drawvisible
 }
 
 proc removerow {id v} {
     global varcid varccommits parents children commitidx
-    global varctok vtokmod cmitlisted
+    global varctok vtokmod cmitlisted currentid selectedline
+    global targetid
 
     if {[llength $parents($v,$id)] != 1} {
        puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
@@ -605,9 +618,40 @@ proc removerow {id v} {
     if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
        modify_arc $v $a $i
     }
+    if {[info exist currentid] && $id eq $currentid} {
+       unset currentid
+       unset selectedline
+    }
+    if {[info exists targetid] && $targetid eq $id} {
+       set targetid $p
+    }
     drawvisible
 }
 
+proc first_real_child {vp} {
+    global children nullid nullid2
+
+    foreach id $children($vp) {
+       if {$id ne $nullid && $id ne $nullid2} {
+           return $id
+       }
+    }
+    return {}
+}
+
+proc last_real_child {vp} {
+    global children nullid nullid2
+
+    set kids $children($vp)
+    for {set i [llength $kids]} {[incr i -1] >= 0} {} {
+       set id [lindex $kids $i]
+       if {$id ne $nullid && $id ne $nullid2} {
+           return $id
+       }
+    }
+    return {}
+}
+
 proc vtokcmp {v a b} {
     global varctok varcid
 
@@ -617,7 +661,6 @@ proc vtokcmp {v a b} {
 
 proc modify_arc {v a {lim {}}} {
     global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
-    global vhighlights nhighlights fhighlights rhighlights
 
     set vtokmod($v) [lindex $varctok($v) $a]
     set varcmod($v) $a
@@ -636,10 +679,6 @@ proc modify_arc {v a {lim {}}} {
        set vrowmod($v) $r
        undolayout $r
     }
-    catch {unset nhighlights}
-    catch {unset fhighlights}
-    catch {unset vhighlights}
-    catch {unset rhighlights}
 }
 
 proc update_arcrows {v} {
@@ -724,18 +763,18 @@ proc rowofcommit {id} {
     global varcid varccommits varcrow curview cached_commitrow
     global varctok vtokmod
 
-    if {[info exists cached_commitrow($id)]} {
-       return $cached_commitrow($id)
-    }
     set v $curview
     if {![info exists varcid($v,$id)]} {
        puts "oops rowofcommit no arc for [shortids $id]"
        return {}
     }
     set a $varcid($v,$id)
-    if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] > 0} {
+    if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
        update_arcrows $v
     }
+    if {[info exists cached_commitrow($id)]} {
+       return $cached_commitrow($id)
+    }
     set i [lsearch -exact $varccommits($v,$a) $id]
     if {$i < 0} {
        puts "oops didn't find commit [shortids $id] in arc $a"
@@ -746,6 +785,22 @@ proc rowofcommit {id} {
     return $i
 }
 
+# Returns 1 if a is on an earlier row than b, otherwise 0
+proc comes_before {a b} {
+    global varcid varctok curview
+
+    set v $curview
+    if {$a eq $b || ![info exists varcid($v,$a)] || \
+           ![info exists varcid($v,$b)]} {
+       return 0
+    }
+    if {$varcid($v,$a) != $varcid($v,$b)} {
+       return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
+                          [lindex $varctok($v) $varcid($v,$b)]] < 0}]
+    }
+    return [expr {[rowofcommit $a] < [rowofcommit $b]}]
+}
+
 proc bsearch {l elt} {
     if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
        return 0
@@ -1288,8 +1343,21 @@ proc confirm_popup msg {
     return $confirm_ok
 }
 
+proc setoptions {} {
+    option add *Panedwindow.showHandle 1 startupFile
+    option add *Panedwindow.sashRelief raised startupFile
+    option add *Button.font uifont startupFile
+    option add *Checkbutton.font uifont startupFile
+    option add *Radiobutton.font uifont startupFile
+    option add *Menu.font uifont startupFile
+    option add *Menubutton.font uifont startupFile
+    option add *Label.font uifont startupFile
+    option add *Message.font uifont startupFile
+    option add *Entry.font uifont startupFile
+}
+
 proc makewindow {} {
-    global canv canv2 canv3 linespc charspc ctext cflist
+    global canv canv2 canv3 linespc charspc ctext cflist cscroll
     global tabstop
     global findtype findtypemenu findloc findstring fstring geometry
     global entries sha1entry sha1string sha1but
@@ -1306,20 +1374,17 @@ proc makewindow {} {
 
     menu .bar
     .bar add cascade -label [mc "File"] -menu .bar.file
-    .bar configure -font uifont
     menu .bar.file
     .bar.file add command -label [mc "Update"] -command updatecommits
     .bar.file add command -label [mc "Reload"] -command reloadcommits
     .bar.file add command -label [mc "Reread references"] -command rereadrefs
     .bar.file add command -label [mc "List references"] -command showrefs
     .bar.file add command -label [mc "Quit"] -command doquit
-    .bar.file configure -font uifont
     menu .bar.edit
     .bar add cascade -label [mc "Edit"] -menu .bar.edit
     .bar.edit add command -label [mc "Preferences"] -command doprefs
-    .bar.edit configure -font uifont
 
-    menu .bar.view -font uifont
+    menu .bar.view
     .bar add cascade -label [mc "View"] -menu .bar.view
     .bar.view add command -label [mc "New view..."] -command {newview 0}
     .bar.view add command -label [mc "Edit view..."] -command editview \
@@ -1333,7 +1398,7 @@ proc makewindow {} {
     .bar add cascade -label [mc "Help"] -menu .bar.help
     .bar.help add command -label [mc "About gitk"] -command about
     .bar.help add command -label [mc "Key bindings"] -command keys
-    .bar.help configure -font uifont
+    .bar.help configure
     . configure -menu .bar
 
     # the gui has upper and lower half, parts of a paned window.
@@ -1390,7 +1455,7 @@ proc makewindow {} {
     set entries $sha1entry
     set sha1but .tf.bar.sha1label
     button $sha1but -text [mc "SHA1 ID: "] -state disabled -relief flat \
-       -command gotocommit -width 8 -font uifont
+       -command gotocommit -width 8
     $sha1but conf -disabledforeground [$sha1but cget -foreground]
     pack .tf.bar.sha1label -side left
     entry $sha1entry -width 40 -font textfont -textvariable sha1string
@@ -1422,7 +1487,7 @@ proc makewindow {} {
 
     # Status label and progress bar
     set statusw .tf.bar.status
-    label $statusw -width 15 -relief sunken -font uifont
+    label $statusw -width 15 -relief sunken
     pack $statusw -side left -padx 5
     set h [expr {[font metrics uifont -linespace] + 2}]
     set progresscanv .tf.bar.progress
@@ -1439,10 +1504,10 @@ proc makewindow {} {
     set progupdatepending 0
 
     # build up the bottom bar of upper window
-    label .tf.lbar.flabel -text "[mc "Find"] " -font uifont
-    button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1} -font uifont
-    button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1} -font uifont
-    label .tf.lbar.flab2 -text " [mc "commit"] " -font uifont
+    label .tf.lbar.flabel -text "[mc "Find"] "
+    button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1}
+    button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1}
+    label .tf.lbar.flab2 -text " [mc "commit"] "
     pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
        -side left -fill y
     set gdttype [mc "containing:"]
@@ -1451,8 +1516,6 @@ proc makewindow {} {
                [mc "touching paths:"] \
                [mc "adding/removing string:"]]
     trace add variable gdttype write gdttype_change
-    $gm conf -font uifont
-    .tf.lbar.gdttype conf -font uifont
     pack .tf.lbar.gdttype -side left -fill y
 
     set findstring {}
@@ -1464,14 +1527,10 @@ proc makewindow {} {
     set findtypemenu [tk_optionMenu .tf.lbar.findtype \
                      findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
     trace add variable findtype write findcom_change
-    .tf.lbar.findtype configure -font uifont
-    .tf.lbar.findtype.menu configure -font uifont
     set findloc [mc "All fields"]
     tk_optionMenu .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
        [mc "Comments"] [mc "Author"] [mc "Committer"]
     trace add variable findloc write find_change
-    .tf.lbar.findloc configure -font uifont
-    .tf.lbar.findloc.menu configure -font uifont
     pack .tf.lbar.findloc -side right
     pack .tf.lbar.findtype -side right
     pack $fstring -side left -expand 1 -fill x
@@ -1498,22 +1557,20 @@ proc makewindow {} {
     frame .bleft.top
     frame .bleft.mid
 
-    button .bleft.top.search -text [mc "Search"] -command dosearch \
-       -font uifont
+    button .bleft.top.search -text [mc "Search"] -command dosearch
     pack .bleft.top.search -side left -padx 5
     set sstring .bleft.top.sstring
     entry $sstring -width 20 -font textfont -textvariable searchstring
     lappend entries $sstring
     trace add variable searchstring write incrsearch
     pack $sstring -side left -expand 1 -fill x
-    radiobutton .bleft.mid.diff -text [mc "Diff"] -font uifont \
+    radiobutton .bleft.mid.diff -text [mc "Diff"] \
        -command changediffdisp -variable diffelide -value {0 0}
-    radiobutton .bleft.mid.old -text [mc "Old version"] -font uifont \
+    radiobutton .bleft.mid.old -text [mc "Old version"] \
        -command changediffdisp -variable diffelide -value {0 1}
-    radiobutton .bleft.mid.new -text [mc "New version"] -font uifont \
+    radiobutton .bleft.mid.new -text [mc "New version"] \
        -command changediffdisp -variable diffelide -value {1 0}
-    label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: " \
-       -font uifont
+    label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: "
     pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
     spinbox .bleft.mid.diffcontext -width 5 -font textfont \
        -from 1 -increment 1 -to 10000000 \
@@ -1573,10 +1630,8 @@ proc makewindow {} {
     frame .bright.mode
     radiobutton .bright.mode.patch -text [mc "Patch"] \
        -command reselectline -variable cmitmode -value "patch"
-    .bright.mode.patch configure -font uifont
     radiobutton .bright.mode.tree -text [mc "Tree"] \
        -command reselectline -variable cmitmode -value "tree"
-    .bright.mode.tree configure -font uifont
     grid .bright.mode.patch .bright.mode.tree -sticky ew
     pack .bright.mode -side top -fill x
     set cflist .bright.cfiles
@@ -1764,7 +1819,7 @@ proc canvscan {op w x y} {
 
 proc scrollcanv {cscroll f0 f1} {
     $cscroll set $f0 $f1
-    drawfrac $f0 $f1
+    drawvisible
     flushhighlights
 }
 
@@ -1962,17 +2017,14 @@ Copyright © 2005-2006 Paul Mackerras
 Use and redistribute under the terms of the GNU General Public License"] \
            -justify center -aspect 400 -border 2 -bg white -relief groove
     pack $w.m -side top -fill x -padx 2 -pady 2
-    $w.m configure -font uifont
     button $w.ok -text [mc "Close"] -command "destroy $w" -default active
     pack $w.ok -side bottom
-    $w.ok configure -font uifont
     bind $w <Visibility> "focus $w.ok"
     bind $w <Key-Escape> "destroy $w"
     bind $w <Key-Return> "destroy $w"
 }
 
 proc keys {} {
-    global uifont
     set w .keys
     if {[winfo exists $w]} {
        raise $w
@@ -2026,10 +2078,8 @@ f                Scroll diff view to next file
 "] \
            -justify left -bg white -border 2 -relief groove
     pack $w.m -side top -fill both -padx 2 -pady 2
-    $w.m configure -font uifont
     button $w.ok -text [mc "Close"] -command "destroy $w" -default active
     pack $w.ok -side bottom
-    $w.ok configure -font uifont
     bind $w <Visibility> "focus $w.ok"
     bind $w <Key-Escape> "destroy $w"
     bind $w <Key-Return> "destroy $w"
@@ -2524,7 +2574,7 @@ proc shellsplit {str} {
 # Code to implement multiple views
 
 proc newview {ishighlight} {
-    global nextviewnum newviewname newviewperm uifont newishighlight
+    global nextviewnum newviewname newviewperm newishighlight
     global newviewargs revtreeargs
 
     set newishighlight $ishighlight
@@ -2556,27 +2606,26 @@ proc editview {} {
 }
 
 proc vieweditor {top n title} {
-    global newviewname newviewperm viewfiles
-    global uifont
+    global newviewname newviewperm viewfiles bgcolor
 
     toplevel $top
     wm title $top $title
-    label $top.nl -text [mc "Name"] -font uifont
-    entry $top.name -width 20 -textvariable newviewname($n) -font uifont
+    label $top.nl -text [mc "Name"]
+    entry $top.name -width 20 -textvariable newviewname($n)
     grid $top.nl $top.name -sticky w -pady 5
-    checkbutton $top.perm -text [mc "Remember this view"] -variable newviewperm($n) \
-       -font uifont
+    checkbutton $top.perm -text [mc "Remember this view"] \
+       -variable newviewperm($n)
     grid $top.perm - -pady 5 -sticky w
-    message $top.al -aspect 1000 -font uifont \
+    message $top.al -aspect 1000 \
        -text [mc "Commits to include (arguments to git rev-list):"]
     grid $top.al - -sticky w -pady 5
     entry $top.args -width 50 -textvariable newviewargs($n) \
-       -background white -font uifont
+       -background $bgcolor
     grid $top.args - -sticky ew -padx 5
-    message $top.l -aspect 1000 -font uifont \
+    message $top.l -aspect 1000 \
        -text [mc "Enter files and directories to include, one per line:"]
     grid $top.l - -sticky w
-    text $top.t -width 40 -height 10 -background white -font uifont
+    text $top.t -width 40 -height 10 -background $bgcolor -font uifont
     if {[info exists viewfiles($n)]} {
        foreach f $viewfiles($n) {
            $top.t insert end $f
@@ -2587,10 +2636,8 @@ proc vieweditor {top n title} {
     }
     grid $top.t - -sticky ew -padx 5
     frame $top.buts
-    button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n] \
-       -font uifont
-    button $top.buts.can -text [mc "Cancel"] -command [list destroy $top] \
-       -font uifont
+    button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
+    button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
     grid $top.buts.ok $top.buts.can
     grid columnconfigure $top.buts 0 -weight 1 -uniform a
     grid columnconfigure $top.buts 1 -weight 1 -uniform a
@@ -2798,20 +2845,20 @@ proc showview {n} {
 
 # Stuff relating to the highlighting facility
 
-proc ishighlighted {row} {
+proc ishighlighted {id} {
     global vhighlights fhighlights nhighlights rhighlights
 
-    if {[info exists nhighlights($row)] && $nhighlights($row) > 0} {
-       return $nhighlights($row)
+    if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
+       return $nhighlights($id)
     }
-    if {[info exists vhighlights($row)] && $vhighlights($row) > 0} {
-       return $vhighlights($row)
+    if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
+       return $vhighlights($id)
     }
-    if {[info exists fhighlights($row)] && $fhighlights($row) > 0} {
-       return $fhighlights($row)
+    if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
+       return $fhighlights($id)
     }
-    if {[info exists rhighlights($row)] && $rhighlights($row) > 0} {
-       return $rhighlights($row)
+    if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
+       return $rhighlights($id)
     }
     return 0
 }
@@ -2849,7 +2896,7 @@ proc unbolden {} {
 
     set stillbold {}
     foreach row $boldrows {
-       if {![ishighlighted $row]} {
+       if {![ishighlighted [commitonrow $row]]} {
            bolden $row mainfont
        } else {
            lappend stillbold $row
@@ -2859,7 +2906,7 @@ proc unbolden {} {
 }
 
 proc addvhighlight {n} {
-    global hlview viewcomplete curview vhl_done vhighlights commitidx
+    global hlview viewcomplete curview vhl_done commitidx
 
     if {[info exists hlview]} {
        delvhighlight
@@ -2898,7 +2945,7 @@ proc vhighlightmore {} {
                if {![highlighted $row]} {
                    bolden $row mainfontbold
                }
-               set vhighlights($row) 1
+               set vhighlights($id) 1
            }
        }
     }
@@ -2909,12 +2956,12 @@ proc askvhighlight {row id} {
     global hlview vhighlights iddrawn
 
     if {[commitinview $id $hlview]} {
-       if {[info exists iddrawn($id)] && ![ishighlighted $row]} {
+       if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
            bolden $row mainfontbold
        }
-       set vhighlights($row) 1
+       set vhighlights($id) 1
     } else {
-       set vhighlights($row) 0
+       set vhighlights($id) 0
     }
 }
 
@@ -3052,7 +3099,7 @@ proc askfilehighlight {row id} {
     global filehighlight fhighlights fhl_list
 
     lappend fhl_list $id
-    set fhighlights($row) -1
+    set fhighlights($id) -1
     puts $filehighlight $id
 }
 
@@ -3070,18 +3117,16 @@ proc readfhighlight {} {
        if {$i < 0} continue
        for {set j 0} {$j < $i} {incr j} {
            set id [lindex $fhl_list $j]
-           if {[commitinview $id $curview]} {
-               set fhighlights([rowofcommit $id]) 0
-           }
+           set fhighlights($id) 0
        }
        set fhl_list [lrange $fhl_list [expr {$i+1}] end]
        if {$line eq {}} continue
        if {![commitinview $line $curview]} continue
        set row [rowofcommit $line]
-       if {[info exists iddrawn($line)] && ![ishighlighted $row]} {
+       if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
            bolden $row mainfontbold
        }
-       set fhighlights($row) 1
+       set fhighlights($line) 1
     }
     if {[eof $filehighlight]} {
        # strange...
@@ -3130,7 +3175,7 @@ proc askfindhighlight {row id} {
        }
     }
     if {$isbold && [info exists iddrawn($id)]} {
-       if {![ishighlighted $row]} {
+       if {![ishighlighted $id]} {
            bolden $row mainfontbold
            if {$isbold > 1} {
                bolden_name $row mainfontbold
@@ -3140,7 +3185,7 @@ proc askfindhighlight {row id} {
            markrowmatches $row $id
        }
     }
-    set nhighlights($row) $isbold
+    set nhighlights($id) $isbold
 }
 
 proc markrowmatches {row id} {
@@ -3178,7 +3223,7 @@ proc vrel_change {name ix op} {
 # prepare for testing whether commits are descendents or ancestors of a
 proc rhighlight_sel {a} {
     global descendent desc_todo ancestor anc_todo
-    global highlight_related rhighlights
+    global highlight_related
 
     catch {unset descendent}
     set desc_todo [list $a]
@@ -3285,11 +3330,11 @@ proc askrelhighlight {row id} {
        }
     }
     if {[info exists iddrawn($id)]} {
-       if {$isbold && ![ishighlighted $row]} {
+       if {$isbold && ![ishighlighted $id]} {
            bolden $row mainfontbold
        }
     }
-    set rhighlights($row) $isbold
+    set rhighlights($id) $isbold
 }
 
 # Graph layout functions
@@ -3340,17 +3385,12 @@ proc ordertoken {id} {
            set tok $ordertok($p)
            break
        }
-       if {[llength $children($curview,$p)] == 0} {
+       set id [first_real_child $curview,$p]
+       if {$id eq {}} {
            # it's a root
            set tok [lindex $varctok($curview) $a]
            break
        }
-       set id [lindex $children($curview,$p) 0]
-       if {$id eq $nullid || $id eq $nullid2} {
-           # XXX treat it as a root
-           set tok [lindex $varctok($curview) $a]
-           break
-       }
        if {[llength $parents($curview,$id)] == 1} {
            lappend todo [list $p {}]
        } else {
@@ -3515,7 +3555,7 @@ proc dodiffindex {} {
 }
 
 proc readdiffindex {fd serial} {
-    global mainheadid nullid2 curview commitinfo commitdata lserial
+    global mainheadid nullid nullid2 curview commitinfo commitdata lserial
 
     set isdiff 1
     if {[gets $fd line] < 0} {
@@ -3541,6 +3581,9 @@ proc readdiffindex {fd serial} {
        set hl [mc "Local changes checked in to index but not committed"]
        set commitinfo($nullid2) [list  $hl {} {} {} {} "    $hl\n"]
        set commitdata($nullid2) "\n    $hl\n"
+       if {[commitinview $nullid $curview]} {
+           removerow $nullid $curview
+       }
        insertrow $nullid2 $mainheadid $curview
     } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
        removerow $nullid2 $curview
@@ -4358,7 +4401,7 @@ proc drawcmittext {id row col} {
     set date [formatdate $date]
     set font mainfont
     set nfont mainfont
-    set isbold [ishighlighted $row]
+    set isbold [ishighlighted $id]
     if {$isbold > 0} {
        lappend boldrows $row
        set font mainfontbold
@@ -4395,16 +4438,16 @@ proc drawcmitrow {row} {
     if {$row >= $numcommits} return
 
     set id [lindex $displayorder $row]
-    if {[info exists hlview] && ![info exists vhighlights($row)]} {
+    if {[info exists hlview] && ![info exists vhighlights($id)]} {
        askvhighlight $row $id
     }
-    if {[info exists filehighlight] && ![info exists fhighlights($row)]} {
+    if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
        askfilehighlight $row $id
     }
-    if {$findpattern ne {} && ![info exists nhighlights($row)]} {
+    if {$findpattern ne {} && ![info exists nhighlights($id)]} {
        askfindhighlight $row $id
     }
-    if {$highlight_related ne [mc "None"] && ![info exists rhighlights($row)]} {
+    if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
        askrelhighlight $row $id
     }
     if {![info exists iddrawn($id)]} {
@@ -4525,23 +4568,59 @@ proc undolayout {row} {
     }
 }
 
-proc drawfrac {f0 f1} {
-    global canv linespc
+proc drawvisible {} {
+    global canv linespc curview vrowmod selectedline targetrow targetid
+    global need_redisplay cscroll numcommits
 
+    set fs [$canv yview]
     set ymax [lindex [$canv cget -scrollregion] 3]
     if {$ymax eq {} || $ymax == 0} return
+    set f0 [lindex $fs 0]
+    set f1 [lindex $fs 1]
     set y0 [expr {int($f0 * $ymax)}]
-    set row [expr {int(($y0 - 3) / $linespc) - 1}]
     set y1 [expr {int($f1 * $ymax)}]
+
+    if {[info exists targetid]} {
+       if {[commitinview $targetid $curview]} {
+           set r [rowofcommit $targetid]
+           if {$r != $targetrow} {
+               # Fix up the scrollregion and change the scrolling position
+               # now that our target row has moved.
+               set diff [expr {($r - $targetrow) * $linespc}]
+               set targetrow $r
+               setcanvscroll
+               set ymax [lindex [$canv cget -scrollregion] 3]
+               incr y0 $diff
+               incr y1 $diff
+               set f0 [expr {$y0 / $ymax}]
+               set f1 [expr {$y1 / $ymax}]
+               allcanvs yview moveto $f0
+               $cscroll set $f0 $f1
+               set need_redisplay 1
+           }
+       } else {
+           unset targetid
+       }
+    }
+
+    set row [expr {int(($y0 - 3) / $linespc) - 1}]
     set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
+    if {$endrow >= $vrowmod($curview)} {
+       update_arcrows $curview
+    }
+    if {[info exists selectedline] &&
+       $row <= $selectedline && $selectedline <= $endrow} {
+       set targetrow $selectedline
+    } else {
+       set targetrow [expr {int(($row + $endrow) / 2)}]
+    }
+    if {$targetrow >= $numcommits} {
+       set targetrow [expr {$numcommits - 1}]
+    }
+    set targetid [commitonrow $targetrow]
     drawcommits $row $endrow
 }
 
-proc drawvisible {} {
-    global canv
-    eval drawfrac [$canv yview]
-}
-
 proc clear_display {} {
     global iddrawn linesegs need_redisplay nrows_drawn
     global vhighlights fhighlights nhighlights rhighlights
@@ -4875,7 +4954,7 @@ proc findmore {} {
     global commitdata commitinfo numcommits findpattern findloc
     global findstartline findcurline findallowwrap
     global find_dirn gdttype fhighlights fprogcoord
-    global curview varcorder vrownum varccommits
+    global curview varcorder vrownum varccommits vrowmod
 
     if {![info exists find_dirn]} {
        return 0
@@ -4911,6 +4990,9 @@ proc findmore {} {
        set n 500
        set moretodo 1
     }
+    if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
+       update_arcrows $curview
+    }
     set found 0
     set domore 1
     set ai [bsearch $vrownum($curview) $l]
@@ -4956,15 +5038,19 @@ proc findmore {} {
                set arowend [expr {$arow + [llength $ids]}]
            }
            set id [lindex $ids [expr {$l - $arow}]]
-           if {![info exists fhighlights($l)]} {
+           if {![info exists fhighlights($id)]} {
+               # this sets fhighlights($id) to -1
                askfilehighlight $l $id
+           }
+           if {$fhighlights($id) > 0} {
+               set found $domore
+               break
+           }
+           if {$fhighlights($id) < 0} {
                if {$domore} {
                    set domore 0
                    set findcurline [expr {$l - $find_dirn}]
                }
-           } elseif {$fhighlights($l)} {
-               set found $domore
-               break
            }
        }
     }
@@ -5058,7 +5144,9 @@ proc selcanvline {w x y} {
        set l 0
     }
     if {$w eq $canv} {
-       if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
+       set xmax [lindex [$canv cget -scrollregion] 2]
+       set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
+       if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
     }
     unmarkmatches
     selectline $l 1
@@ -5305,13 +5393,12 @@ proc selectline {l isnew} {
 
     make_secsel $l
 
+    set id [commitonrow $l]
     if {$isnew} {
-       addtohistory [list selectline $l 0]
+       addtohistory [list selbyid $id]
     }
 
     set selectedline $l
-
-    set id [commitonrow $l]
     set currentid $id
     $sha1entry delete 0 end
     $sha1entry insert 0 $id
@@ -6765,24 +6852,24 @@ proc domktag {} {
 }
 
 proc redrawtags {id} {
-    global canv linehtag idpos selectedline curview
+    global canv linehtag idpos currentid curview
     global canvxmax iddrawn
 
     if {![commitinview $id $curview]} return
     if {![info exists iddrawn($id)]} return
-    drawcommits [rowofcommit $id]
+    set row [rowofcommit $id]
     $canv delete tag.$id
     set xt [eval drawtags $id $idpos($id)]
-    $canv coords $linehtag([rowofcommit $id]) $xt [lindex $idpos($id) 2]
-    set text [$canv itemcget $linehtag([rowofcommit $id]) -text]
-    set xr [expr {$xt + [font measure mainfont $text]}]
+    $canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
+    set text [$canv itemcget $linehtag($row) -text]
+    set font [$canv itemcget $linehtag($row) -font]
+    set xr [expr {$xt + [font measure $font $text]}]
     if {$xr > $canvxmax} {
        set canvxmax $xr
        setcanvscroll
     }
-    if {[info exists selectedline]
-       && $selectedline == [rowofcommit $id]} {
-       selectline $selectedline 0
+    if {[info exists currentid] && $currentid == $id} {
+       make_secsel $row
     }
 }
 
@@ -7124,15 +7211,14 @@ proc showrefs {} {
     grid $top.list $top.ysb -sticky nsew
     grid $top.xsb x -sticky ew
     frame $top.f
-    label $top.f.l -text "[mc "Filter"]: " -font uifont
-    entry $top.f.e -width 20 -textvariable reflistfilter -font uifont
+    label $top.f.l -text "[mc "Filter"]: "
+    entry $top.f.e -width 20 -textvariable reflistfilter
     set reflistfilter "*"
     trace add variable reflistfilter write reflistfilter_change
     pack $top.f.e -side right -fill x -expand 1
     pack $top.f.l -side left
     grid $top.f - -sticky ew -pady 2
-    button $top.close -command [list destroy $top] -text [mc "Close"] \
-       -font uifont
+    button $top.close -command [list destroy $top] -text [mc "Close"]
     grid $top.close -
     grid columnconfigure $top 0 -weight 1
     grid rowconfigure $top 0 -weight 1
@@ -8342,7 +8428,7 @@ proc changedrefs {} {
 }
 
 proc rereadrefs {} {
-    global idtags idheads idotherrefs mainhead
+    global idtags idheads idotherrefs mainheadid
 
     set refids [concat [array names idtags] \
                    [array names idheads] [array names idotherrefs]]
@@ -8351,7 +8437,7 @@ proc rereadrefs {} {
            set ref($id) [listrefs $id]
        }
     }
-    set oldmainhead $mainhead
+    set oldmainhead $mainheadid
     readrefs
     changedrefs
     set refids [lsort -unique [concat $refids [array names idtags] \
@@ -8359,8 +8445,8 @@ proc rereadrefs {} {
     foreach id $refids {
        set v [listrefs $id]
        if {![info exists ref($id)] || $ref($id) != $v ||
-           ($id eq $oldmainhead && $id ne $mainhead) ||
-           ($id eq $mainhead && $id ne $oldmainhead)} {
+           ($id eq $oldmainhead && $id ne $mainheadid) ||
+           ($id eq $mainheadid && $id ne $oldmainhead)} {
            redrawtags $id
        }
     }
@@ -8444,7 +8530,7 @@ proc choosefont {font which} {
        eval font config sample [font actual $font]
        toplevel $top
        wm title $top [mc "Gitk font chooser"]
-       label $top.l -textvariable fontparam(which) -font uifont
+       label $top.l -textvariable fontparam(which)
        pack $top.l -side top
        set fontlist [lsort [font families]]
        frame $top.f
@@ -8474,10 +8560,8 @@ proc choosefont {font which} {
        bind $top.c <Configure> [list centertext $top.c]
        pack $top.c -side top -fill x
        frame $top.buts
-       button $top.buts.ok -text [mc "OK"] -command fontok -default active \
-           -font uifont
-       button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal \
-           -font uifont
+       button $top.buts.ok -text [mc "OK"] -command fontok -default active
+       button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
        grid $top.buts.ok $top.buts.can
        grid columnconfigure $top.buts 0 -weight 1 -uniform a
        grid columnconfigure $top.buts 1 -weight 1 -uniform a
@@ -8545,7 +8629,7 @@ proc doprefs {} {
     global maxwidth maxgraphpct
     global oldprefs prefstop showneartags showlocalchanges
     global bgcolor fgcolor ctext diffcolors selectbgcolor
-    global uifont tabstop limitdiffs
+    global tabstop limitdiffs
 
     set top .gitkprefs
     set prefstop $top
@@ -8560,7 +8644,6 @@ proc doprefs {} {
     toplevel $top
     wm title $top [mc "Gitk preferences"]
     label $top.ldisp -text [mc "Commit list display options"]
-    $top.ldisp configure -font uifont
     grid $top.ldisp - -sticky w -pady 10
     label $top.spacer -text " "
     label $top.maxwidthl -text [mc "Maximum graph width (lines)"] \
@@ -8578,7 +8661,6 @@ proc doprefs {} {
     grid x $top.showlocal -sticky w
 
     label $top.ddisp -text [mc "Diff display options"]
-    $top.ddisp configure -font uifont
     grid $top.ddisp - -sticky w -pady 10
     label $top.tabstopl -text [mc "Tab spacing"] -font optionfont
     spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
@@ -8595,7 +8677,6 @@ proc doprefs {} {
     grid x $top.ldiff -sticky w
 
     label $top.cdisp -text [mc "Colors: press to choose"]
-    $top.cdisp configure -font uifont
     grid $top.cdisp - -sticky w -pady 10
     label $top.bg -padx 40 -relief sunk -background $bgcolor
     button $top.bgbut -text [mc "Background"] -font optionfont \
@@ -8627,7 +8708,6 @@ proc doprefs {} {
     grid x $top.selbgbut $top.selbgsep -sticky w
 
     label $top.cfont -text [mc "Fonts: press to choose"]
-    $top.cfont configure -font uifont
     grid $top.cfont - -sticky w -pady 10
     mkfontdisp mainfont $top [mc "Main font"]
     mkfontdisp textfont $top [mc "Diff display font"]
@@ -8635,9 +8715,7 @@ proc doprefs {} {
 
     frame $top.buts
     button $top.buts.ok -text [mc "OK"] -command prefsok -default active
-    $top.buts.ok configure -font uifont
     button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
-    $top.buts.can configure -font uifont
     grid $top.buts.ok $top.buts.can
     grid columnconfigure $top.buts 0 -weight 1 -uniform a
     grid columnconfigure $top.buts 1 -weight 1 -uniform a
@@ -9113,6 +9191,8 @@ eval font create textfontbold [fontflags textfont 1]
 parsefont uifont $uifont
 eval font create uifont [fontflags uifont]
 
+setoptions
+
 # check that we can find a .git directory somewhere...
 if {[catch {set gitdir [gitdir]}]} {
     show_error {} . [mc "Cannot find a git repository here."]