From 3244729aac7515ccda651d40f41cef94517ac089 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Fri, 27 Jul 2007 22:30:15 +1000 Subject: [PATCH 1/8] gitk: Add a context menu for file list entries At the moment this just has two entries, which allow you to add the file that you clicked on to the list of filenames to highlight, or replace the list with the file. Signed-off-by: Paul Mackerras --- gitk | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gitk b/gitk index f74ce51379..6c2be3b727 100755 --- a/gitk +++ b/gitk @@ -879,6 +879,7 @@ proc makewindow {} { bind $cflist <1> {sel_flist %W %x %y; break} bind $cflist {sel_flist %W %x %y; break} bind $cflist {treeclick %W %x %y} + bind $cflist {pop_flist_menu %W %X %Y %x %y} set maincursor [. cget -cursor] set textcursor [$ctext cget -cursor] @@ -916,6 +917,14 @@ proc makewindow {} { -command cobranch $headctxmenu add command -label "Remove this branch" \ -command rmbranch + + global flist_menu + set flist_menu .flistctxmenu + menu $flist_menu -tearoff 0 + $flist_menu add command -label "Highlight this too" \ + -command {flist_hl 0} + $flist_menu add command -label "Highlight this only" \ + -command {flist_hl 1} } # mouse-2 makes all windows scan vertically, but only the one @@ -1499,6 +1508,33 @@ proc sel_flist {w x y} { } } +proc pop_flist_menu {w X Y x y} { + global ctext cflist cmitmode flist_menu flist_menu_file + global treediffs diffids + + set l [lindex [split [$w index "@$x,$y"] "."] 0] + if {$l <= 1} return + if {$cmitmode eq "tree"} { + set e [linetoelt $l] + if {[string index $e end] eq "/"} return + } else { + set e [lindex $treediffs($diffids) [expr {$l-2}]] + } + set flist_menu_file $e + tk_popup $flist_menu $X $Y +} + +proc flist_hl {only} { + global flist_menu_file highlight_files + + set x [shellquote $flist_menu_file] + if {$only || $highlight_files eq {}} { + set highlight_files $x + } else { + append highlight_files " " $x + } +} + # Functions for adding and removing shell-type quoting proc shellquote {str} { From 67a4f1a7f5c778ffa23d1e562feb4cc6d52c9414 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Sun, 12 Aug 2007 17:23:47 +1000 Subject: [PATCH 2/8] gitk: Fix bug causing the "can't unset idinlist(...)" error Under some circumstances, having duplicate parents in a commit could trigger a "can't unset idinlist" Tcl error. This fixes the cause (the logic in layoutrows could end up putting the same commit into rowidlist twice) and also puts a catch around the unset to ignore the error. Thanks to Jeff King for coming up with a test script to generate a repo that shows the problem. Signed-off-by: Paul Mackerras --- gitk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gitk b/gitk index 6c2be3b727..44b04f017a 100755 --- a/gitk +++ b/gitk @@ -2880,6 +2880,7 @@ proc layoutrows {row endrow last} { } elseif {!$idinlist($p)} { lappend oldolds $p } + set idinlist($p) 1 } set nev [expr {[llength $idlist] + [llength $newolds] + [llength $oldolds] - $maxwidth + 1}] @@ -2952,12 +2953,10 @@ proc layoutrows {row endrow last} { lset offs $col {} } foreach i $newolds { - set idinlist($i) 1 set idrowranges($i) $id } incr col $l foreach oid $oldolds { - set idinlist($oid) 1 set idlist [linsert $idlist $col $oid] set offs [linsert $offs $col $o] makeuparrow $oid $col $row $o @@ -2998,7 +2997,7 @@ proc layouttail {} { set col [expr {[llength $idlist] - 1}] set id [lindex $idlist $col] addextraid $id $row - unset idinlist($id) + catch {unset idinlist($id)} lappend idrowranges($id) $id lappend rowrangelist $idrowranges($id) unset idrowranges($id) From bd441de4df68c4144425b1c18d323fd90f3f9617 Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Tue, 7 Aug 2007 21:40:34 -0400 Subject: [PATCH 3/8] [PATCH] gitk: Enable selected patch text on Windows On windows, mouse input follows the keyboard focus, so to allow selecting text from the patch canvas we must not shift focus back to the top level. This change has no negative impact on X, so we don't explicitly test for Win32 on this change. This provides similar selection capability as already available using X-Windows. Signed-off-by: Mark Levedahl Signed-off-by: Paul Mackerras --- gitk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index 44b04f017a..32206a68f0 100755 --- a/gitk +++ b/gitk @@ -964,8 +964,8 @@ proc bindkey {ev script} { # set the focus back to the toplevel for any click outside # the entry widgets proc click {w} { - global entries - foreach e $entries { + global ctext entries + foreach e [concat $entries $ctext] { if {$w == $e} return } focus . @@ -4600,6 +4600,7 @@ proc sellastline {} { proc selnextline {dir} { global selectedline + focus . if {![info exists selectedline]} return set l [expr {$selectedline + $dir}] unmarkmatches @@ -4680,6 +4681,7 @@ proc godo {elt} { proc goback {} { global history historyindex + focus . if {$historyindex > 1} { incr historyindex -1 @@ -4693,6 +4695,7 @@ proc goback {} { proc goforw {} { global history historyindex + focus . if {$historyindex < [llength $history]} { set cmd [lindex $history $historyindex] From 314c30936f505f70534c619a48d99afb93451cb2 Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Tue, 7 Aug 2007 21:40:35 -0400 Subject: [PATCH 4/8] [PATCH] gitk: Handle MouseWheel events on Windows Windows, unlike X-Windows, sends mousewheel events by default to the window that has keyboard focus and uses the MouseWheel event to do so. The window to be scrolled must be able to take focus, but gitk's panels are disabled so cannot take focus. For all these reasons, a different design is needed to use the mousewheel on Windows. The approach here is to bind the mousewheel events to the top level window and redirect them based upon the current mouse position. Signed-off-by: Mark Levedahl Signed-off-by: Paul Mackerras --- gitk | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index 32206a68f0..9000383235 100755 --- a/gitk +++ b/gitk @@ -823,8 +823,13 @@ proc makewindow {} { pack .ctop -fill both -expand 1 bindall <1> {selcanvline %W %x %y} #bindall {selcanvline %W %x %y} - bindall "allcanvs yview scroll -5 units" - bindall "allcanvs yview scroll 5 units" + if {[tk windowingsystem] == "win32"} { + bind . { windows_mousewheel_redirector %W %X %Y %D } + bind $ctext { windows_mousewheel_redirector %W %X %Y %D ; break } + } else { + bindall "allcanvs yview scroll -5 units" + bindall "allcanvs yview scroll 5 units" + } bindall <2> "canvscan mark %W %x %y" bindall "canvscan dragto %W %x %y" bindkey selfirstline @@ -927,6 +932,24 @@ proc makewindow {} { -command {flist_hl 1} } +# Windows sends all mouse wheel events to the current focused window, not +# the one where the mouse hovers, so bind those events here and redirect +# to the correct window +proc windows_mousewheel_redirector {W X Y D} { + global canv canv2 canv3 + set w [winfo containing -displayof $W $X $Y] + if {$w ne ""} { + set u [expr {$D < 0 ? 5 : -5}] + if {$w == $canv || $w == $canv2 || $w == $canv3} { + allcanvs yview scroll $u units + } else { + catch { + $w yview scroll $u units + } + } + } +} + # mouse-2 makes all windows scan vertically, but only the one # the cursor is in scans horizontally proc canvscan {op w x y} { From 062d671f57a422863416ee4c746ef74c1cc45c19 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Sun, 29 Jul 2007 22:28:40 +0200 Subject: [PATCH 5/8] [PATCH] gitk: Continue and show error message in new repos If there is no commit made yet, gitk just dumps a Tcl error on stderr, which sometimes is hard to see. Noticed when gitk was run from Xfce file manager (thunar's custom action). Signed-off-by: Alex Riesen Signed-off-by: Paul Mackerras --- gitk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitk b/gitk index 9000383235..b0a76dd225 100755 --- a/gitk +++ b/gitk @@ -427,7 +427,7 @@ proc readrefs {} { lappend idotherrefs($id) $name } } - close $refd + catch {close $refd} set mainhead {} set mainheadid {} catch { From 6c87d60cc6202d4de5ac6d136394602feefeafc6 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Sun, 29 Jul 2007 22:29:45 +0200 Subject: [PATCH 6/8] [PATCH] gitk: Show an error and exit if no .git could be found This is to help people starting gitk from graphical file managers where the stderr output is hidden. Signed-off-by: Alex Riesen Signed-off-by: Paul Mackerras --- gitk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gitk b/gitk index b0a76dd225..769c79ab07 100755 --- a/gitk +++ b/gitk @@ -7636,7 +7636,10 @@ catch {source ~/.gitk} font create optionfont -family sans-serif -size -12 # check that we can find a .git directory somewhere... -set gitdir [gitdir] +if {[catch {set gitdir [gitdir]}]} { + show_error {} . "Cannot find a git repository here." + exit 1 +} if {![file isdirectory $gitdir]} { show_error {} . "Cannot find the git directory \"$gitdir\"." exit 1 From 7b459a1c1cc5401295e3adb12031e39e35712f4a Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 13 Aug 2007 14:52:00 +1000 Subject: [PATCH 7/8] gitk: Fix bug introduced in commit 67a4f1a7 In fixing the "can't unset idinlist" error, I moved the setting of idinlist into the loop that splits the parents into "new" parents (i.e. those of which this is the first child) and "old" parents. Unfortunately this is incorrect in the case where we hit the break statement a few lines further down, since when we come back in, we'll see idinlist($p) set for some parents that aren't in the list. This fixes it by moving the loop that sets up newolds and oldolds further down. Signed-off-by: Paul Mackerras --- gitk | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gitk b/gitk index 769c79ab07..666a545751 100755 --- a/gitk +++ b/gitk @@ -2895,18 +2895,12 @@ proc layoutrows {row endrow last} { set offs [lindex $rowoffsets $row] while {$row < $endrow} { set id [lindex $displayorder $row] - set oldolds {} - set newolds {} + set nev [expr {[llength $idlist] - $maxwidth + 1}] foreach p [lindex $parentlist $row] { - if {![info exists idinlist($p)]} { - lappend newolds $p - } elseif {!$idinlist($p)} { - lappend oldolds $p + if {![info exists idinlist($p)] || !$idinlist($p)} { + incr nev } - set idinlist($p) 1 } - set nev [expr {[llength $idlist] + [llength $newolds] - + [llength $oldolds] - $maxwidth + 1}] if {$nev > 0} { if {!$last && $row + $uparrowlen + $mingaplen >= $commitidx($curview)} break @@ -2925,12 +2919,22 @@ proc layoutrows {row endrow last} { if {[incr nev -1] <= 0} break continue } - set rowchk($id) [expr {$row + $r}] + set rowchk($i) [expr {$row + $r}] } } lset rowidlist $row $idlist lset rowoffsets $row $offs } + set oldolds {} + set newolds {} + foreach p [lindex $parentlist $row] { + if {![info exists idinlist($p)]} { + lappend newolds $p + } elseif {!$idinlist($p)} { + lappend oldolds $p + } + set idinlist($p) 1 + } set col [lsearch -exact $idlist $id] if {$col < 0} { set col [llength $idlist] From a69b2d1a8bf335ddbf0929c609b2daa523c7ede0 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 13 Aug 2007 15:02:02 +1000 Subject: [PATCH 8/8] gitk: Fix bug causing Tcl error when updating graph If "Show nearby tags" is turned off, selecting "Update" from the File menu will cause a Tcl error. This fixes it. The problem was that we were calling regetallcommits unconditionally, but it assumed that getallcommits had been called previously. This also restructures {re,}getallcommits to be a bit simpler. Signed-off-by: Paul Mackerras --- gitk | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/gitk b/gitk index 666a545751..57617d58b0 100755 --- a/gitk +++ b/gitk @@ -296,7 +296,7 @@ proc readcommit {id} { proc updatecommits {} { global viewdata curview phase displayorder - global children commitrow selectedline thickerline + global children commitrow selectedline thickerline showneartags if {$phase ne {}} { stop_rev_list @@ -313,7 +313,9 @@ proc updatecommits {} { catch {unset viewdata($n)} readrefs changedrefs - regetallcommits + if {$showneartags} { + getallcommits + } showview $n } @@ -6199,17 +6201,13 @@ proc rmbranch {} { proc getallcommits {} { global allcommits allids nbmp nextarc seeds - set allids {} - set nbmp 0 - set nextarc 0 - set allcommits 0 - set seeds {} - regetallcommits -} - -# Called when the graph might have changed -proc regetallcommits {} { - global allcommits seeds + if {![info exists allcommits]} { + set allids {} + set nbmp 0 + set nextarc 0 + set allcommits 0 + set seeds {} + } set cmd [concat | git rev-list --all --parents] foreach id $seeds {