2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2008 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
12 if {[info exists env(GIT_DIR)]} {
15 return [exec git rev-parse --git-dir]
19 # A simple scheduler for compute-intensive stuff.
20 # The aim is to make sure that event handlers for GUI actions can
21 # run at least every 50-100 ms. Unfortunately fileevent handlers are
22 # run before X event handlers, so reading from a fast source can
23 # make the GUI completely unresponsive.
25 global isonrunq runq currunq
28 if {[info exists isonrunq($script)]} return
29 if {$runq eq {} && ![info exists currunq]} {
32 lappend runq [list {} $script]
33 set isonrunq($script) 1
36 proc filerun {fd script} {
37 fileevent $fd readable [list filereadable $fd $script]
40 proc filereadable {fd script} {
43 fileevent $fd readable {}
44 if {$runq eq {} && ![info exists currunq]} {
47 lappend runq [list $fd $script]
53 for {set i 0} {$i < [llength $runq]} {} {
54 if {[lindex $runq $i 0] eq $fd} {
55 set runq [lreplace $runq $i $i]
63 global isonrunq runq currunq
65 set tstart [clock clicks -milliseconds]
67 while {[llength $runq] > 0} {
68 set fd [lindex $runq 0 0]
69 set script [lindex $runq 0 1]
70 set currunq [lindex $runq 0]
71 set runq [lrange $runq 1 end]
72 set repeat [eval $script]
74 set t1 [clock clicks -milliseconds]
75 set t [expr {$t1 - $t0}]
76 if {$repeat ne {} && $repeat} {
77 if {$fd eq {} || $repeat == 2} {
78 # script returns 1 if it wants to be readded
79 # file readers return 2 if they could do more straight away
80 lappend runq [list $fd $script]
82 fileevent $fd readable [list filereadable $fd $script]
84 } elseif {$fd eq {}} {
85 unset isonrunq($script)
88 if {$t1 - $tstart >= 80} break
95 proc reg_instance {fd} {
96 global commfd leftover loginstance
98 set i [incr loginstance]
104 proc unmerged_files {files} {
107 # find the list of unmerged files
111 set fd [open "| git ls-files -u" r]
113 show_error {} . "[mc "Couldn't get list of unmerged files:"] $err"
116 while {[gets $fd line] >= 0} {
117 set i [string first "\t" $line]
119 set fname [string range $line [expr {$i+1}] end]
120 if {[lsearch -exact $mlist $fname] >= 0} continue
122 if {$files eq {} || [path_filter $files $fname]} {
130 proc parseviewargs {n arglist} {
131 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs
139 set origargs $arglist
143 foreach arg $arglist {
150 switch -glob -- $arg {
154 # remove from origargs in case we hit an unknown option
155 set origargs [lreplace $origargs $i $i]
159 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
160 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
161 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
162 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
163 "--ignore-space-change" - "-U*" - "--unified=*" {
164 # These request or affect diff output, which we don't want.
165 # Some could be used to set our defaults for diff display.
166 lappend diffargs $arg
168 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
169 "--name-only" - "--name-status" - "--color" - "--color-words" -
170 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
171 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
172 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
173 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
174 "--objects" - "--objects-edge" - "--reverse" {
175 # These cause our parsing of git log's output to fail, or else
176 # they're options we want to set ourselves, so ignore them.
178 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
179 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
180 "--full-history" - "--dense" - "--sparse" -
181 "--follow" - "--left-right" - "--encoding=*" {
182 # These are harmless, and some are even useful
185 "--diff-filter=*" - "--no-merges" - "--unpacked" -
186 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
187 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
188 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
189 "--remove-empty" - "--first-parent" - "--cherry-pick" -
190 "-S*" - "--pickaxe-all" - "--pickaxe-regex" {
191 # These mean that we get a subset of the commits
196 # This appears to be the only one that has a value as a
197 # separate word following it
207 # git rev-parse doesn't understand --merge
208 lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD
211 # Other flag arguments including -<n>
212 if {[string is digit -strict [string range $arg 1 end]]} {
215 # a flag argument that we don't recognize;
216 # that means we can't optimize
222 # Non-flag arguments specify commits or ranges of commits
223 if {[string match "*...*" $arg]} {
224 lappend revargs --gitk-symmetric-diff-marker
230 set vdflags($n) $diffargs
231 set vflags($n) $glflags
232 set vrevs($n) $revargs
233 set vfiltered($n) $filtered
234 set vorigargs($n) $origargs
238 proc parseviewrevs {view revs} {
239 global vposids vnegids
244 if {[catch {set ids [eval exec git rev-parse $revs]} err]} {
245 # we get stdout followed by stderr in $err
246 # for an unknown rev, git rev-parse echoes it and then errors out
247 set errlines [split $err "\n"]
249 for {set l 0} {$l < [llength $errlines]} {incr l} {
250 set line [lindex $errlines $l]
251 if {!([string length $line] == 40 && [string is xdigit $line])} {
252 if {[string match "fatal:*" $line]} {
253 if {[string match "fatal: ambiguous argument*" $line]
255 if {[llength $badrev] == 1} {
256 set err "unknown revision $badrev"
258 set err "unknown revisions: [join $badrev ", "]"
261 set err [join [lrange $errlines $l end] "\n"]
268 error_popup "[mc "Error parsing revisions:"] $err"
275 foreach id [split $ids "\n"] {
276 if {$id eq "--gitk-symmetric-diff-marker"} {
278 } elseif {[string match "^*" $id]} {
285 lappend neg [string range $id 1 end]
290 lset ret end [lindex $ret end]...$id
296 set vposids($view) $pos
297 set vnegids($view) $neg
301 # Start off a git log process and arrange to read its output
302 proc start_rev_list {view} {
303 global startmsecs commitidx viewcomplete curview
305 global viewargs viewargscmd viewfiles vfilelimit
306 global showlocalchanges
307 global viewactive viewinstances vmergeonly
308 global mainheadid viewmainheadid viewmainheadid_orig
309 global vcanopt vflags vrevs vorigargs
311 set startmsecs [clock clicks -milliseconds]
312 set commitidx($view) 0
313 # these are set this way for the error exits
314 set viewcomplete($view) 1
315 set viewactive($view) 0
318 set args $viewargs($view)
319 if {$viewargscmd($view) ne {}} {
321 set str [exec sh -c $viewargscmd($view)]
323 error_popup "[mc "Error executing --argscmd command:"] $err"
326 set args [concat $args [split $str "\n"]]
328 set vcanopt($view) [parseviewargs $view $args]
330 set files $viewfiles($view)
331 if {$vmergeonly($view)} {
332 set files [unmerged_files $files]
335 if {$nr_unmerged == 0} {
336 error_popup [mc "No files selected: --merge specified but\
337 no files are unmerged."]
339 error_popup [mc "No files selected: --merge specified but\
340 no unmerged files are within file limit."]
345 set vfilelimit($view) $files
347 if {$vcanopt($view)} {
348 set revs [parseviewrevs $view $vrevs($view)]
352 set args [concat $vflags($view) $revs]
354 set args $vorigargs($view)
358 set fd [open [concat | git log --no-color -z --pretty=raw --parents \
359 --boundary $args "--" $files] r]
361 error_popup "[mc "Error executing git log:"] $err"
364 set i [reg_instance $fd]
365 set viewinstances($view) [list $i]
366 set viewmainheadid($view) $mainheadid
367 set viewmainheadid_orig($view) $mainheadid
368 if {$files ne {} && $mainheadid ne {}} {
369 get_viewmainhead $view
371 if {$showlocalchanges && $viewmainheadid($view) ne {}} {
372 interestedin $viewmainheadid($view) dodiffindex
374 fconfigure $fd -blocking 0 -translation lf -eofchar {}
375 if {$tclencoding != {}} {
376 fconfigure $fd -encoding $tclencoding
378 filerun $fd [list getcommitlines $fd $i $view 0]
379 nowbusy $view [mc "Reading"]
380 set viewcomplete($view) 0
381 set viewactive($view) 1
385 proc stop_instance {inst} {
386 global commfd leftover
388 set fd $commfd($inst)
392 if {$::tcl_platform(platform) eq {windows}} {
401 unset leftover($inst)
404 proc stop_backends {} {
407 foreach inst [array names commfd] {
412 proc stop_rev_list {view} {
415 foreach inst $viewinstances($view) {
418 set viewinstances($view) {}
421 proc reset_pending_select {selid} {
422 global pending_select mainheadid selectheadid
425 set pending_select $selid
426 } elseif {$selectheadid ne {}} {
427 set pending_select $selectheadid
429 set pending_select $mainheadid
433 proc getcommits {selid} {
434 global canv curview need_redisplay viewactive
437 if {[start_rev_list $curview]} {
438 reset_pending_select $selid
439 show_status [mc "Reading commits..."]
442 show_status [mc "No commits selected"]
446 proc updatecommits {} {
447 global curview vcanopt vorigargs vfilelimit viewinstances
448 global viewactive viewcomplete tclencoding
449 global startmsecs showneartags showlocalchanges
450 global mainheadid viewmainheadid viewmainheadid_orig pending_select
452 global varcid vposids vnegids vflags vrevs
454 set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
457 if {$mainheadid ne $viewmainheadid_orig($view)} {
458 if {$showlocalchanges} {
461 set viewmainheadid($view) $mainheadid
462 set viewmainheadid_orig($view) $mainheadid
463 if {$vfilelimit($view) ne {}} {
464 get_viewmainhead $view
467 if {$showlocalchanges} {
470 if {$vcanopt($view)} {
471 set oldpos $vposids($view)
472 set oldneg $vnegids($view)
473 set revs [parseviewrevs $view $vrevs($view)]
477 # note: getting the delta when negative refs change is hard,
478 # and could require multiple git log invocations, so in that
479 # case we ask git log for all the commits (not just the delta)
480 if {$oldneg eq $vnegids($view)} {
483 # take out positive refs that we asked for before or
484 # that we have already seen
486 if {[string length $rev] == 40} {
487 if {[lsearch -exact $oldpos $rev] < 0
488 && ![info exists varcid($view,$rev)]} {
493 lappend $newrevs $rev
496 if {$npos == 0} return
498 set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
500 set args [concat $vflags($view) $revs --not $oldpos]
502 set args $vorigargs($view)
505 set fd [open [concat | git log --no-color -z --pretty=raw --parents \
506 --boundary $args "--" $vfilelimit($view)] r]
508 error_popup "[mc "Error executing git log:"] $err"
511 if {$viewactive($view) == 0} {
512 set startmsecs [clock clicks -milliseconds]
514 set i [reg_instance $fd]
515 lappend viewinstances($view) $i
516 fconfigure $fd -blocking 0 -translation lf -eofchar {}
517 if {$tclencoding != {}} {
518 fconfigure $fd -encoding $tclencoding
520 filerun $fd [list getcommitlines $fd $i $view 1]
521 incr viewactive($view)
522 set viewcomplete($view) 0
523 reset_pending_select {}
524 nowbusy $view "Reading"
530 proc reloadcommits {} {
531 global curview viewcomplete selectedline currentid thickerline
532 global showneartags treediffs commitinterest cached_commitrow
536 if {$selectedline ne {}} {
540 if {!$viewcomplete($curview)} {
541 stop_rev_list $curview
545 catch {unset currentid}
546 catch {unset thickerline}
547 catch {unset treediffs}
554 catch {unset commitinterest}
555 catch {unset cached_commitrow}
556 catch {unset targetid}
562 # This makes a string representation of a positive integer which
563 # sorts as a string in numerical order
566 return [format "%x" $n]
567 } elseif {$n < 256} {
568 return [format "x%.2x" $n]
569 } elseif {$n < 65536} {
570 return [format "y%.4x" $n]
572 return [format "z%.8x" $n]
575 # Procedures used in reordering commits from git log (without
576 # --topo-order) into the order for display.
578 proc varcinit {view} {
579 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
580 global vtokmod varcmod vrowmod varcix vlastins
582 set varcstart($view) {{}}
583 set vupptr($view) {0}
584 set vdownptr($view) {0}
585 set vleftptr($view) {0}
586 set vbackptr($view) {0}
587 set varctok($view) {{}}
588 set varcrow($view) {{}}
589 set vtokmod($view) {}
592 set varcix($view) {{}}
593 set vlastins($view) {0}
596 proc resetvarcs {view} {
597 global varcid varccommits parents children vseedcount ordertok
599 foreach vid [array names varcid $view,*] {
604 # some commits might have children but haven't been seen yet
605 foreach vid [array names children $view,*] {
608 foreach va [array names varccommits $view,*] {
609 unset varccommits($va)
611 foreach vd [array names vseedcount $view,*] {
612 unset vseedcount($vd)
614 catch {unset ordertok}
617 # returns a list of the commits with no children
619 global vdownptr vleftptr varcstart
622 set a [lindex $vdownptr($v) 0]
624 lappend ret [lindex $varcstart($v) $a]
625 set a [lindex $vleftptr($v) $a]
630 proc newvarc {view id} {
631 global varcid varctok parents children vdatemode
632 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
633 global commitdata commitinfo vseedcount varccommits vlastins
635 set a [llength $varctok($view)]
637 if {[llength $children($vid)] == 0 || $vdatemode($view)} {
638 if {![info exists commitinfo($id)]} {
639 parsecommit $id $commitdata($id) 1
641 set cdate [lindex $commitinfo($id) 4]
642 if {![string is integer -strict $cdate]} {
645 if {![info exists vseedcount($view,$cdate)]} {
646 set vseedcount($view,$cdate) -1
648 set c [incr vseedcount($view,$cdate)]
649 set cdate [expr {$cdate ^ 0xffffffff}]
650 set tok "s[strrep $cdate][strrep $c]"
655 if {[llength $children($vid)] > 0} {
656 set kid [lindex $children($vid) end]
657 set k $varcid($view,$kid)
658 if {[string compare [lindex $varctok($view) $k] $tok] > 0} {
661 set tok [lindex $varctok($view) $k]
665 set i [lsearch -exact $parents($view,$ki) $id]
666 set j [expr {[llength $parents($view,$ki)] - 1 - $i}]
667 append tok [strrep $j]
669 set c [lindex $vlastins($view) $ka]
670 if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} {
672 set b [lindex $vdownptr($view) $ka]
674 set b [lindex $vleftptr($view) $c]
676 while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} {
678 set b [lindex $vleftptr($view) $c]
681 lset vdownptr($view) $ka $a
682 lappend vbackptr($view) 0
684 lset vleftptr($view) $c $a
685 lappend vbackptr($view) $c
687 lset vlastins($view) $ka $a
688 lappend vupptr($view) $ka
689 lappend vleftptr($view) $b
691 lset vbackptr($view) $b $a
693 lappend varctok($view) $tok
694 lappend varcstart($view) $id
695 lappend vdownptr($view) 0
696 lappend varcrow($view) {}
697 lappend varcix($view) {}
698 set varccommits($view,$a) {}
699 lappend vlastins($view) 0
703 proc splitvarc {p v} {
704 global varcid varcstart varccommits varctok vtokmod
705 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
707 set oa $varcid($v,$p)
708 set otok [lindex $varctok($v) $oa]
709 set ac $varccommits($v,$oa)
710 set i [lsearch -exact $varccommits($v,$oa) $p]
712 set na [llength $varctok($v)]
713 # "%" sorts before "0"...
714 set tok "$otok%[strrep $i]"
715 lappend varctok($v) $tok
716 lappend varcrow($v) {}
717 lappend varcix($v) {}
718 set varccommits($v,$oa) [lrange $ac 0 [expr {$i - 1}]]
719 set varccommits($v,$na) [lrange $ac $i end]
720 lappend varcstart($v) $p
721 foreach id $varccommits($v,$na) {
722 set varcid($v,$id) $na
724 lappend vdownptr($v) [lindex $vdownptr($v) $oa]
725 lappend vlastins($v) [lindex $vlastins($v) $oa]
726 lset vdownptr($v) $oa $na
727 lset vlastins($v) $oa 0
728 lappend vupptr($v) $oa
729 lappend vleftptr($v) 0
730 lappend vbackptr($v) 0
731 for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} {
732 lset vupptr($v) $b $na
734 if {[string compare $otok $vtokmod($v)] <= 0} {
739 proc renumbervarc {a v} {
740 global parents children varctok varcstart varccommits
741 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
743 set t1 [clock clicks -milliseconds]
749 if {[info exists isrelated($a)]} {
751 set id [lindex $varccommits($v,$a) end]
752 foreach p $parents($v,$id) {
753 if {[info exists varcid($v,$p)]} {
754 set isrelated($varcid($v,$p)) 1
759 set b [lindex $vdownptr($v) $a]
762 set b [lindex $vleftptr($v) $a]
764 set a [lindex $vupptr($v) $a]
770 if {![info exists kidchanged($a)]} continue
771 set id [lindex $varcstart($v) $a]
772 if {[llength $children($v,$id)] > 1} {
773 set children($v,$id) [lsort -command [list vtokcmp $v] \
776 set oldtok [lindex $varctok($v) $a]
777 if {!$vdatemode($v)} {
783 set kid [last_real_child $v,$id]
785 set k $varcid($v,$kid)
786 if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
789 set tok [lindex $varctok($v) $k]
793 set i [lsearch -exact $parents($v,$ki) $id]
794 set j [expr {[llength $parents($v,$ki)] - 1 - $i}]
795 append tok [strrep $j]
797 if {$tok eq $oldtok} {
800 set id [lindex $varccommits($v,$a) end]
801 foreach p $parents($v,$id) {
802 if {[info exists varcid($v,$p)]} {
803 set kidchanged($varcid($v,$p)) 1
808 lset varctok($v) $a $tok
809 set b [lindex $vupptr($v) $a]
811 if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} {
814 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
817 set c [lindex $vbackptr($v) $a]
818 set d [lindex $vleftptr($v) $a]
820 lset vdownptr($v) $b $d
822 lset vleftptr($v) $c $d
825 lset vbackptr($v) $d $c
827 if {[lindex $vlastins($v) $b] == $a} {
828 lset vlastins($v) $b $c
830 lset vupptr($v) $a $ka
831 set c [lindex $vlastins($v) $ka]
833 [string compare $tok [lindex $varctok($v) $c]] < 0} {
835 set b [lindex $vdownptr($v) $ka]
837 set b [lindex $vleftptr($v) $c]
840 [string compare $tok [lindex $varctok($v) $b]] >= 0} {
842 set b [lindex $vleftptr($v) $c]
845 lset vdownptr($v) $ka $a
846 lset vbackptr($v) $a 0
848 lset vleftptr($v) $c $a
849 lset vbackptr($v) $a $c
851 lset vleftptr($v) $a $b
853 lset vbackptr($v) $b $a
855 lset vlastins($v) $ka $a
858 foreach id [array names sortkids] {
859 if {[llength $children($v,$id)] > 1} {
860 set children($v,$id) [lsort -command [list vtokcmp $v] \
864 set t2 [clock clicks -milliseconds]
865 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
868 # Fix up the graph after we have found out that in view $v,
869 # $p (a commit that we have already seen) is actually the parent
870 # of the last commit in arc $a.
871 proc fix_reversal {p a v} {
872 global varcid varcstart varctok vupptr
874 set pa $varcid($v,$p)
875 if {$p ne [lindex $varcstart($v) $pa]} {
877 set pa $varcid($v,$p)
879 # seeds always need to be renumbered
880 if {[lindex $vupptr($v) $pa] == 0 ||
881 [string compare [lindex $varctok($v) $a] \
882 [lindex $varctok($v) $pa]] > 0} {
887 proc insertrow {id p v} {
888 global cmitlisted children parents varcid varctok vtokmod
889 global varccommits ordertok commitidx numcommits curview
890 global targetid targetrow
894 set cmitlisted($vid) 1
895 set children($vid) {}
896 set parents($vid) [list $p]
897 set a [newvarc $v $id]
899 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
902 lappend varccommits($v,$a) $id
904 if {[llength [lappend children($vp) $id]] > 1} {
905 set children($vp) [lsort -command [list vtokcmp $v] $children($vp)]
906 catch {unset ordertok}
908 fix_reversal $p $a $v
910 if {$v == $curview} {
911 set numcommits $commitidx($v)
913 if {[info exists targetid]} {
914 if {![comes_before $targetid $p]} {
921 proc insertfakerow {id p} {
922 global varcid varccommits parents children cmitlisted
923 global commitidx varctok vtokmod targetid targetrow curview numcommits
927 set i [lsearch -exact $varccommits($v,$a) $p]
929 puts "oops: insertfakerow can't find [shortids $p] on arc $a"
932 set children($v,$id) {}
933 set parents($v,$id) [list $p]
934 set varcid($v,$id) $a
935 lappend children($v,$p) $id
936 set cmitlisted($v,$id) 1
937 set numcommits [incr commitidx($v)]
938 # note we deliberately don't update varcstart($v) even if $i == 0
939 set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id]
941 if {[info exists targetid]} {
942 if {![comes_before $targetid $p]} {
950 proc removefakerow {id} {
951 global varcid varccommits parents children commitidx
952 global varctok vtokmod cmitlisted currentid selectedline
953 global targetid curview numcommits
956 if {[llength $parents($v,$id)] != 1} {
957 puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
960 set p [lindex $parents($v,$id) 0]
961 set a $varcid($v,$id)
962 set i [lsearch -exact $varccommits($v,$a) $id]
964 puts "oops: removefakerow can't find [shortids $id] on arc $a"
968 set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i]
969 unset parents($v,$id)
970 unset children($v,$id)
971 unset cmitlisted($v,$id)
972 set numcommits [incr commitidx($v) -1]
973 set j [lsearch -exact $children($v,$p) $id]
975 set children($v,$p) [lreplace $children($v,$p) $j $j]
978 if {[info exist currentid] && $id eq $currentid} {
982 if {[info exists targetid] && $targetid eq $id} {
989 proc first_real_child {vp} {
990 global children nullid nullid2
992 foreach id $children($vp) {
993 if {$id ne $nullid && $id ne $nullid2} {
1000 proc last_real_child {vp} {
1001 global children nullid nullid2
1003 set kids $children($vp)
1004 for {set i [llength $kids]} {[incr i -1] >= 0} {} {
1005 set id [lindex $kids $i]
1006 if {$id ne $nullid && $id ne $nullid2} {
1013 proc vtokcmp {v a b} {
1014 global varctok varcid
1016 return [string compare [lindex $varctok($v) $varcid($v,$a)] \
1017 [lindex $varctok($v) $varcid($v,$b)]]
1020 # This assumes that if lim is not given, the caller has checked that
1021 # arc a's token is less than $vtokmod($v)
1022 proc modify_arc {v a {lim {}}} {
1023 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1026 set c [string compare [lindex $varctok($v) $a] $vtokmod($v)]
1029 set r [lindex $varcrow($v) $a]
1030 if {$r ne {} && $vrowmod($v) <= $r + $lim} return
1033 set vtokmod($v) [lindex $varctok($v) $a]
1035 if {$v == $curview} {
1036 while {$a != 0 && [lindex $varcrow($v) $a] eq {}} {
1037 set a [lindex $vupptr($v) $a]
1043 set lim [llength $varccommits($v,$a)]
1045 set r [expr {[lindex $varcrow($v) $a] + $lim}]
1052 proc update_arcrows {v} {
1053 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1054 global varcid vrownum varcorder varcix varccommits
1055 global vupptr vdownptr vleftptr varctok
1056 global displayorder parentlist curview cached_commitrow
1058 if {$vrowmod($v) == $commitidx($v)} return
1059 if {$v == $curview} {
1060 if {[llength $displayorder] > $vrowmod($v)} {
1061 set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]]
1062 set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]]
1064 catch {unset cached_commitrow}
1066 set narctot [expr {[llength $varctok($v)] - 1}]
1068 while {$a != 0 && [lindex $varcix($v) $a] eq {}} {
1069 # go up the tree until we find something that has a row number,
1070 # or we get to a seed
1071 set a [lindex $vupptr($v) $a]
1074 set a [lindex $vdownptr($v) 0]
1077 set varcorder($v) [list $a]
1078 lset varcix($v) $a 0
1079 lset varcrow($v) $a 0
1083 set arcn [lindex $varcix($v) $a]
1084 if {[llength $vrownum($v)] > $arcn + 1} {
1085 set vrownum($v) [lrange $vrownum($v) 0 $arcn]
1086 set varcorder($v) [lrange $varcorder($v) 0 $arcn]
1088 set row [lindex $varcrow($v) $a]
1092 incr row [llength $varccommits($v,$a)]
1093 # go down if possible
1094 set b [lindex $vdownptr($v) $a]
1096 # if not, go left, or go up until we can go left
1098 set b [lindex $vleftptr($v) $a]
1100 set a [lindex $vupptr($v) $a]
1106 lappend vrownum($v) $row
1107 lappend varcorder($v) $a
1108 lset varcix($v) $a $arcn
1109 lset varcrow($v) $a $row
1111 set vtokmod($v) [lindex $varctok($v) $p]
1113 set vrowmod($v) $row
1114 if {[info exists currentid]} {
1115 set selectedline [rowofcommit $currentid]
1119 # Test whether view $v contains commit $id
1120 proc commitinview {id v} {
1123 return [info exists varcid($v,$id)]
1126 # Return the row number for commit $id in the current view
1127 proc rowofcommit {id} {
1128 global varcid varccommits varcrow curview cached_commitrow
1129 global varctok vtokmod
1132 if {![info exists varcid($v,$id)]} {
1133 puts "oops rowofcommit no arc for [shortids $id]"
1136 set a $varcid($v,$id)
1137 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
1140 if {[info exists cached_commitrow($id)]} {
1141 return $cached_commitrow($id)
1143 set i [lsearch -exact $varccommits($v,$a) $id]
1145 puts "oops didn't find commit [shortids $id] in arc $a"
1148 incr i [lindex $varcrow($v) $a]
1149 set cached_commitrow($id) $i
1153 # Returns 1 if a is on an earlier row than b, otherwise 0
1154 proc comes_before {a b} {
1155 global varcid varctok curview
1158 if {$a eq $b || ![info exists varcid($v,$a)] || \
1159 ![info exists varcid($v,$b)]} {
1162 if {$varcid($v,$a) != $varcid($v,$b)} {
1163 return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
1164 [lindex $varctok($v) $varcid($v,$b)]] < 0}]
1166 return [expr {[rowofcommit $a] < [rowofcommit $b]}]
1169 proc bsearch {l elt} {
1170 if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
1175 while {$hi - $lo > 1} {
1176 set mid [expr {int(($lo + $hi) / 2)}]
1177 set t [lindex $l $mid]
1180 } elseif {$elt > $t} {
1189 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1190 proc make_disporder {start end} {
1191 global vrownum curview commitidx displayorder parentlist
1192 global varccommits varcorder parents vrowmod varcrow
1193 global d_valid_start d_valid_end
1195 if {$end > $vrowmod($curview)} {
1196 update_arcrows $curview
1198 set ai [bsearch $vrownum($curview) $start]
1199 set start [lindex $vrownum($curview) $ai]
1200 set narc [llength $vrownum($curview)]
1201 for {set r $start} {$ai < $narc && $r < $end} {incr ai} {
1202 set a [lindex $varcorder($curview) $ai]
1203 set l [llength $displayorder]
1204 set al [llength $varccommits($curview,$a)]
1205 if {$l < $r + $al} {
1207 set pad [ntimes [expr {$r - $l}] {}]
1208 set displayorder [concat $displayorder $pad]
1209 set parentlist [concat $parentlist $pad]
1210 } elseif {$l > $r} {
1211 set displayorder [lrange $displayorder 0 [expr {$r - 1}]]
1212 set parentlist [lrange $parentlist 0 [expr {$r - 1}]]
1214 foreach id $varccommits($curview,$a) {
1215 lappend displayorder $id
1216 lappend parentlist $parents($curview,$id)
1218 } elseif {[lindex $displayorder [expr {$r + $al - 1}]] eq {}} {
1220 foreach id $varccommits($curview,$a) {
1221 lset displayorder $i $id
1222 lset parentlist $i $parents($curview,$id)
1230 proc commitonrow {row} {
1233 set id [lindex $displayorder $row]
1235 make_disporder $row [expr {$row + 1}]
1236 set id [lindex $displayorder $row]
1241 proc closevarcs {v} {
1242 global varctok varccommits varcid parents children
1243 global cmitlisted commitidx vtokmod
1245 set missing_parents 0
1247 set narcs [llength $varctok($v)]
1248 for {set a 1} {$a < $narcs} {incr a} {
1249 set id [lindex $varccommits($v,$a) end]
1250 foreach p $parents($v,$id) {
1251 if {[info exists varcid($v,$p)]} continue
1252 # add p as a new commit
1253 incr missing_parents
1254 set cmitlisted($v,$p) 0
1255 set parents($v,$p) {}
1256 if {[llength $children($v,$p)] == 1 &&
1257 [llength $parents($v,$id)] == 1} {
1260 set b [newvarc $v $p]
1262 set varcid($v,$p) $b
1263 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
1266 lappend varccommits($v,$b) $p
1268 set scripts [check_interest $p $scripts]
1271 if {$missing_parents > 0} {
1272 foreach s $scripts {
1278 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1279 # Assumes we already have an arc for $rwid.
1280 proc rewrite_commit {v id rwid} {
1281 global children parents varcid varctok vtokmod varccommits
1283 foreach ch $children($v,$id) {
1284 # make $rwid be $ch's parent in place of $id
1285 set i [lsearch -exact $parents($v,$ch) $id]
1287 puts "oops rewrite_commit didn't find $id in parent list for $ch"
1289 set parents($v,$ch) [lreplace $parents($v,$ch) $i $i $rwid]
1290 # add $ch to $rwid's children and sort the list if necessary
1291 if {[llength [lappend children($v,$rwid) $ch]] > 1} {
1292 set children($v,$rwid) [lsort -command [list vtokcmp $v] \
1293 $children($v,$rwid)]
1295 # fix the graph after joining $id to $rwid
1296 set a $varcid($v,$ch)
1297 fix_reversal $rwid $a $v
1298 # parentlist is wrong for the last element of arc $a
1299 # even if displayorder is right, hence the 3rd arg here
1300 modify_arc $v $a [expr {[llength $varccommits($v,$a)] - 1}]
1304 # Mechanism for registering a command to be executed when we come
1305 # across a particular commit. To handle the case when only the
1306 # prefix of the commit is known, the commitinterest array is now
1307 # indexed by the first 4 characters of the ID. Each element is a
1308 # list of id, cmd pairs.
1309 proc interestedin {id cmd} {
1310 global commitinterest
1312 lappend commitinterest([string range $id 0 3]) $id $cmd
1315 proc check_interest {id scripts} {
1316 global commitinterest
1318 set prefix [string range $id 0 3]
1319 if {[info exists commitinterest($prefix)]} {
1321 foreach {i script} $commitinterest($prefix) {
1322 if {[string match "$i*" $id]} {
1323 lappend scripts [string map [list "%I" $id "%P" $i] $script]
1325 lappend newlist $i $script
1328 if {$newlist ne {}} {
1329 set commitinterest($prefix) $newlist
1331 unset commitinterest($prefix)
1337 proc getcommitlines {fd inst view updating} {
1338 global cmitlisted leftover
1339 global commitidx commitdata vdatemode
1340 global parents children curview hlview
1341 global idpending ordertok
1342 global varccommits varcid varctok vtokmod vfilelimit
1344 set stuff [read $fd 500000]
1345 # git log doesn't terminate the last commit with a null...
1346 if {$stuff == {} && $leftover($inst) ne {} && [eof $fd]} {
1353 global commfd viewcomplete viewactive viewname
1354 global viewinstances
1356 set i [lsearch -exact $viewinstances($view) $inst]
1358 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
1360 # set it blocking so we wait for the process to terminate
1361 fconfigure $fd -blocking 1
1362 if {[catch {close $fd} err]} {
1364 if {$view != $curview} {
1365 set fv " for the \"$viewname($view)\" view"
1367 if {[string range $err 0 4] == "usage"} {
1368 set err "Gitk: error reading commits$fv:\
1369 bad arguments to git log."
1370 if {$viewname($view) eq "Command line"} {
1372 " (Note: arguments to gitk are passed to git log\
1373 to allow selection of commits to be displayed.)"
1376 set err "Error reading commits$fv: $err"
1380 if {[incr viewactive($view) -1] <= 0} {
1381 set viewcomplete($view) 1
1382 # Check if we have seen any ids listed as parents that haven't
1383 # appeared in the list
1387 if {$view == $curview} {
1396 set i [string first "\0" $stuff $start]
1398 append leftover($inst) [string range $stuff $start end]
1402 set cmit $leftover($inst)
1403 append cmit [string range $stuff 0 [expr {$i - 1}]]
1404 set leftover($inst) {}
1406 set cmit [string range $stuff $start [expr {$i - 1}]]
1408 set start [expr {$i + 1}]
1409 set j [string first "\n" $cmit]
1412 if {$j >= 0 && [string match "commit *" $cmit]} {
1413 set ids [string range $cmit 7 [expr {$j - 1}]]
1414 if {[string match {[-^<>]*} $ids]} {
1415 switch -- [string index $ids 0] {
1421 set ids [string range $ids 1 end]
1425 if {[string length $id] != 40} {
1433 if {[string length $shortcmit] > 80} {
1434 set shortcmit "[string range $shortcmit 0 80]..."
1436 error_popup "[mc "Can't parse git log output:"] {$shortcmit}"
1439 set id [lindex $ids 0]
1442 if {!$listed && $updating && ![info exists varcid($vid)] &&
1443 $vfilelimit($view) ne {}} {
1444 # git log doesn't rewrite parents for unlisted commits
1445 # when doing path limiting, so work around that here
1446 # by working out the rewritten parent with git rev-list
1447 # and if we already know about it, using the rewritten
1448 # parent as a substitute parent for $id's children.
1450 set rwid [exec git rev-list --first-parent --max-count=1 \
1451 $id -- $vfilelimit($view)]
1453 if {$rwid ne {} && [info exists varcid($view,$rwid)]} {
1454 # use $rwid in place of $id
1455 rewrite_commit $view $id $rwid
1462 if {[info exists varcid($vid)]} {
1463 if {$cmitlisted($vid) || !$listed} continue
1467 set olds [lrange $ids 1 end]
1471 set commitdata($id) [string range $cmit [expr {$j + 1}] end]
1472 set cmitlisted($vid) $listed
1473 set parents($vid) $olds
1474 if {![info exists children($vid)]} {
1475 set children($vid) {}
1476 } elseif {$a == 0 && [llength $children($vid)] == 1} {
1477 set k [lindex $children($vid) 0]
1478 if {[llength $parents($view,$k)] == 1 &&
1479 (!$vdatemode($view) ||
1480 $varcid($view,$k) == [llength $varctok($view)] - 1)} {
1481 set a $varcid($view,$k)
1486 set a [newvarc $view $id]
1488 if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} {
1491 if {![info exists varcid($vid)]} {
1493 lappend varccommits($view,$a) $id
1494 incr commitidx($view)
1499 if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
1501 if {[llength [lappend children($vp) $id]] > 1 &&
1502 [vtokcmp $view [lindex $children($vp) end-1] $id] > 0} {
1503 set children($vp) [lsort -command [list vtokcmp $view] \
1505 catch {unset ordertok}
1507 if {[info exists varcid($view,$p)]} {
1508 fix_reversal $p $a $view
1514 set scripts [check_interest $id $scripts]
1518 global numcommits hlview
1520 if {$view == $curview} {
1521 set numcommits $commitidx($view)
1524 if {[info exists hlview] && $view == $hlview} {
1525 # we never actually get here...
1528 foreach s $scripts {
1535 proc chewcommits {} {
1536 global curview hlview viewcomplete
1537 global pending_select
1540 if {$viewcomplete($curview)} {
1541 global commitidx varctok
1542 global numcommits startmsecs
1544 if {[info exists pending_select]} {
1546 reset_pending_select {}
1548 if {[commitinview $pending_select $curview]} {
1549 selectline [rowofcommit $pending_select] 1
1551 set row [first_real_row]
1555 if {$commitidx($curview) > 0} {
1556 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1557 #puts "overall $ms ms for $numcommits commits"
1558 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1560 show_status [mc "No commits selected"]
1567 proc do_readcommit {id} {
1570 # Invoke git-log to handle automatic encoding conversion
1571 set fd [open [concat | git log --no-color --pretty=raw -1 $id] r]
1572 # Read the results using i18n.logoutputencoding
1573 fconfigure $fd -translation lf -eofchar {}
1574 if {$tclencoding != {}} {
1575 fconfigure $fd -encoding $tclencoding
1577 set contents [read $fd]
1579 # Remove the heading line
1580 regsub {^commit [0-9a-f]+\n} $contents {} contents
1585 proc readcommit {id} {
1586 if {[catch {set contents [do_readcommit $id]}]} return
1587 parsecommit $id $contents 1
1590 proc parsecommit {id contents listed} {
1591 global commitinfo cdate
1600 set hdrend [string first "\n\n" $contents]
1602 # should never happen...
1603 set hdrend [string length $contents]
1605 set header [string range $contents 0 [expr {$hdrend - 1}]]
1606 set comment [string range $contents [expr {$hdrend + 2}] end]
1607 foreach line [split $header "\n"] {
1608 set line [split $line " "]
1609 set tag [lindex $line 0]
1610 if {$tag == "author"} {
1611 set audate [lindex $line end-1]
1612 set auname [join [lrange $line 1 end-2] " "]
1613 } elseif {$tag == "committer"} {
1614 set comdate [lindex $line end-1]
1615 set comname [join [lrange $line 1 end-2] " "]
1619 # take the first non-blank line of the comment as the headline
1620 set headline [string trimleft $comment]
1621 set i [string first "\n" $headline]
1623 set headline [string range $headline 0 $i]
1625 set headline [string trimright $headline]
1626 set i [string first "\r" $headline]
1628 set headline [string trimright [string range $headline 0 $i]]
1631 # git log indents the comment by 4 spaces;
1632 # if we got this via git cat-file, add the indentation
1634 foreach line [split $comment "\n"] {
1635 append newcomment " "
1636 append newcomment $line
1637 append newcomment "\n"
1639 set comment $newcomment
1641 if {$comdate != {}} {
1642 set cdate($id) $comdate
1644 set commitinfo($id) [list $headline $auname $audate \
1645 $comname $comdate $comment]
1648 proc getcommit {id} {
1649 global commitdata commitinfo
1651 if {[info exists commitdata($id)]} {
1652 parsecommit $id $commitdata($id) 1
1655 if {![info exists commitinfo($id)]} {
1656 set commitinfo($id) [list [mc "No commit information available"]]
1662 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1663 # and are present in the current view.
1664 # This is fairly slow...
1665 proc longid {prefix} {
1666 global varcid curview
1669 foreach match [array names varcid "$curview,$prefix*"] {
1670 lappend ids [lindex [split $match ","] 1]
1676 global tagids idtags headids idheads tagobjid
1677 global otherrefids idotherrefs mainhead mainheadid
1678 global selecthead selectheadid
1680 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
1683 set refd [open [list | git show-ref -d] r]
1684 while {[gets $refd line] >= 0} {
1685 if {[string index $line 40] ne " "} continue
1686 set id [string range $line 0 39]
1687 set ref [string range $line 41 end]
1688 if {![string match "refs/*" $ref]} continue
1689 set name [string range $ref 5 end]
1690 if {[string match "remotes/*" $name]} {
1691 if {![string match "*/HEAD" $name]} {
1692 set headids($name) $id
1693 lappend idheads($id) $name
1695 } elseif {[string match "heads/*" $name]} {
1696 set name [string range $name 6 end]
1697 set headids($name) $id
1698 lappend idheads($id) $name
1699 } elseif {[string match "tags/*" $name]} {
1700 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1701 # which is what we want since the former is the commit ID
1702 set name [string range $name 5 end]
1703 if {[string match "*^{}" $name]} {
1704 set name [string range $name 0 end-3]
1706 set tagobjid($name) $id
1708 set tagids($name) $id
1709 lappend idtags($id) $name
1711 set otherrefids($name) $id
1712 lappend idotherrefs($id) $name
1719 set mainheadid [exec git rev-parse HEAD]
1720 set thehead [exec git symbolic-ref HEAD]
1721 if {[string match "refs/heads/*" $thehead]} {
1722 set mainhead [string range $thehead 11 end]
1726 if {$selecthead ne {}} {
1728 set selectheadid [exec git rev-parse --verify $selecthead]
1733 # skip over fake commits
1734 proc first_real_row {} {
1735 global nullid nullid2 numcommits
1737 for {set row 0} {$row < $numcommits} {incr row} {
1738 set id [commitonrow $row]
1739 if {$id ne $nullid && $id ne $nullid2} {
1746 # update things for a head moved to a child of its previous location
1747 proc movehead {id name} {
1748 global headids idheads
1750 removehead $headids($name) $name
1751 set headids($name) $id
1752 lappend idheads($id) $name
1755 # update things when a head has been removed
1756 proc removehead {id name} {
1757 global headids idheads
1759 if {$idheads($id) eq $name} {
1762 set i [lsearch -exact $idheads($id) $name]
1764 set idheads($id) [lreplace $idheads($id) $i $i]
1767 unset headids($name)
1770 proc make_transient {window origin} {
1773 # In MacOS Tk 8.4 transient appears to work by setting
1774 # overrideredirect, which is utterly useless, since the
1775 # windows get no border, and are not even kept above
1777 if {!$have_tk85 && [tk windowingsystem] eq {aqua}} return
1779 wm transient $window $origin
1781 # Windows fails to place transient windows normally, so
1782 # schedule a callback to center them on the parent.
1783 if {[tk windowingsystem] eq {win32}} {
1784 after idle [list tk::PlaceWindow $window widget $origin]
1788 proc show_error {w top msg} {
1789 message $w.m -text $msg -justify center -aspect 400
1790 pack $w.m -side top -fill x -padx 20 -pady 20
1791 button $w.ok -text [mc OK] -command "destroy $top"
1792 pack $w.ok -side bottom -fill x
1793 bind $top <Visibility> "grab $top; focus $top"
1794 bind $top <Key-Return> "destroy $top"
1795 bind $top <Key-space> "destroy $top"
1796 bind $top <Key-Escape> "destroy $top"
1800 proc error_popup {msg {owner .}} {
1803 make_transient $w $owner
1804 show_error $w $w $msg
1807 proc confirm_popup {msg {owner .}} {
1812 make_transient $w $owner
1813 message $w.m -text $msg -justify center -aspect 400
1814 pack $w.m -side top -fill x -padx 20 -pady 20
1815 button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
1816 pack $w.ok -side left -fill x
1817 button $w.cancel -text [mc Cancel] -command "destroy $w"
1818 pack $w.cancel -side right -fill x
1819 bind $w <Visibility> "grab $w; focus $w"
1820 bind $w <Key-Return> "set confirm_ok 1; destroy $w"
1821 bind $w <Key-space> "set confirm_ok 1; destroy $w"
1822 bind $w <Key-Escape> "destroy $w"
1827 proc setoptions {} {
1828 option add *Panedwindow.showHandle 1 startupFile
1829 option add *Panedwindow.sashRelief raised startupFile
1830 option add *Button.font uifont startupFile
1831 option add *Checkbutton.font uifont startupFile
1832 option add *Radiobutton.font uifont startupFile
1833 if {[tk windowingsystem] ne "aqua"} {
1834 option add *Menu.font uifont startupFile
1836 option add *Menubutton.font uifont startupFile
1837 option add *Label.font uifont startupFile
1838 option add *Message.font uifont startupFile
1839 option add *Entry.font uifont startupFile
1842 # Make a menu and submenus.
1843 # m is the window name for the menu, items is the list of menu items to add.
1844 # Each item is a list {mc label type description options...}
1845 # mc is ignored; it's so we can put mc there to alert xgettext
1846 # label is the string that appears in the menu
1847 # type is cascade, command or radiobutton (should add checkbutton)
1848 # description depends on type; it's the sublist for cascade, the
1849 # command to invoke for command, or {variable value} for radiobutton
1850 proc makemenu {m items} {
1852 if {[tk windowingsystem] eq {aqua}} {
1858 set name [mc [lindex $i 1]]
1859 set type [lindex $i 2]
1860 set thing [lindex $i 3]
1861 set params [list $type]
1863 set u [string first "&" [string map {&& x} $name]]
1864 lappend params -label [string map {&& & & {}} $name]
1866 lappend params -underline $u
1871 set submenu [string tolower [string map {& ""} [lindex $i 1]]]
1872 lappend params -menu $m.$submenu
1875 lappend params -command $thing
1878 lappend params -variable [lindex $thing 0] \
1879 -value [lindex $thing 1]
1882 set tail [lrange $i 4 end]
1883 regsub -all {\yMeta1\y} $tail $Meta1 tail
1884 eval $m add $params $tail
1885 if {$type eq "cascade"} {
1886 makemenu $m.$submenu $thing
1891 # translate string and remove ampersands
1893 return [string map {&& & & {}} [mc $str]]
1896 proc makewindow {} {
1897 global canv canv2 canv3 linespc charspc ctext cflist cscroll
1899 global findtype findtypemenu findloc findstring fstring geometry
1900 global entries sha1entry sha1string sha1but
1901 global diffcontextstring diffcontext
1903 global maincursor textcursor curtextcursor
1904 global rowctxmenu fakerowmenu mergemax wrapcomment
1905 global highlight_files gdttype
1906 global searchstring sstring
1907 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
1908 global headctxmenu progresscanv progressitem progresscoords statusw
1909 global fprogitem fprogcoord lastprogupdate progupdatepending
1910 global rprogitem rprogcoord rownumsel numcommits
1913 # The "mc" arguments here are purely so that xgettext
1914 # sees the following string as needing to be translated
1917 {mc "Update" command updatecommits -accelerator F5}
1918 {mc "Reload" command reloadcommits -accelerator Meta1-F5}
1919 {mc "Reread references" command rereadrefs}
1920 {mc "List references" command showrefs -accelerator F2}
1922 {mc "Start git gui" command {exec git gui &}}
1924 {mc "Quit" command doquit -accelerator Meta1-Q}
1928 {mc "Preferences" command doprefs}
1932 {mc "New view..." command {newview 0} -accelerator Shift-F4}
1933 {mc "Edit view..." command editview -state disabled -accelerator F4}
1934 {mc "Delete view" command delview -state disabled}
1936 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
1938 if {[tk windowingsystem] ne "aqua"} {
1941 {mc "About gitk" command about}
1942 {mc "Key bindings" command keys}
1944 set bar [list $file $edit $view $help]
1946 proc ::tk::mac::ShowPreferences {} {doprefs}
1947 proc ::tk::mac::Quit {} {doquit}
1948 lset file end [lreplace [lindex $file end] end-1 end]
1950 xx "Apple" cascade {
1951 {mc "About gitk" command about}
1956 {mc "Key bindings" command keys}
1958 set bar [list $apple $file $view $help]
1961 . configure -menu .bar
1963 # the gui has upper and lower half, parts of a paned window.
1964 panedwindow .ctop -orient vertical
1966 # possibly use assumed geometry
1967 if {![info exists geometry(pwsash0)]} {
1968 set geometry(topheight) [expr {15 * $linespc}]
1969 set geometry(topwidth) [expr {80 * $charspc}]
1970 set geometry(botheight) [expr {15 * $linespc}]
1971 set geometry(botwidth) [expr {50 * $charspc}]
1972 set geometry(pwsash0) "[expr {40 * $charspc}] 2"
1973 set geometry(pwsash1) "[expr {60 * $charspc}] 2"
1976 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
1977 frame .tf -height $geometry(topheight) -width $geometry(topwidth)
1979 panedwindow .tf.histframe.pwclist -orient horizontal -sashpad 0 -handlesize 4
1981 # create three canvases
1982 set cscroll .tf.histframe.csb
1983 set canv .tf.histframe.pwclist.canv
1985 -selectbackground $selectbgcolor \
1986 -background $bgcolor -bd 0 \
1987 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
1988 .tf.histframe.pwclist add $canv
1989 set canv2 .tf.histframe.pwclist.canv2
1991 -selectbackground $selectbgcolor \
1992 -background $bgcolor -bd 0 -yscrollincr $linespc
1993 .tf.histframe.pwclist add $canv2
1994 set canv3 .tf.histframe.pwclist.canv3
1996 -selectbackground $selectbgcolor \
1997 -background $bgcolor -bd 0 -yscrollincr $linespc
1998 .tf.histframe.pwclist add $canv3
1999 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2000 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2002 # a scroll bar to rule them
2003 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
2004 pack $cscroll -side right -fill y
2005 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2006 lappend bglist $canv $canv2 $canv3
2007 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2009 # we have two button bars at bottom of top frame. Bar 1
2011 frame .tf.lbar -height 15
2013 set sha1entry .tf.bar.sha1
2014 set entries $sha1entry
2015 set sha1but .tf.bar.sha1label
2016 button $sha1but -text [mc "SHA1 ID: "] -state disabled -relief flat \
2017 -command gotocommit -width 8
2018 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2019 pack .tf.bar.sha1label -side left
2020 entry $sha1entry -width 40 -font textfont -textvariable sha1string
2021 trace add variable sha1string write sha1change
2022 pack $sha1entry -side left -pady 2
2024 image create bitmap bm-left -data {
2025 #define left_width 16
2026 #define left_height 16
2027 static unsigned char left_bits[] = {
2028 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2029 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2030 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2032 image create bitmap bm-right -data {
2033 #define right_width 16
2034 #define right_height 16
2035 static unsigned char right_bits[] = {
2036 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2037 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2038 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2040 button .tf.bar.leftbut -image bm-left -command goback \
2041 -state disabled -width 26
2042 pack .tf.bar.leftbut -side left -fill y
2043 button .tf.bar.rightbut -image bm-right -command goforw \
2044 -state disabled -width 26
2045 pack .tf.bar.rightbut -side left -fill y
2047 label .tf.bar.rowlabel -text [mc "Row"]
2049 label .tf.bar.rownum -width 7 -font textfont -textvariable rownumsel \
2050 -relief sunken -anchor e
2051 label .tf.bar.rowlabel2 -text "/"
2052 label .tf.bar.numcommits -width 7 -font textfont -textvariable numcommits \
2053 -relief sunken -anchor e
2054 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2057 trace add variable selectedline write selectedline_change
2059 # Status label and progress bar
2060 set statusw .tf.bar.status
2061 label $statusw -width 15 -relief sunken
2062 pack $statusw -side left -padx 5
2063 set h [expr {[font metrics uifont -linespace] + 2}]
2064 set progresscanv .tf.bar.progress
2065 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2066 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2067 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2068 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2069 pack $progresscanv -side right -expand 1 -fill x
2070 set progresscoords {0 0}
2073 bind $progresscanv <Configure> adjustprogress
2074 set lastprogupdate [clock clicks -milliseconds]
2075 set progupdatepending 0
2077 # build up the bottom bar of upper window
2078 label .tf.lbar.flabel -text "[mc "Find"] "
2079 button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1}
2080 button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1}
2081 label .tf.lbar.flab2 -text " [mc "commit"] "
2082 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2084 set gdttype [mc "containing:"]
2085 set gm [tk_optionMenu .tf.lbar.gdttype gdttype \
2086 [mc "containing:"] \
2087 [mc "touching paths:"] \
2088 [mc "adding/removing string:"]]
2089 trace add variable gdttype write gdttype_change
2090 pack .tf.lbar.gdttype -side left -fill y
2093 set fstring .tf.lbar.findstring
2094 lappend entries $fstring
2095 entry $fstring -width 30 -font textfont -textvariable findstring
2096 trace add variable findstring write find_change
2097 set findtype [mc "Exact"]
2098 set findtypemenu [tk_optionMenu .tf.lbar.findtype \
2099 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2100 trace add variable findtype write findcom_change
2101 set findloc [mc "All fields"]
2102 tk_optionMenu .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2103 [mc "Comments"] [mc "Author"] [mc "Committer"]
2104 trace add variable findloc write find_change
2105 pack .tf.lbar.findloc -side right
2106 pack .tf.lbar.findtype -side right
2107 pack $fstring -side left -expand 1 -fill x
2109 # Finish putting the upper half of the viewer together
2110 pack .tf.lbar -in .tf -side bottom -fill x
2111 pack .tf.bar -in .tf -side bottom -fill x
2112 pack .tf.histframe -fill both -side top -expand 1
2114 .ctop paneconfigure .tf -height $geometry(topheight)
2115 .ctop paneconfigure .tf -width $geometry(topwidth)
2117 # now build up the bottom
2118 panedwindow .pwbottom -orient horizontal
2120 # lower left, a text box over search bar, scroll bar to the right
2121 # if we know window height, then that will set the lower text height, otherwise
2122 # we set lower text height which will drive window height
2123 if {[info exists geometry(main)]} {
2124 frame .bleft -width $geometry(botwidth)
2126 frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2132 button .bleft.top.search -text [mc "Search"] -command dosearch
2133 pack .bleft.top.search -side left -padx 5
2134 set sstring .bleft.top.sstring
2135 entry $sstring -width 20 -font textfont -textvariable searchstring
2136 lappend entries $sstring
2137 trace add variable searchstring write incrsearch
2138 pack $sstring -side left -expand 1 -fill x
2139 radiobutton .bleft.mid.diff -text [mc "Diff"] \
2140 -command changediffdisp -variable diffelide -value {0 0}
2141 radiobutton .bleft.mid.old -text [mc "Old version"] \
2142 -command changediffdisp -variable diffelide -value {0 1}
2143 radiobutton .bleft.mid.new -text [mc "New version"] \
2144 -command changediffdisp -variable diffelide -value {1 0}
2145 label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2146 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2147 spinbox .bleft.mid.diffcontext -width 5 -font textfont \
2148 -from 1 -increment 1 -to 10000000 \
2149 -validate all -validatecommand "diffcontextvalidate %P" \
2150 -textvariable diffcontextstring
2151 .bleft.mid.diffcontext set $diffcontext
2152 trace add variable diffcontextstring write diffcontextchange
2153 lappend entries .bleft.mid.diffcontext
2154 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2155 checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2156 -command changeignorespace -variable ignorespace
2157 pack .bleft.mid.ignspace -side left -padx 5
2158 set ctext .bleft.bottom.ctext
2159 text $ctext -background $bgcolor -foreground $fgcolor \
2160 -state disabled -font textfont \
2161 -yscrollcommand scrolltext -wrap none \
2162 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2164 $ctext conf -tabstyle wordprocessor
2166 scrollbar .bleft.bottom.sb -command "$ctext yview"
2167 scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h \
2169 pack .bleft.top -side top -fill x
2170 pack .bleft.mid -side top -fill x
2171 grid $ctext .bleft.bottom.sb -sticky nsew
2172 grid .bleft.bottom.sbhorizontal -sticky ew
2173 grid columnconfigure .bleft.bottom 0 -weight 1
2174 grid rowconfigure .bleft.bottom 0 -weight 1
2175 grid rowconfigure .bleft.bottom 1 -weight 0
2176 pack .bleft.bottom -side top -fill both -expand 1
2177 lappend bglist $ctext
2178 lappend fglist $ctext
2180 $ctext tag conf comment -wrap $wrapcomment
2181 $ctext tag conf filesep -font textfontbold -back "#aaaaaa"
2182 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2183 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2184 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2185 $ctext tag conf m0 -fore red
2186 $ctext tag conf m1 -fore blue
2187 $ctext tag conf m2 -fore green
2188 $ctext tag conf m3 -fore purple
2189 $ctext tag conf m4 -fore brown
2190 $ctext tag conf m5 -fore "#009090"
2191 $ctext tag conf m6 -fore magenta
2192 $ctext tag conf m7 -fore "#808000"
2193 $ctext tag conf m8 -fore "#009000"
2194 $ctext tag conf m9 -fore "#ff0080"
2195 $ctext tag conf m10 -fore cyan
2196 $ctext tag conf m11 -fore "#b07070"
2197 $ctext tag conf m12 -fore "#70b0f0"
2198 $ctext tag conf m13 -fore "#70f0b0"
2199 $ctext tag conf m14 -fore "#f0b070"
2200 $ctext tag conf m15 -fore "#ff70b0"
2201 $ctext tag conf mmax -fore darkgrey
2203 $ctext tag conf mresult -font textfontbold
2204 $ctext tag conf msep -font textfontbold
2205 $ctext tag conf found -back yellow
2207 .pwbottom add .bleft
2208 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2213 radiobutton .bright.mode.patch -text [mc "Patch"] \
2214 -command reselectline -variable cmitmode -value "patch"
2215 radiobutton .bright.mode.tree -text [mc "Tree"] \
2216 -command reselectline -variable cmitmode -value "tree"
2217 grid .bright.mode.patch .bright.mode.tree -sticky ew
2218 pack .bright.mode -side top -fill x
2219 set cflist .bright.cfiles
2220 set indent [font measure mainfont "nn"]
2222 -selectbackground $selectbgcolor \
2223 -background $bgcolor -foreground $fgcolor \
2225 -tabs [list $indent [expr {2 * $indent}]] \
2226 -yscrollcommand ".bright.sb set" \
2227 -cursor [. cget -cursor] \
2228 -spacing1 1 -spacing3 1
2229 lappend bglist $cflist
2230 lappend fglist $cflist
2231 scrollbar .bright.sb -command "$cflist yview"
2232 pack .bright.sb -side right -fill y
2233 pack $cflist -side left -fill both -expand 1
2234 $cflist tag configure highlight \
2235 -background [$cflist cget -selectbackground]
2236 $cflist tag configure bold -font mainfontbold
2238 .pwbottom add .bright
2241 # restore window width & height if known
2242 if {[info exists geometry(main)]} {
2243 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2244 if {$w > [winfo screenwidth .]} {
2245 set w [winfo screenwidth .]
2247 if {$h > [winfo screenheight .]} {
2248 set h [winfo screenheight .]
2250 wm geometry . "${w}x$h"
2254 if {[tk windowingsystem] eq {aqua}} {
2262 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2263 pack .ctop -fill both -expand 1
2264 bindall <1> {selcanvline %W %x %y}
2265 #bindall <B1-Motion> {selcanvline %W %x %y}
2266 if {[tk windowingsystem] == "win32"} {
2267 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2268 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2270 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2271 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2272 if {[tk windowingsystem] eq "aqua"} {
2273 bindall <MouseWheel> {
2274 set delta [expr {- (%D)}]
2275 allcanvs yview scroll $delta units
2277 bindall <Shift-MouseWheel> {
2278 set delta [expr {- (%D)}]
2279 $canv xview scroll $delta units
2283 bindall <$::BM> "canvscan mark %W %x %y"
2284 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2285 bindkey <Home> selfirstline
2286 bindkey <End> sellastline
2287 bind . <Key-Up> "selnextline -1"
2288 bind . <Key-Down> "selnextline 1"
2289 bind . <Shift-Key-Up> "dofind -1 0"
2290 bind . <Shift-Key-Down> "dofind 1 0"
2291 bindkey <Key-Right> "goforw"
2292 bindkey <Key-Left> "goback"
2293 bind . <Key-Prior> "selnextpage -1"
2294 bind . <Key-Next> "selnextpage 1"
2295 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2296 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2297 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2298 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2299 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2300 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2301 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2302 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2303 bindkey <Key-space> "$ctext yview scroll 1 pages"
2304 bindkey p "selnextline -1"
2305 bindkey n "selnextline 1"
2308 bindkey i "selnextline -1"
2309 bindkey k "selnextline 1"
2313 bindkey d "$ctext yview scroll 18 units"
2314 bindkey u "$ctext yview scroll -18 units"
2315 bindkey / {focus $fstring}
2316 bindkey <Key-Return> {dofind 1 1}
2317 bindkey ? {dofind -1 1}
2319 bind . <F5> updatecommits
2320 bind . <$M1B-F5> reloadcommits
2321 bind . <F2> showrefs
2322 bind . <Shift-F4> {newview 0}
2323 catch { bind . <Shift-Key-XF86_Switch_VT_4> {newview 0} }
2324 bind . <F4> edit_or_newview
2325 bind . <$M1B-q> doquit
2326 bind . <$M1B-f> {dofind 1 1}
2327 bind . <$M1B-g> {dofind 1 0}
2328 bind . <$M1B-r> dosearchback
2329 bind . <$M1B-s> dosearch
2330 bind . <$M1B-equal> {incrfont 1}
2331 bind . <$M1B-plus> {incrfont 1}
2332 bind . <$M1B-KP_Add> {incrfont 1}
2333 bind . <$M1B-minus> {incrfont -1}
2334 bind . <$M1B-KP_Subtract> {incrfont -1}
2335 wm protocol . WM_DELETE_WINDOW doquit
2336 bind . <Destroy> {stop_backends}
2337 bind . <Button-1> "click %W"
2338 bind $fstring <Key-Return> {dofind 1 1}
2339 bind $sha1entry <Key-Return> {gotocommit; break}
2340 bind $sha1entry <<PasteSelection>> clearsha1
2341 bind $cflist <1> {sel_flist %W %x %y; break}
2342 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2343 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2345 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2346 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2348 set maincursor [. cget -cursor]
2349 set textcursor [$ctext cget -cursor]
2350 set curtextcursor $textcursor
2352 set rowctxmenu .rowctxmenu
2353 makemenu $rowctxmenu {
2354 {mc "Diff this -> selected" command {diffvssel 0}}
2355 {mc "Diff selected -> this" command {diffvssel 1}}
2356 {mc "Make patch" command mkpatch}
2357 {mc "Create tag" command mktag}
2358 {mc "Write commit to file" command writecommit}
2359 {mc "Create new branch" command mkbranch}
2360 {mc "Cherry-pick this commit" command cherrypick}
2361 {mc "Reset HEAD branch to here" command resethead}
2363 $rowctxmenu configure -tearoff 0
2365 set fakerowmenu .fakerowmenu
2366 makemenu $fakerowmenu {
2367 {mc "Diff this -> selected" command {diffvssel 0}}
2368 {mc "Diff selected -> this" command {diffvssel 1}}
2369 {mc "Make patch" command mkpatch}
2371 $fakerowmenu configure -tearoff 0
2373 set headctxmenu .headctxmenu
2374 makemenu $headctxmenu {
2375 {mc "Check out this branch" command cobranch}
2376 {mc "Remove this branch" command rmbranch}
2378 $headctxmenu configure -tearoff 0
2381 set flist_menu .flistctxmenu
2382 makemenu $flist_menu {
2383 {mc "Highlight this too" command {flist_hl 0}}
2384 {mc "Highlight this only" command {flist_hl 1}}
2385 {mc "External diff" command {external_diff}}
2386 {mc "Blame parent commit" command {external_blame 1}}
2388 $flist_menu configure -tearoff 0
2391 set diff_menu .diffctxmenu
2392 makemenu $diff_menu {
2393 {mc "Show origin of this line" command show_line_source}
2394 {mc "Run git gui blame on this line" command {external_blame_diff}}
2396 $diff_menu configure -tearoff 0
2399 # Windows sends all mouse wheel events to the current focused window, not
2400 # the one where the mouse hovers, so bind those events here and redirect
2401 # to the correct window
2402 proc windows_mousewheel_redirector {W X Y D} {
2403 global canv canv2 canv3
2404 set w [winfo containing -displayof $W $X $Y]
2406 set u [expr {$D < 0 ? 5 : -5}]
2407 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2408 allcanvs yview scroll $u units
2411 $w yview scroll $u units
2417 # Update row number label when selectedline changes
2418 proc selectedline_change {n1 n2 op} {
2419 global selectedline rownumsel
2421 if {$selectedline eq {}} {
2424 set rownumsel [expr {$selectedline + 1}]
2428 # mouse-2 makes all windows scan vertically, but only the one
2429 # the cursor is in scans horizontally
2430 proc canvscan {op w x y} {
2431 global canv canv2 canv3
2432 foreach c [list $canv $canv2 $canv3] {
2441 proc scrollcanv {cscroll f0 f1} {
2442 $cscroll set $f0 $f1
2447 # when we make a key binding for the toplevel, make sure
2448 # it doesn't get triggered when that key is pressed in the
2449 # find string entry widget.
2450 proc bindkey {ev script} {
2453 set escript [bind Entry $ev]
2454 if {$escript == {}} {
2455 set escript [bind Entry <Key>]
2457 foreach e $entries {
2458 bind $e $ev "$escript; break"
2462 # set the focus back to the toplevel for any click outside
2465 global ctext entries
2466 foreach e [concat $entries $ctext] {
2467 if {$w == $e} return
2472 # Adjust the progress bar for a change in requested extent or canvas size
2473 proc adjustprogress {} {
2474 global progresscanv progressitem progresscoords
2475 global fprogitem fprogcoord lastprogupdate progupdatepending
2476 global rprogitem rprogcoord
2478 set w [expr {[winfo width $progresscanv] - 4}]
2479 set x0 [expr {$w * [lindex $progresscoords 0]}]
2480 set x1 [expr {$w * [lindex $progresscoords 1]}]
2481 set h [winfo height $progresscanv]
2482 $progresscanv coords $progressitem $x0 0 $x1 $h
2483 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2484 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2485 set now [clock clicks -milliseconds]
2486 if {$now >= $lastprogupdate + 100} {
2487 set progupdatepending 0
2489 } elseif {!$progupdatepending} {
2490 set progupdatepending 1
2491 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2495 proc doprogupdate {} {
2496 global lastprogupdate progupdatepending
2498 if {$progupdatepending} {
2499 set progupdatepending 0
2500 set lastprogupdate [clock clicks -milliseconds]
2505 proc savestuff {w} {
2506 global canv canv2 canv3 mainfont textfont uifont tabstop
2507 global stuffsaved findmergefiles maxgraphpct
2508 global maxwidth showneartags showlocalchanges
2509 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2510 global cmitmode wrapcomment datetimeformat limitdiffs
2511 global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor
2512 global autoselect extdifftool perfile_attrs markbgcolor
2514 if {$stuffsaved} return
2515 if {![winfo viewable .]} return
2517 set f [open "~/.gitk-new" w]
2518 puts $f [list set mainfont $mainfont]
2519 puts $f [list set textfont $textfont]
2520 puts $f [list set uifont $uifont]
2521 puts $f [list set tabstop $tabstop]
2522 puts $f [list set findmergefiles $findmergefiles]
2523 puts $f [list set maxgraphpct $maxgraphpct]
2524 puts $f [list set maxwidth $maxwidth]
2525 puts $f [list set cmitmode $cmitmode]
2526 puts $f [list set wrapcomment $wrapcomment]
2527 puts $f [list set autoselect $autoselect]
2528 puts $f [list set showneartags $showneartags]
2529 puts $f [list set showlocalchanges $showlocalchanges]
2530 puts $f [list set datetimeformat $datetimeformat]
2531 puts $f [list set limitdiffs $limitdiffs]
2532 puts $f [list set bgcolor $bgcolor]
2533 puts $f [list set fgcolor $fgcolor]
2534 puts $f [list set colors $colors]
2535 puts $f [list set diffcolors $diffcolors]
2536 puts $f [list set markbgcolor $markbgcolor]
2537 puts $f [list set diffcontext $diffcontext]
2538 puts $f [list set selectbgcolor $selectbgcolor]
2539 puts $f [list set extdifftool $extdifftool]
2540 puts $f [list set perfile_attrs $perfile_attrs]
2542 puts $f "set geometry(main) [wm geometry .]"
2543 puts $f "set geometry(topwidth) [winfo width .tf]"
2544 puts $f "set geometry(topheight) [winfo height .tf]"
2545 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2546 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2547 puts $f "set geometry(botwidth) [winfo width .bleft]"
2548 puts $f "set geometry(botheight) [winfo height .bleft]"
2550 puts -nonewline $f "set permviews {"
2551 for {set v 0} {$v < $nextviewnum} {incr v} {
2552 if {$viewperm($v)} {
2553 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2558 file rename -force "~/.gitk-new" "~/.gitk"
2563 proc resizeclistpanes {win w} {
2565 if {[info exists oldwidth($win)]} {
2566 set s0 [$win sash coord 0]
2567 set s1 [$win sash coord 1]
2569 set sash0 [expr {int($w/2 - 2)}]
2570 set sash1 [expr {int($w*5/6 - 2)}]
2572 set factor [expr {1.0 * $w / $oldwidth($win)}]
2573 set sash0 [expr {int($factor * [lindex $s0 0])}]
2574 set sash1 [expr {int($factor * [lindex $s1 0])}]
2578 if {$sash1 < $sash0 + 20} {
2579 set sash1 [expr {$sash0 + 20}]
2581 if {$sash1 > $w - 10} {
2582 set sash1 [expr {$w - 10}]
2583 if {$sash0 > $sash1 - 20} {
2584 set sash0 [expr {$sash1 - 20}]
2588 $win sash place 0 $sash0 [lindex $s0 1]
2589 $win sash place 1 $sash1 [lindex $s1 1]
2591 set oldwidth($win) $w
2594 proc resizecdetpanes {win w} {
2596 if {[info exists oldwidth($win)]} {
2597 set s0 [$win sash coord 0]
2599 set sash0 [expr {int($w*3/4 - 2)}]
2601 set factor [expr {1.0 * $w / $oldwidth($win)}]
2602 set sash0 [expr {int($factor * [lindex $s0 0])}]
2606 if {$sash0 > $w - 15} {
2607 set sash0 [expr {$w - 15}]
2610 $win sash place 0 $sash0 [lindex $s0 1]
2612 set oldwidth($win) $w
2615 proc allcanvs args {
2616 global canv canv2 canv3
2622 proc bindall {event action} {
2623 global canv canv2 canv3
2624 bind $canv $event $action
2625 bind $canv2 $event $action
2626 bind $canv3 $event $action
2632 if {[winfo exists $w]} {
2637 wm title $w [mc "About gitk"]
2639 message $w.m -text [mc "
2640 Gitk - a commit viewer for git
2642 Copyright © 2005-2008 Paul Mackerras
2644 Use and redistribute under the terms of the GNU General Public License"] \
2645 -justify center -aspect 400 -border 2 -bg white -relief groove
2646 pack $w.m -side top -fill x -padx 2 -pady 2
2647 button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2648 pack $w.ok -side bottom
2649 bind $w <Visibility> "focus $w.ok"
2650 bind $w <Key-Escape> "destroy $w"
2651 bind $w <Key-Return> "destroy $w"
2656 if {[winfo exists $w]} {
2660 if {[tk windowingsystem] eq {aqua}} {
2666 wm title $w [mc "Gitk key bindings"]
2668 message $w.m -text "
2669 [mc "Gitk key bindings:"]
2671 [mc "<%s-Q> Quit" $M1T]
2672 [mc "<Home> Move to first commit"]
2673 [mc "<End> Move to last commit"]
2674 [mc "<Up>, p, i Move up one commit"]
2675 [mc "<Down>, n, k Move down one commit"]
2676 [mc "<Left>, z, j Go back in history list"]
2677 [mc "<Right>, x, l Go forward in history list"]
2678 [mc "<PageUp> Move up one page in commit list"]
2679 [mc "<PageDown> Move down one page in commit list"]
2680 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2681 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2682 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2683 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2684 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2685 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2686 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2687 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2688 [mc "<Delete>, b Scroll diff view up one page"]
2689 [mc "<Backspace> Scroll diff view up one page"]
2690 [mc "<Space> Scroll diff view down one page"]
2691 [mc "u Scroll diff view up 18 lines"]
2692 [mc "d Scroll diff view down 18 lines"]
2693 [mc "<%s-F> Find" $M1T]
2694 [mc "<%s-G> Move to next find hit" $M1T]
2695 [mc "<Return> Move to next find hit"]
2696 [mc "/ Focus the search box"]
2697 [mc "? Move to previous find hit"]
2698 [mc "f Scroll diff view to next file"]
2699 [mc "<%s-S> Search for next hit in diff view" $M1T]
2700 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2701 [mc "<%s-KP+> Increase font size" $M1T]
2702 [mc "<%s-plus> Increase font size" $M1T]
2703 [mc "<%s-KP-> Decrease font size" $M1T]
2704 [mc "<%s-minus> Decrease font size" $M1T]
2707 -justify left -bg white -border 2 -relief groove
2708 pack $w.m -side top -fill both -padx 2 -pady 2
2709 button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2710 bind $w <Key-Escape> [list destroy $w]
2711 pack $w.ok -side bottom
2712 bind $w <Visibility> "focus $w.ok"
2713 bind $w <Key-Escape> "destroy $w"
2714 bind $w <Key-Return> "destroy $w"
2717 # Procedures for manipulating the file list window at the
2718 # bottom right of the overall window.
2720 proc treeview {w l openlevs} {
2721 global treecontents treediropen treeheight treeparent treeindex
2731 set treecontents() {}
2732 $w conf -state normal
2734 while {[string range $f 0 $prefixend] ne $prefix} {
2735 if {$lev <= $openlevs} {
2736 $w mark set e:$treeindex($prefix) "end -1c"
2737 $w mark gravity e:$treeindex($prefix) left
2739 set treeheight($prefix) $ht
2740 incr ht [lindex $htstack end]
2741 set htstack [lreplace $htstack end end]
2742 set prefixend [lindex $prefendstack end]
2743 set prefendstack [lreplace $prefendstack end end]
2744 set prefix [string range $prefix 0 $prefixend]
2747 set tail [string range $f [expr {$prefixend+1}] end]
2748 while {[set slash [string first "/" $tail]] >= 0} {
2751 lappend prefendstack $prefixend
2752 incr prefixend [expr {$slash + 1}]
2753 set d [string range $tail 0 $slash]
2754 lappend treecontents($prefix) $d
2755 set oldprefix $prefix
2757 set treecontents($prefix) {}
2758 set treeindex($prefix) [incr ix]
2759 set treeparent($prefix) $oldprefix
2760 set tail [string range $tail [expr {$slash+1}] end]
2761 if {$lev <= $openlevs} {
2763 set treediropen($prefix) [expr {$lev < $openlevs}]
2764 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
2765 $w mark set d:$ix "end -1c"
2766 $w mark gravity d:$ix left
2768 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2770 $w image create end -align center -image $bm -padx 1 \
2772 $w insert end $d [highlight_tag $prefix]
2773 $w mark set s:$ix "end -1c"
2774 $w mark gravity s:$ix left
2779 if {$lev <= $openlevs} {
2782 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2784 $w insert end $tail [highlight_tag $f]
2786 lappend treecontents($prefix) $tail
2789 while {$htstack ne {}} {
2790 set treeheight($prefix) $ht
2791 incr ht [lindex $htstack end]
2792 set htstack [lreplace $htstack end end]
2793 set prefixend [lindex $prefendstack end]
2794 set prefendstack [lreplace $prefendstack end end]
2795 set prefix [string range $prefix 0 $prefixend]
2797 $w conf -state disabled
2800 proc linetoelt {l} {
2801 global treeheight treecontents
2806 foreach e $treecontents($prefix) {
2811 if {[string index $e end] eq "/"} {
2812 set n $treeheight($prefix$e)
2824 proc highlight_tree {y prefix} {
2825 global treeheight treecontents cflist
2827 foreach e $treecontents($prefix) {
2829 if {[highlight_tag $path] ne {}} {
2830 $cflist tag add bold $y.0 "$y.0 lineend"
2833 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
2834 set y [highlight_tree $y $path]
2840 proc treeclosedir {w dir} {
2841 global treediropen treeheight treeparent treeindex
2843 set ix $treeindex($dir)
2844 $w conf -state normal
2845 $w delete s:$ix e:$ix
2846 set treediropen($dir) 0
2847 $w image configure a:$ix -image tri-rt
2848 $w conf -state disabled
2849 set n [expr {1 - $treeheight($dir)}]
2850 while {$dir ne {}} {
2851 incr treeheight($dir) $n
2852 set dir $treeparent($dir)
2856 proc treeopendir {w dir} {
2857 global treediropen treeheight treeparent treecontents treeindex
2859 set ix $treeindex($dir)
2860 $w conf -state normal
2861 $w image configure a:$ix -image tri-dn
2862 $w mark set e:$ix s:$ix
2863 $w mark gravity e:$ix right
2866 set n [llength $treecontents($dir)]
2867 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
2870 incr treeheight($x) $n
2872 foreach e $treecontents($dir) {
2874 if {[string index $e end] eq "/"} {
2875 set iy $treeindex($de)
2876 $w mark set d:$iy e:$ix
2877 $w mark gravity d:$iy left
2878 $w insert e:$ix $str
2879 set treediropen($de) 0
2880 $w image create e:$ix -align center -image tri-rt -padx 1 \
2882 $w insert e:$ix $e [highlight_tag $de]
2883 $w mark set s:$iy e:$ix
2884 $w mark gravity s:$iy left
2885 set treeheight($de) 1
2887 $w insert e:$ix $str
2888 $w insert e:$ix $e [highlight_tag $de]
2891 $w mark gravity e:$ix right
2892 $w conf -state disabled
2893 set treediropen($dir) 1
2894 set top [lindex [split [$w index @0,0] .] 0]
2895 set ht [$w cget -height]
2896 set l [lindex [split [$w index s:$ix] .] 0]
2899 } elseif {$l + $n + 1 > $top + $ht} {
2900 set top [expr {$l + $n + 2 - $ht}]
2908 proc treeclick {w x y} {
2909 global treediropen cmitmode ctext cflist cflist_top
2911 if {$cmitmode ne "tree"} return
2912 if {![info exists cflist_top]} return
2913 set l [lindex [split [$w index "@$x,$y"] "."] 0]
2914 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
2915 $cflist tag add highlight $l.0 "$l.0 lineend"
2921 set e [linetoelt $l]
2922 if {[string index $e end] ne "/"} {
2924 } elseif {$treediropen($e)} {
2931 proc setfilelist {id} {
2932 global treefilelist cflist jump_to_here
2934 treeview $cflist $treefilelist($id) 0
2935 if {$jump_to_here ne {}} {
2936 set f [lindex $jump_to_here 0]
2937 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
2943 image create bitmap tri-rt -background black -foreground blue -data {
2944 #define tri-rt_width 13
2945 #define tri-rt_height 13
2946 static unsigned char tri-rt_bits[] = {
2947 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
2948 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
2951 #define tri-rt-mask_width 13
2952 #define tri-rt-mask_height 13
2953 static unsigned char tri-rt-mask_bits[] = {
2954 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
2955 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
2958 image create bitmap tri-dn -background black -foreground blue -data {
2959 #define tri-dn_width 13
2960 #define tri-dn_height 13
2961 static unsigned char tri-dn_bits[] = {
2962 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
2963 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2966 #define tri-dn-mask_width 13
2967 #define tri-dn-mask_height 13
2968 static unsigned char tri-dn-mask_bits[] = {
2969 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
2970 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
2974 image create bitmap reficon-T -background black -foreground yellow -data {
2975 #define tagicon_width 13
2976 #define tagicon_height 9
2977 static unsigned char tagicon_bits[] = {
2978 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
2979 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
2981 #define tagicon-mask_width 13
2982 #define tagicon-mask_height 9
2983 static unsigned char tagicon-mask_bits[] = {
2984 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
2985 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
2988 #define headicon_width 13
2989 #define headicon_height 9
2990 static unsigned char headicon_bits[] = {
2991 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
2992 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
2995 #define headicon-mask_width 13
2996 #define headicon-mask_height 9
2997 static unsigned char headicon-mask_bits[] = {
2998 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
2999 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3001 image create bitmap reficon-H -background black -foreground green \
3002 -data $rectdata -maskdata $rectmask
3003 image create bitmap reficon-o -background black -foreground "#ddddff" \
3004 -data $rectdata -maskdata $rectmask
3006 proc init_flist {first} {
3007 global cflist cflist_top difffilestart
3009 $cflist conf -state normal
3010 $cflist delete 0.0 end
3012 $cflist insert end $first
3014 $cflist tag add highlight 1.0 "1.0 lineend"
3016 catch {unset cflist_top}
3018 $cflist conf -state disabled
3019 set difffilestart {}
3022 proc highlight_tag {f} {
3023 global highlight_paths
3025 foreach p $highlight_paths {
3026 if {[string match $p $f]} {
3033 proc highlight_filelist {} {
3034 global cmitmode cflist
3036 $cflist conf -state normal
3037 if {$cmitmode ne "tree"} {
3038 set end [lindex [split [$cflist index end] .] 0]
3039 for {set l 2} {$l < $end} {incr l} {
3040 set line [$cflist get $l.0 "$l.0 lineend"]
3041 if {[highlight_tag $line] ne {}} {
3042 $cflist tag add bold $l.0 "$l.0 lineend"
3048 $cflist conf -state disabled
3051 proc unhighlight_filelist {} {
3054 $cflist conf -state normal
3055 $cflist tag remove bold 1.0 end
3056 $cflist conf -state disabled
3059 proc add_flist {fl} {
3062 $cflist conf -state normal
3064 $cflist insert end "\n"
3065 $cflist insert end $f [highlight_tag $f]
3067 $cflist conf -state disabled
3070 proc sel_flist {w x y} {
3071 global ctext difffilestart cflist cflist_top cmitmode
3073 if {$cmitmode eq "tree"} return
3074 if {![info exists cflist_top]} return
3075 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3076 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3077 $cflist tag add highlight $l.0 "$l.0 lineend"
3082 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3086 proc pop_flist_menu {w X Y x y} {
3087 global ctext cflist cmitmode flist_menu flist_menu_file
3088 global treediffs diffids
3091 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3093 if {$cmitmode eq "tree"} {
3094 set e [linetoelt $l]
3095 if {[string index $e end] eq "/"} return
3097 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3099 set flist_menu_file $e
3100 set xdiffstate "normal"
3101 if {$cmitmode eq "tree"} {
3102 set xdiffstate "disabled"
3104 # Disable "External diff" item in tree mode
3105 $flist_menu entryconf 2 -state $xdiffstate
3106 tk_popup $flist_menu $X $Y
3109 proc find_ctext_fileinfo {line} {
3110 global ctext_file_names ctext_file_lines
3112 set ok [bsearch $ctext_file_lines $line]
3113 set tline [lindex $ctext_file_lines $ok]
3115 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3118 return [list [lindex $ctext_file_names $ok] $tline]
3122 proc pop_diff_menu {w X Y x y} {
3123 global ctext diff_menu flist_menu_file
3124 global diff_menu_txtpos diff_menu_line
3125 global diff_menu_filebase
3127 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3128 set diff_menu_line [lindex $diff_menu_txtpos 0]
3129 # don't pop up the menu on hunk-separator or file-separator lines
3130 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3134 set f [find_ctext_fileinfo $diff_menu_line]
3135 if {$f eq {}} return
3136 set flist_menu_file [lindex $f 0]
3137 set diff_menu_filebase [lindex $f 1]
3138 tk_popup $diff_menu $X $Y
3141 proc flist_hl {only} {
3142 global flist_menu_file findstring gdttype
3144 set x [shellquote $flist_menu_file]
3145 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3148 append findstring " " $x
3150 set gdttype [mc "touching paths:"]
3153 proc save_file_from_commit {filename output what} {
3156 if {[catch {exec git show $filename -- > $output} err]} {
3157 if {[string match "fatal: bad revision *" $err]} {
3160 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3166 proc external_diff_get_one_file {diffid filename diffdir} {
3167 global nullid nullid2 nullfile
3170 if {$diffid == $nullid} {
3171 set difffile [file join [file dirname $gitdir] $filename]
3172 if {[file exists $difffile]} {
3177 if {$diffid == $nullid2} {
3178 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3179 return [save_file_from_commit :$filename $difffile index]
3181 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3182 return [save_file_from_commit $diffid:$filename $difffile \
3186 proc external_diff {} {
3187 global gitktmpdir nullid nullid2
3188 global flist_menu_file
3191 global gitdir extdifftool
3193 if {[llength $diffids] == 1} {
3194 # no reference commit given
3195 set diffidto [lindex $diffids 0]
3196 if {$diffidto eq $nullid} {
3197 # diffing working copy with index
3198 set diffidfrom $nullid2
3199 } elseif {$diffidto eq $nullid2} {
3200 # diffing index with HEAD
3201 set diffidfrom "HEAD"
3203 # use first parent commit
3204 global parentlist selectedline
3205 set diffidfrom [lindex $parentlist $selectedline 0]
3208 set diffidfrom [lindex $diffids 0]
3209 set diffidto [lindex $diffids 1]
3212 # make sure that several diffs wont collide
3213 if {![info exists gitktmpdir]} {
3214 set gitktmpdir [file join [file dirname $gitdir] \
3215 [format ".gitk-tmp.%s" [pid]]]
3216 if {[catch {file mkdir $gitktmpdir} err]} {
3217 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3224 set diffdir [file join $gitktmpdir $diffnum]
3225 if {[catch {file mkdir $diffdir} err]} {
3226 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3230 # gather files to diff
3231 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3232 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3234 if {$difffromfile ne {} && $difftofile ne {}} {
3235 set cmd [concat | [shellsplit $extdifftool] \
3236 [list $difffromfile $difftofile]]
3237 if {[catch {set fl [open $cmd r]} err]} {
3238 file delete -force $diffdir
3239 error_popup "$extdifftool: [mc "command failed:"] $err"
3241 fconfigure $fl -blocking 0
3242 filerun $fl [list delete_at_eof $fl $diffdir]
3247 proc find_hunk_blamespec {base line} {
3250 # Find and parse the hunk header
3251 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3252 if {$s_lix eq {}} return
3254 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3255 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3256 s_line old_specs osz osz1 new_line nsz]} {
3260 # base lines for the parents
3261 set base_lines [list $new_line]
3262 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3263 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3264 old_spec old_line osz]} {
3267 lappend base_lines $old_line
3270 # Now scan the lines to determine offset within the hunk
3271 set max_parent [expr {[llength $base_lines]-2}]
3273 set s_lno [lindex [split $s_lix "."] 0]
3275 # Determine if the line is removed
3276 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3277 if {[string match {[-+ ]*} $chunk]} {
3278 set removed_idx [string first "-" $chunk]
3279 # Choose a parent index
3280 if {$removed_idx >= 0} {
3281 set parent $removed_idx
3283 set unchanged_idx [string first " " $chunk]
3284 if {$unchanged_idx >= 0} {
3285 set parent $unchanged_idx
3287 # blame the current commit
3291 # then count other lines that belong to it
3292 for {set i $line} {[incr i -1] > $s_lno} {} {
3293 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3294 # Determine if the line is removed
3295 set removed_idx [string first "-" $chunk]
3297 set code [string index $chunk $parent]
3298 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3302 if {$removed_idx < 0} {
3312 incr dline [lindex $base_lines $parent]
3313 return [list $parent $dline]
3316 proc external_blame_diff {} {
3317 global currentid cmitmode
3318 global diff_menu_txtpos diff_menu_line
3319 global diff_menu_filebase flist_menu_file
3321 if {$cmitmode eq "tree"} {
3323 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3325 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3327 set parent_idx [lindex $hinfo 0]
3328 set line [lindex $hinfo 1]
3335 external_blame $parent_idx $line
3338 # Find the SHA1 ID of the blob for file $fname in the index
3340 proc index_sha1 {fname} {
3341 set f [open [list | git ls-files -s $fname] r]
3342 while {[gets $f line] >= 0} {
3343 set info [lindex [split $line "\t"] 0]
3344 set stage [lindex $info 2]
3345 if {$stage eq "0" || $stage eq "2"} {
3347 return [lindex $info 1]
3354 # Turn an absolute path into one relative to the current directory
3355 proc make_relative {f} {
3356 set elts [file split $f]
3357 set here [file split [pwd]]
3362 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3369 set elts [concat $res [lrange $elts $ei end]]
3370 return [eval file join $elts]
3373 proc external_blame {parent_idx {line {}}} {
3374 global flist_menu_file gitdir
3375 global nullid nullid2
3376 global parentlist selectedline currentid
3378 if {$parent_idx > 0} {
3379 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3381 set base_commit $currentid
3384 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3385 error_popup [mc "No such commit"]
3389 set cmdline [list git gui blame]
3390 if {$line ne {} && $line > 1} {
3391 lappend cmdline "--line=$line"
3393 set f [file join [file dirname $gitdir] $flist_menu_file]
3394 # Unfortunately it seems git gui blame doesn't like
3395 # being given an absolute path...
3396 set f [make_relative $f]
3397 lappend cmdline $base_commit $f
3398 if {[catch {eval exec $cmdline &} err]} {
3399 error_popup "[mc "git gui blame: command failed:"] $err"
3403 proc show_line_source {} {
3404 global cmitmode currentid parents curview blamestuff blameinst
3405 global diff_menu_line diff_menu_filebase flist_menu_file
3406 global nullid nullid2 gitdir
3409 if {$cmitmode eq "tree"} {
3411 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3413 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3414 if {$h eq {}} return
3415 set pi [lindex $h 0]
3417 mark_ctext_line $diff_menu_line
3421 if {$currentid eq $nullid} {
3423 # must be a merge in progress...
3425 # get the last line from .git/MERGE_HEAD
3426 set f [open [file join $gitdir MERGE_HEAD] r]
3427 set id [lindex [split [read $f] "\n"] end-1]
3430 error_popup [mc "Couldn't read merge head: %s" $err]
3433 } elseif {$parents($curview,$currentid) eq $nullid2} {
3434 # need to do the blame from the index
3436 set from_index [index_sha1 $flist_menu_file]
3438 error_popup [mc "Error reading index: %s" $err]
3442 set id $parents($curview,$currentid)
3445 set id [lindex $parents($curview,$currentid) $pi]
3447 set line [lindex $h 1]
3450 if {$from_index ne {}} {
3451 lappend blameargs | git cat-file blob $from_index
3453 lappend blameargs | git blame -p -L$line,+1
3454 if {$from_index ne {}} {
3455 lappend blameargs --contents -
3457 lappend blameargs $id
3459 lappend blameargs -- [file join [file dirname $gitdir] $flist_menu_file]
3461 set f [open $blameargs r]
3463 error_popup [mc "Couldn't start git blame: %s" $err]
3466 nowbusy blaming [mc "Searching"]
3467 fconfigure $f -blocking 0
3468 set i [reg_instance $f]
3469 set blamestuff($i) {}
3471 filerun $f [list read_line_source $f $i]
3474 proc stopblaming {} {
3477 if {[info exists blameinst]} {
3478 stop_instance $blameinst
3484 proc read_line_source {fd inst} {
3485 global blamestuff curview commfd blameinst nullid nullid2
3487 while {[gets $fd line] >= 0} {
3488 lappend blamestuff($inst) $line
3496 fconfigure $fd -blocking 1
3497 if {[catch {close $fd} err]} {
3498 error_popup [mc "Error running git blame: %s" $err]
3503 set line [split [lindex $blamestuff($inst) 0] " "]
3504 set id [lindex $line 0]
3505 set lnum [lindex $line 1]
3506 if {[string length $id] == 40 && [string is xdigit $id] &&
3507 [string is digit -strict $lnum]} {
3508 # look for "filename" line
3509 foreach l $blamestuff($inst) {
3510 if {[string match "filename *" $l]} {
3511 set fname [string range $l 9 end]
3517 # all looks good, select it
3518 if {$id eq $nullid} {
3519 # blame uses all-zeroes to mean not committed,
3520 # which would mean a change in the index
3523 if {[commitinview $id $curview]} {
3524 selectline [rowofcommit $id] 1 [list $fname $lnum]
3526 error_popup [mc "That line comes from commit %s, \
3527 which is not in this view" [shortids $id]]
3530 puts "oops couldn't parse git blame output"
3535 # delete $dir when we see eof on $f (presumably because the child has exited)
3536 proc delete_at_eof {f dir} {
3537 while {[gets $f line] >= 0} {}
3539 if {[catch {close $f} err]} {
3540 error_popup "[mc "External diff viewer failed:"] $err"
3542 file delete -force $dir
3548 # Functions for adding and removing shell-type quoting
3550 proc shellquote {str} {
3551 if {![string match "*\['\"\\ \t]*" $str]} {
3554 if {![string match "*\['\"\\]*" $str]} {
3557 if {![string match "*'*" $str]} {
3560 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3563 proc shellarglist {l} {
3569 append str [shellquote $a]
3574 proc shelldequote {str} {
3579 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3580 append ret [string range $str $used end]
3581 set used [string length $str]
3584 set first [lindex $first 0]
3585 set ch [string index $str $first]
3586 if {$first > $used} {
3587 append ret [string range $str $used [expr {$first - 1}]]
3590 if {$ch eq " " || $ch eq "\t"} break
3593 set first [string first "'" $str $used]
3595 error "unmatched single-quote"
3597 append ret [string range $str $used [expr {$first - 1}]]
3602 if {$used >= [string length $str]} {
3603 error "trailing backslash"
3605 append ret [string index $str $used]
3610 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3611 error "unmatched double-quote"
3613 set first [lindex $first 0]
3614 set ch [string index $str $first]
3615 if {$first > $used} {
3616 append ret [string range $str $used [expr {$first - 1}]]
3619 if {$ch eq "\""} break
3621 append ret [string index $str $used]
3625 return [list $used $ret]
3628 proc shellsplit {str} {
3631 set str [string trimleft $str]
3632 if {$str eq {}} break
3633 set dq [shelldequote $str]
3634 set n [lindex $dq 0]
3635 set word [lindex $dq 1]
3636 set str [string range $str $n end]
3642 # Code to implement multiple views
3644 proc newview {ishighlight} {
3645 global nextviewnum newviewname newishighlight
3646 global revtreeargs viewargscmd newviewopts curview
3648 set newishighlight $ishighlight
3650 if {[winfo exists $top]} {
3654 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3655 set newviewopts($nextviewnum,perm) 0
3656 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3657 decode_view_opts $nextviewnum $revtreeargs
3658 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3661 set known_view_options {
3662 {perm b . {} {mc "Remember this view"}}
3663 {args t50= + {} {mc "Commits to include (arguments to git log):"}}
3664 {all b * "--all" {mc "Use all refs"}}
3665 {dorder b . {"--date-order" "-d"} {mc "Strictly sort by date"}}
3666 {lright b . "--left-right" {mc "Mark branch sides"}}
3667 {since t15 + {"--since=*" "--after=*"} {mc "Since date:"}}
3668 {until t15 . {"--until=*" "--before=*"} {mc "Until date:"}}
3669 {limit t10 + "--max-count=*" {mc "Max count:"}}
3670 {skip t10 . "--skip=*" {mc "Skip:"}}
3671 {first b . "--first-parent" {mc "Limit to first parent"}}
3672 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3675 proc encode_view_opts {n} {
3676 global known_view_options newviewopts
3679 foreach opt $known_view_options {
3680 set patterns [lindex $opt 3]
3681 if {$patterns eq {}} continue
3682 set pattern [lindex $patterns 0]
3684 set val $newviewopts($n,[lindex $opt 0])
3686 if {[lindex $opt 1] eq "b"} {
3688 lappend rargs $pattern
3691 set val [string trim $val]
3693 set pfix [string range $pattern 0 end-1]
3694 lappend rargs $pfix$val
3698 return [concat $rargs [shellsplit $newviewopts($n,args)]]
3701 proc decode_view_opts {n view_args} {
3702 global known_view_options newviewopts
3704 foreach opt $known_view_options {
3705 if {[lindex $opt 1] eq "b"} {
3710 set newviewopts($n,[lindex $opt 0]) $val
3713 foreach arg $view_args {
3714 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
3715 && ![info exists found(limit)]} {
3716 set newviewopts($n,limit) $cnt
3721 foreach opt $known_view_options {
3722 set id [lindex $opt 0]
3723 if {[info exists found($id)]} continue
3724 foreach pattern [lindex $opt 3] {
3725 if {![string match $pattern $arg]} continue
3726 if {[lindex $opt 1] ne "b"} {
3727 set size [string length $pattern]
3728 set val [string range $arg [expr {$size-1}] end]
3732 set newviewopts($n,$id) $val
3736 if {[info exists val]} break
3738 if {[info exists val]} continue
3741 set newviewopts($n,args) [shellarglist $oargs]
3744 proc edit_or_newview {} {
3756 global viewname viewperm newviewname newviewopts
3757 global viewargs viewargscmd
3759 set top .gitkvedit-$curview
3760 if {[winfo exists $top]} {
3764 set newviewname($curview) $viewname($curview)
3765 set newviewopts($curview,perm) $viewperm($curview)
3766 set newviewopts($curview,cmd) $viewargscmd($curview)
3767 decode_view_opts $curview $viewargs($curview)
3768 vieweditor $top $curview "Gitk: edit view $viewname($curview)"
3771 proc vieweditor {top n title} {
3772 global newviewname newviewopts viewfiles bgcolor
3773 global known_view_options
3776 wm title $top $title
3777 make_transient $top .
3781 label $top.nl -text [mc "Name"]
3782 entry $top.name -width 20 -textvariable newviewname($n)
3783 pack $top.nfr -in $top -fill x -pady 5 -padx 3
3784 pack $top.nl -in $top.nfr -side left -padx {0 30}
3785 pack $top.name -in $top.nfr -side left
3791 foreach opt $known_view_options {
3792 set id [lindex $opt 0]
3793 set type [lindex $opt 1]
3794 set flags [lindex $opt 2]
3795 set title [eval [lindex $opt 4]]
3798 if {$flags eq "+" || $flags eq "*"} {
3799 set cframe $top.fr$cnt
3802 pack $cframe -in $top -fill x -pady 3 -padx 3
3803 set cexpand [expr {$flags eq "*"}]
3809 checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
3810 pack $cframe.c_$id -in $cframe -side left \
3811 -padx [list $lxpad 0] -expand $cexpand -anchor w
3812 } elseif {[regexp {^t(\d+)$} $type type sz]} {
3813 message $cframe.l_$id -aspect 1500 -text $title
3814 entry $cframe.e_$id -width $sz -background $bgcolor \
3815 -textvariable newviewopts($n,$id)
3816 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
3817 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
3818 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
3819 message $cframe.l_$id -aspect 1500 -text $title
3820 entry $cframe.e_$id -width $sz -background $bgcolor \
3821 -textvariable newviewopts($n,$id)
3822 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
3823 pack $cframe.e_$id -in $cframe -side top -fill x
3828 message $top.l -aspect 1500 \
3829 -text [mc "Enter files and directories to include, one per line:"]
3830 pack $top.l -in $top -side top -pady [list 7 0] -anchor w -padx 3
3831 text $top.t -width 40 -height 5 -background $bgcolor -font uifont
3832 if {[info exists viewfiles($n)]} {
3833 foreach f $viewfiles($n) {
3834 $top.t insert end $f
3835 $top.t insert end "\n"
3837 $top.t delete {end - 1c} end
3838 $top.t mark set insert 0.0
3840 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
3842 button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
3843 button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
3844 button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
3845 bind $top <Control-Return> [list newviewok $top $n]
3846 bind $top <F5> [list newviewok $top $n 1]
3847 bind $top <Escape> [list destroy $top]
3848 grid $top.buts.ok $top.buts.apply $top.buts.can
3849 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3850 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3851 grid columnconfigure $top.buts 2 -weight 1 -uniform a
3852 pack $top.buts -in $top -side top -fill x
3856 proc doviewmenu {m first cmd op argv} {
3857 set nmenu [$m index end]
3858 for {set i $first} {$i <= $nmenu} {incr i} {
3859 if {[$m entrycget $i -command] eq $cmd} {
3860 eval $m $op $i $argv
3866 proc allviewmenus {n op args} {
3869 doviewmenu .bar.view 5 [list showview $n] $op $args
3870 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
3873 proc newviewok {top n {apply 0}} {
3874 global nextviewnum newviewperm newviewname newishighlight
3875 global viewname viewfiles viewperm selectedview curview
3876 global viewargs viewargscmd newviewopts viewhlmenu
3879 set newargs [encode_view_opts $n]
3881 error_popup "[mc "Error in commit selection arguments:"] $err" $top
3885 foreach f [split [$top.t get 0.0 end] "\n"] {
3886 set ft [string trim $f]
3891 if {![info exists viewfiles($n)]} {
3892 # creating a new view
3894 set viewname($n) $newviewname($n)
3895 set viewperm($n) $newviewopts($n,perm)
3896 set viewfiles($n) $files
3897 set viewargs($n) $newargs
3898 set viewargscmd($n) $newviewopts($n,cmd)
3900 if {!$newishighlight} {
3903 run addvhighlight $n
3906 # editing an existing view
3907 set viewperm($n) $newviewopts($n,perm)
3908 if {$newviewname($n) ne $viewname($n)} {
3909 set viewname($n) $newviewname($n)
3910 doviewmenu .bar.view 5 [list showview $n] \
3911 entryconf [list -label $viewname($n)]
3912 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
3913 # entryconf [list -label $viewname($n) -value $viewname($n)]
3915 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
3916 $newviewopts($n,cmd) ne $viewargscmd($n)} {
3917 set viewfiles($n) $files
3918 set viewargs($n) $newargs
3919 set viewargscmd($n) $newviewopts($n,cmd)
3920 if {$curview == $n} {
3926 catch {destroy $top}
3930 global curview viewperm hlview selectedhlview
3932 if {$curview == 0} return
3933 if {[info exists hlview] && $hlview == $curview} {
3934 set selectedhlview [mc "None"]
3937 allviewmenus $curview delete
3938 set viewperm($curview) 0
3942 proc addviewmenu {n} {
3943 global viewname viewhlmenu
3945 .bar.view add radiobutton -label $viewname($n) \
3946 -command [list showview $n] -variable selectedview -value $n
3947 #$viewhlmenu add radiobutton -label $viewname($n) \
3948 # -command [list addvhighlight $n] -variable selectedhlview
3952 global curview cached_commitrow ordertok
3953 global displayorder parentlist rowidlist rowisopt rowfinal
3954 global colormap rowtextx nextcolor canvxmax
3955 global numcommits viewcomplete
3956 global selectedline currentid canv canvy0
3958 global pending_select mainheadid
3961 global hlview selectedhlview commitinterest
3963 if {$n == $curview} return
3965 set ymax [lindex [$canv cget -scrollregion] 3]
3966 set span [$canv yview]
3967 set ytop [expr {[lindex $span 0] * $ymax}]
3968 set ybot [expr {[lindex $span 1] * $ymax}]
3969 set yscreen [expr {($ybot - $ytop) / 2}]
3970 if {$selectedline ne {}} {
3971 set selid $currentid
3972 set y [yc $selectedline]
3973 if {$ytop < $y && $y < $ybot} {
3974 set yscreen [expr {$y - $ytop}]
3976 } elseif {[info exists pending_select]} {
3977 set selid $pending_select
3978 unset pending_select
3982 catch {unset treediffs}
3984 if {[info exists hlview] && $hlview == $n} {
3986 set selectedhlview [mc "None"]
3988 catch {unset commitinterest}
3989 catch {unset cached_commitrow}
3990 catch {unset ordertok}
3994 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
3995 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
3998 if {![info exists viewcomplete($n)]} {
4008 set numcommits $commitidx($n)
4010 catch {unset colormap}
4011 catch {unset rowtextx}
4013 set canvxmax [$canv cget -width]
4019 if {$selid ne {} && [commitinview $selid $n]} {
4020 set row [rowofcommit $selid]
4021 # try to get the selected row in the same position on the screen
4022 set ymax [lindex [$canv cget -scrollregion] 3]
4023 set ytop [expr {[yc $row] - $yscreen}]
4027 set yf [expr {$ytop * 1.0 / $ymax}]
4029 allcanvs yview moveto $yf
4033 } elseif {!$viewcomplete($n)} {
4034 reset_pending_select $selid
4036 reset_pending_select {}
4038 if {[commitinview $pending_select $curview]} {
4039 selectline [rowofcommit $pending_select] 1
4041 set row [first_real_row]
4042 if {$row < $numcommits} {
4047 if {!$viewcomplete($n)} {
4048 if {$numcommits == 0} {
4049 show_status [mc "Reading commits..."]
4051 } elseif {$numcommits == 0} {
4052 show_status [mc "No commits selected"]
4056 # Stuff relating to the highlighting facility
4058 proc ishighlighted {id} {
4059 global vhighlights fhighlights nhighlights rhighlights
4061 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4062 return $nhighlights($id)
4064 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4065 return $vhighlights($id)
4067 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4068 return $fhighlights($id)
4070 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4071 return $rhighlights($id)
4076 proc bolden {id font} {
4077 global canv linehtag currentid boldids need_redisplay
4079 # need_redisplay = 1 means the display is stale and about to be redrawn
4080 if {$need_redisplay} return
4082 $canv itemconf $linehtag($id) -font $font
4083 if {[info exists currentid] && $id eq $currentid} {
4085 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4086 -outline {{}} -tags secsel \
4087 -fill [$canv cget -selectbackground]]
4092 proc bolden_name {id font} {
4093 global canv2 linentag currentid boldnameids need_redisplay
4095 if {$need_redisplay} return
4096 lappend boldnameids $id
4097 $canv2 itemconf $linentag($id) -font $font
4098 if {[info exists currentid] && $id eq $currentid} {
4099 $canv2 delete secsel
4100 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4101 -outline {{}} -tags secsel \
4102 -fill [$canv2 cget -selectbackground]]
4111 foreach id $boldids {
4112 if {![ishighlighted $id]} {
4115 lappend stillbold $id
4118 set boldids $stillbold
4121 proc addvhighlight {n} {
4122 global hlview viewcomplete curview vhl_done commitidx
4124 if {[info exists hlview]} {
4128 if {$n != $curview && ![info exists viewcomplete($n)]} {
4131 set vhl_done $commitidx($hlview)
4132 if {$vhl_done > 0} {
4137 proc delvhighlight {} {
4138 global hlview vhighlights
4140 if {![info exists hlview]} return
4142 catch {unset vhighlights}
4146 proc vhighlightmore {} {
4147 global hlview vhl_done commitidx vhighlights curview
4149 set max $commitidx($hlview)
4150 set vr [visiblerows]
4151 set r0 [lindex $vr 0]
4152 set r1 [lindex $vr 1]
4153 for {set i $vhl_done} {$i < $max} {incr i} {
4154 set id [commitonrow $i $hlview]
4155 if {[commitinview $id $curview]} {
4156 set row [rowofcommit $id]
4157 if {$r0 <= $row && $row <= $r1} {
4158 if {![highlighted $row]} {
4159 bolden $id mainfontbold
4161 set vhighlights($id) 1
4169 proc askvhighlight {row id} {
4170 global hlview vhighlights iddrawn
4172 if {[commitinview $id $hlview]} {
4173 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4174 bolden $id mainfontbold
4176 set vhighlights($id) 1
4178 set vhighlights($id) 0
4182 proc hfiles_change {} {
4183 global highlight_files filehighlight fhighlights fh_serial
4184 global highlight_paths
4186 if {[info exists filehighlight]} {
4187 # delete previous highlights
4188 catch {close $filehighlight}
4190 catch {unset fhighlights}
4192 unhighlight_filelist
4194 set highlight_paths {}
4195 after cancel do_file_hl $fh_serial
4197 if {$highlight_files ne {}} {
4198 after 300 do_file_hl $fh_serial
4202 proc gdttype_change {name ix op} {
4203 global gdttype highlight_files findstring findpattern
4206 if {$findstring ne {}} {
4207 if {$gdttype eq [mc "containing:"]} {
4208 if {$highlight_files ne {}} {
4209 set highlight_files {}
4214 if {$findpattern ne {}} {
4218 set highlight_files $findstring
4223 # enable/disable findtype/findloc menus too
4226 proc find_change {name ix op} {
4227 global gdttype findstring highlight_files
4230 if {$gdttype eq [mc "containing:"]} {
4233 if {$highlight_files ne $findstring} {
4234 set highlight_files $findstring
4241 proc findcom_change args {
4242 global nhighlights boldnameids
4243 global findpattern findtype findstring gdttype
4246 # delete previous highlights, if any
4247 foreach id $boldnameids {
4248 bolden_name $id mainfont
4251 catch {unset nhighlights}
4254 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4256 } elseif {$findtype eq [mc "Regexp"]} {
4257 set findpattern $findstring
4259 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4261 set findpattern "*$e*"
4265 proc makepatterns {l} {
4268 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4269 if {[string index $ee end] eq "/"} {
4279 proc do_file_hl {serial} {
4280 global highlight_files filehighlight highlight_paths gdttype fhl_list
4282 if {$gdttype eq [mc "touching paths:"]} {
4283 if {[catch {set paths [shellsplit $highlight_files]}]} return
4284 set highlight_paths [makepatterns $paths]
4286 set gdtargs [concat -- $paths]
4287 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4288 set gdtargs [list "-S$highlight_files"]
4290 # must be "containing:", i.e. we're searching commit info
4293 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4294 set filehighlight [open $cmd r+]
4295 fconfigure $filehighlight -blocking 0
4296 filerun $filehighlight readfhighlight
4302 proc flushhighlights {} {
4303 global filehighlight fhl_list
4305 if {[info exists filehighlight]} {
4307 puts $filehighlight ""
4308 flush $filehighlight
4312 proc askfilehighlight {row id} {
4313 global filehighlight fhighlights fhl_list
4315 lappend fhl_list $id
4316 set fhighlights($id) -1
4317 puts $filehighlight $id
4320 proc readfhighlight {} {
4321 global filehighlight fhighlights curview iddrawn
4322 global fhl_list find_dirn
4324 if {![info exists filehighlight]} {
4328 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4329 set line [string trim $line]
4330 set i [lsearch -exact $fhl_list $line]
4331 if {$i < 0} continue
4332 for {set j 0} {$j < $i} {incr j} {
4333 set id [lindex $fhl_list $j]
4334 set fhighlights($id) 0
4336 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4337 if {$line eq {}} continue
4338 if {![commitinview $line $curview]} continue
4339 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4340 bolden $line mainfontbold
4342 set fhighlights($line) 1
4344 if {[eof $filehighlight]} {
4346 puts "oops, git diff-tree died"
4347 catch {close $filehighlight}
4351 if {[info exists find_dirn]} {
4357 proc doesmatch {f} {
4358 global findtype findpattern
4360 if {$findtype eq [mc "Regexp"]} {
4361 return [regexp $findpattern $f]
4362 } elseif {$findtype eq [mc "IgnCase"]} {
4363 return [string match -nocase $findpattern $f]
4365 return [string match $findpattern $f]
4369 proc askfindhighlight {row id} {
4370 global nhighlights commitinfo iddrawn
4372 global markingmatches
4374 if {![info exists commitinfo($id)]} {
4377 set info $commitinfo($id)
4379 set fldtypes [list [mc Headline] [mc Author] [mc Date] [mc Committer] [mc CDate] [mc Comments]]
4380 foreach f $info ty $fldtypes {
4381 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4383 if {$ty eq [mc "Author"]} {
4390 if {$isbold && [info exists iddrawn($id)]} {
4391 if {![ishighlighted $id]} {
4392 bolden $id mainfontbold
4394 bolden_name $id mainfontbold
4397 if {$markingmatches} {
4398 markrowmatches $row $id
4401 set nhighlights($id) $isbold
4404 proc markrowmatches {row id} {
4405 global canv canv2 linehtag linentag commitinfo findloc
4407 set headline [lindex $commitinfo($id) 0]
4408 set author [lindex $commitinfo($id) 1]
4409 $canv delete match$row
4410 $canv2 delete match$row
4411 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4412 set m [findmatches $headline]
4414 markmatches $canv $row $headline $linehtag($id) $m \
4415 [$canv itemcget $linehtag($id) -font] $row
4418 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4419 set m [findmatches $author]
4421 markmatches $canv2 $row $author $linentag($id) $m \
4422 [$canv2 itemcget $linentag($id) -font] $row
4427 proc vrel_change {name ix op} {
4428 global highlight_related
4431 if {$highlight_related ne [mc "None"]} {
4436 # prepare for testing whether commits are descendents or ancestors of a
4437 proc rhighlight_sel {a} {
4438 global descendent desc_todo ancestor anc_todo
4439 global highlight_related
4441 catch {unset descendent}
4442 set desc_todo [list $a]
4443 catch {unset ancestor}
4444 set anc_todo [list $a]
4445 if {$highlight_related ne [mc "None"]} {
4451 proc rhighlight_none {} {
4454 catch {unset rhighlights}
4458 proc is_descendent {a} {
4459 global curview children descendent desc_todo
4462 set la [rowofcommit $a]
4466 for {set i 0} {$i < [llength $todo]} {incr i} {
4467 set do [lindex $todo $i]
4468 if {[rowofcommit $do] < $la} {
4469 lappend leftover $do
4472 foreach nk $children($v,$do) {
4473 if {![info exists descendent($nk)]} {
4474 set descendent($nk) 1
4482 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4486 set descendent($a) 0
4487 set desc_todo $leftover
4490 proc is_ancestor {a} {
4491 global curview parents ancestor anc_todo
4494 set la [rowofcommit $a]
4498 for {set i 0} {$i < [llength $todo]} {incr i} {
4499 set do [lindex $todo $i]
4500 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4501 lappend leftover $do
4504 foreach np $parents($v,$do) {
4505 if {![info exists ancestor($np)]} {
4514 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4519 set anc_todo $leftover
4522 proc askrelhighlight {row id} {
4523 global descendent highlight_related iddrawn rhighlights
4524 global selectedline ancestor
4526 if {$selectedline eq {}} return
4528 if {$highlight_related eq [mc "Descendant"] ||
4529 $highlight_related eq [mc "Not descendant"]} {
4530 if {![info exists descendent($id)]} {
4533 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4536 } elseif {$highlight_related eq [mc "Ancestor"] ||
4537 $highlight_related eq [mc "Not ancestor"]} {
4538 if {![info exists ancestor($id)]} {
4541 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4545 if {[info exists iddrawn($id)]} {
4546 if {$isbold && ![ishighlighted $id]} {
4547 bolden $id mainfontbold
4550 set rhighlights($id) $isbold
4553 # Graph layout functions
4555 proc shortids {ids} {
4558 if {[llength $id] > 1} {
4559 lappend res [shortids $id]
4560 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4561 lappend res [string range $id 0 7]
4572 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4573 if {($n & $mask) != 0} {
4574 set ret [concat $ret $o]
4576 set o [concat $o $o]
4581 proc ordertoken {id} {
4582 global ordertok curview varcid varcstart varctok curview parents children
4583 global nullid nullid2
4585 if {[info exists ordertok($id)]} {
4586 return $ordertok($id)
4591 if {[info exists varcid($curview,$id)]} {
4592 set a $varcid($curview,$id)
4593 set p [lindex $varcstart($curview) $a]
4595 set p [lindex $children($curview,$id) 0]
4597 if {[info exists ordertok($p)]} {
4598 set tok $ordertok($p)
4601 set id [first_real_child $curview,$p]
4604 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4607 if {[llength $parents($curview,$id)] == 1} {
4608 lappend todo [list $p {}]
4610 set j [lsearch -exact $parents($curview,$id) $p]
4612 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4614 lappend todo [list $p [strrep $j]]
4617 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4618 set p [lindex $todo $i 0]
4619 append tok [lindex $todo $i 1]
4620 set ordertok($p) $tok
4622 set ordertok($origid) $tok
4626 # Work out where id should go in idlist so that order-token
4627 # values increase from left to right
4628 proc idcol {idlist id {i 0}} {
4629 set t [ordertoken $id]
4633 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
4634 if {$i > [llength $idlist]} {
4635 set i [llength $idlist]
4637 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
4640 if {$t > [ordertoken [lindex $idlist $i]]} {
4641 while {[incr i] < [llength $idlist] &&
4642 $t >= [ordertoken [lindex $idlist $i]]} {}
4648 proc initlayout {} {
4649 global rowidlist rowisopt rowfinal displayorder parentlist
4650 global numcommits canvxmax canv
4652 global colormap rowtextx
4661 set canvxmax [$canv cget -width]
4662 catch {unset colormap}
4663 catch {unset rowtextx}
4667 proc setcanvscroll {} {
4668 global canv canv2 canv3 numcommits linespc canvxmax canvy0
4669 global lastscrollset lastscrollrows
4671 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
4672 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
4673 $canv2 conf -scrollregion [list 0 0 0 $ymax]
4674 $canv3 conf -scrollregion [list 0 0 0 $ymax]
4675 set lastscrollset [clock clicks -milliseconds]
4676 set lastscrollrows $numcommits
4679 proc visiblerows {} {
4680 global canv numcommits linespc
4682 set ymax [lindex [$canv cget -scrollregion] 3]
4683 if {$ymax eq {} || $ymax == 0} return
4685 set y0 [expr {int([lindex $f 0] * $ymax)}]
4686 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
4690 set y1 [expr {int([lindex $f 1] * $ymax)}]
4691 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
4692 if {$r1 >= $numcommits} {
4693 set r1 [expr {$numcommits - 1}]
4695 return [list $r0 $r1]
4698 proc layoutmore {} {
4699 global commitidx viewcomplete curview
4700 global numcommits pending_select curview
4701 global lastscrollset lastscrollrows
4703 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
4704 [clock clicks -milliseconds] - $lastscrollset > 500} {
4707 if {[info exists pending_select] &&
4708 [commitinview $pending_select $curview]} {
4710 selectline [rowofcommit $pending_select] 1
4715 # With path limiting, we mightn't get the actual HEAD commit,
4716 # so ask git rev-list what is the first ancestor of HEAD that
4717 # touches a file in the path limit.
4718 proc get_viewmainhead {view} {
4719 global viewmainheadid vfilelimit viewinstances mainheadid
4722 set rfd [open [concat | git rev-list -1 $mainheadid \
4723 -- $vfilelimit($view)] r]
4724 set j [reg_instance $rfd]
4725 lappend viewinstances($view) $j
4726 fconfigure $rfd -blocking 0
4727 filerun $rfd [list getviewhead $rfd $j $view]
4728 set viewmainheadid($curview) {}
4732 # git rev-list should give us just 1 line to use as viewmainheadid($view)
4733 proc getviewhead {fd inst view} {
4734 global viewmainheadid commfd curview viewinstances showlocalchanges
4737 if {[gets $fd line] < 0} {
4741 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
4744 set viewmainheadid($view) $id
4747 set i [lsearch -exact $viewinstances($view) $inst]
4749 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
4751 if {$showlocalchanges && $id ne {} && $view == $curview} {
4757 proc doshowlocalchanges {} {
4758 global curview viewmainheadid
4760 if {$viewmainheadid($curview) eq {}} return
4761 if {[commitinview $viewmainheadid($curview) $curview]} {
4764 interestedin $viewmainheadid($curview) dodiffindex
4768 proc dohidelocalchanges {} {
4769 global nullid nullid2 lserial curview
4771 if {[commitinview $nullid $curview]} {
4772 removefakerow $nullid
4774 if {[commitinview $nullid2 $curview]} {
4775 removefakerow $nullid2
4780 # spawn off a process to do git diff-index --cached HEAD
4781 proc dodiffindex {} {
4782 global lserial showlocalchanges vfilelimit curview
4785 if {!$showlocalchanges || !$isworktree} return
4787 set cmd "|git diff-index --cached HEAD"
4788 if {$vfilelimit($curview) ne {}} {
4789 set cmd [concat $cmd -- $vfilelimit($curview)]
4791 set fd [open $cmd r]
4792 fconfigure $fd -blocking 0
4793 set i [reg_instance $fd]
4794 filerun $fd [list readdiffindex $fd $lserial $i]
4797 proc readdiffindex {fd serial inst} {
4798 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
4802 if {[gets $fd line] < 0} {
4808 # we only need to see one line and we don't really care what it says...
4811 if {$serial != $lserial} {
4815 # now see if there are any local changes not checked in to the index
4816 set cmd "|git diff-files"
4817 if {$vfilelimit($curview) ne {}} {
4818 set cmd [concat $cmd -- $vfilelimit($curview)]
4820 set fd [open $cmd r]
4821 fconfigure $fd -blocking 0
4822 set i [reg_instance $fd]
4823 filerun $fd [list readdifffiles $fd $serial $i]
4825 if {$isdiff && ![commitinview $nullid2 $curview]} {
4826 # add the line for the changes in the index to the graph
4827 set hl [mc "Local changes checked in to index but not committed"]
4828 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
4829 set commitdata($nullid2) "\n $hl\n"
4830 if {[commitinview $nullid $curview]} {
4831 removefakerow $nullid
4833 insertfakerow $nullid2 $viewmainheadid($curview)
4834 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
4835 if {[commitinview $nullid $curview]} {
4836 removefakerow $nullid
4838 removefakerow $nullid2
4843 proc readdifffiles {fd serial inst} {
4844 global viewmainheadid nullid nullid2 curview
4845 global commitinfo commitdata lserial
4848 if {[gets $fd line] < 0} {
4854 # we only need to see one line and we don't really care what it says...
4857 if {$serial != $lserial} {
4861 if {$isdiff && ![commitinview $nullid $curview]} {
4862 # add the line for the local diff to the graph
4863 set hl [mc "Local uncommitted changes, not checked in to index"]
4864 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
4865 set commitdata($nullid) "\n $hl\n"
4866 if {[commitinview $nullid2 $curview]} {
4869 set p $viewmainheadid($curview)
4871 insertfakerow $nullid $p
4872 } elseif {!$isdiff && [commitinview $nullid $curview]} {
4873 removefakerow $nullid
4878 proc nextuse {id row} {
4879 global curview children
4881 if {[info exists children($curview,$id)]} {
4882 foreach kid $children($curview,$id) {
4883 if {![commitinview $kid $curview]} {
4886 if {[rowofcommit $kid] > $row} {
4887 return [rowofcommit $kid]
4891 if {[commitinview $id $curview]} {
4892 return [rowofcommit $id]
4897 proc prevuse {id row} {
4898 global curview children
4901 if {[info exists children($curview,$id)]} {
4902 foreach kid $children($curview,$id) {
4903 if {![commitinview $kid $curview]} break
4904 if {[rowofcommit $kid] < $row} {
4905 set ret [rowofcommit $kid]
4912 proc make_idlist {row} {
4913 global displayorder parentlist uparrowlen downarrowlen mingaplen
4914 global commitidx curview children
4916 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
4920 set ra [expr {$row - $downarrowlen}]
4924 set rb [expr {$row + $uparrowlen}]
4925 if {$rb > $commitidx($curview)} {
4926 set rb $commitidx($curview)
4928 make_disporder $r [expr {$rb + 1}]
4930 for {} {$r < $ra} {incr r} {
4931 set nextid [lindex $displayorder [expr {$r + 1}]]
4932 foreach p [lindex $parentlist $r] {
4933 if {$p eq $nextid} continue
4934 set rn [nextuse $p $r]
4936 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
4937 lappend ids [list [ordertoken $p] $p]
4941 for {} {$r < $row} {incr r} {
4942 set nextid [lindex $displayorder [expr {$r + 1}]]
4943 foreach p [lindex $parentlist $r] {
4944 if {$p eq $nextid} continue
4945 set rn [nextuse $p $r]
4946 if {$rn < 0 || $rn >= $row} {
4947 lappend ids [list [ordertoken $p] $p]
4951 set id [lindex $displayorder $row]
4952 lappend ids [list [ordertoken $id] $id]
4954 foreach p [lindex $parentlist $r] {
4955 set firstkid [lindex $children($curview,$p) 0]
4956 if {[rowofcommit $firstkid] < $row} {
4957 lappend ids [list [ordertoken $p] $p]
4961 set id [lindex $displayorder $r]
4963 set firstkid [lindex $children($curview,$id) 0]
4964 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
4965 lappend ids [list [ordertoken $id] $id]
4970 foreach idx [lsort -unique $ids] {
4971 lappend idlist [lindex $idx 1]
4976 proc rowsequal {a b} {
4977 while {[set i [lsearch -exact $a {}]] >= 0} {
4978 set a [lreplace $a $i $i]
4980 while {[set i [lsearch -exact $b {}]] >= 0} {
4981 set b [lreplace $b $i $i]
4983 return [expr {$a eq $b}]
4986 proc makeupline {id row rend col} {
4987 global rowidlist uparrowlen downarrowlen mingaplen
4989 for {set r $rend} {1} {set r $rstart} {
4990 set rstart [prevuse $id $r]
4991 if {$rstart < 0} return
4992 if {$rstart < $row} break
4994 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
4995 set rstart [expr {$rend - $uparrowlen - 1}]
4997 for {set r $rstart} {[incr r] <= $row} {} {
4998 set idlist [lindex $rowidlist $r]
4999 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5000 set col [idcol $idlist $id $col]
5001 lset rowidlist $r [linsert $idlist $col $id]
5007 proc layoutrows {row endrow} {
5008 global rowidlist rowisopt rowfinal displayorder
5009 global uparrowlen downarrowlen maxwidth mingaplen
5010 global children parentlist
5011 global commitidx viewcomplete curview
5013 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5016 set rm1 [expr {$row - 1}]
5017 foreach id [lindex $rowidlist $rm1] {
5022 set final [lindex $rowfinal $rm1]
5024 for {} {$row < $endrow} {incr row} {
5025 set rm1 [expr {$row - 1}]
5026 if {$rm1 < 0 || $idlist eq {}} {
5027 set idlist [make_idlist $row]
5030 set id [lindex $displayorder $rm1]
5031 set col [lsearch -exact $idlist $id]
5032 set idlist [lreplace $idlist $col $col]
5033 foreach p [lindex $parentlist $rm1] {
5034 if {[lsearch -exact $idlist $p] < 0} {
5035 set col [idcol $idlist $p $col]
5036 set idlist [linsert $idlist $col $p]
5037 # if not the first child, we have to insert a line going up
5038 if {$id ne [lindex $children($curview,$p) 0]} {
5039 makeupline $p $rm1 $row $col
5043 set id [lindex $displayorder $row]
5044 if {$row > $downarrowlen} {
5045 set termrow [expr {$row - $downarrowlen - 1}]
5046 foreach p [lindex $parentlist $termrow] {
5047 set i [lsearch -exact $idlist $p]
5048 if {$i < 0} continue
5049 set nr [nextuse $p $termrow]
5050 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5051 set idlist [lreplace $idlist $i $i]
5055 set col [lsearch -exact $idlist $id]
5057 set col [idcol $idlist $id]
5058 set idlist [linsert $idlist $col $id]
5059 if {$children($curview,$id) ne {}} {
5060 makeupline $id $rm1 $row $col
5063 set r [expr {$row + $uparrowlen - 1}]
5064 if {$r < $commitidx($curview)} {
5066 foreach p [lindex $parentlist $r] {
5067 if {[lsearch -exact $idlist $p] >= 0} continue
5068 set fk [lindex $children($curview,$p) 0]
5069 if {[rowofcommit $fk] < $row} {
5070 set x [idcol $idlist $p $x]
5071 set idlist [linsert $idlist $x $p]
5074 if {[incr r] < $commitidx($curview)} {
5075 set p [lindex $displayorder $r]
5076 if {[lsearch -exact $idlist $p] < 0} {
5077 set fk [lindex $children($curview,$p) 0]
5078 if {$fk ne {} && [rowofcommit $fk] < $row} {
5079 set x [idcol $idlist $p $x]
5080 set idlist [linsert $idlist $x $p]
5086 if {$final && !$viewcomplete($curview) &&
5087 $row + $uparrowlen + $mingaplen + $downarrowlen
5088 >= $commitidx($curview)} {
5091 set l [llength $rowidlist]
5093 lappend rowidlist $idlist
5095 lappend rowfinal $final
5096 } elseif {$row < $l} {
5097 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5098 lset rowidlist $row $idlist
5101 lset rowfinal $row $final
5103 set pad [ntimes [expr {$row - $l}] {}]
5104 set rowidlist [concat $rowidlist $pad]
5105 lappend rowidlist $idlist
5106 set rowfinal [concat $rowfinal $pad]
5107 lappend rowfinal $final
5108 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5114 proc changedrow {row} {
5115 global displayorder iddrawn rowisopt need_redisplay
5117 set l [llength $rowisopt]
5119 lset rowisopt $row 0
5120 if {$row + 1 < $l} {
5121 lset rowisopt [expr {$row + 1}] 0
5122 if {$row + 2 < $l} {
5123 lset rowisopt [expr {$row + 2}] 0
5127 set id [lindex $displayorder $row]
5128 if {[info exists iddrawn($id)]} {
5129 set need_redisplay 1
5133 proc insert_pad {row col npad} {
5136 set pad [ntimes $npad {}]
5137 set idlist [lindex $rowidlist $row]
5138 set bef [lrange $idlist 0 [expr {$col - 1}]]
5139 set aft [lrange $idlist $col end]
5140 set i [lsearch -exact $aft {}]
5142 set aft [lreplace $aft $i $i]
5144 lset rowidlist $row [concat $bef $pad $aft]
5148 proc optimize_rows {row col endrow} {
5149 global rowidlist rowisopt displayorder curview children
5154 for {} {$row < $endrow} {incr row; set col 0} {
5155 if {[lindex $rowisopt $row]} continue
5157 set y0 [expr {$row - 1}]
5158 set ym [expr {$row - 2}]
5159 set idlist [lindex $rowidlist $row]
5160 set previdlist [lindex $rowidlist $y0]
5161 if {$idlist eq {} || $previdlist eq {}} continue
5163 set pprevidlist [lindex $rowidlist $ym]
5164 if {$pprevidlist eq {}} continue
5170 for {} {$col < [llength $idlist]} {incr col} {
5171 set id [lindex $idlist $col]
5172 if {[lindex $previdlist $col] eq $id} continue
5177 set x0 [lsearch -exact $previdlist $id]
5178 if {$x0 < 0} continue
5179 set z [expr {$x0 - $col}]
5183 set xm [lsearch -exact $pprevidlist $id]
5185 set z0 [expr {$xm - $x0}]
5189 # if row y0 is the first child of $id then it's not an arrow
5190 if {[lindex $children($curview,$id) 0] ne
5191 [lindex $displayorder $y0]} {
5195 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5196 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5199 # Looking at lines from this row to the previous row,
5200 # make them go straight up if they end in an arrow on
5201 # the previous row; otherwise make them go straight up
5203 if {$z < -1 || ($z < 0 && $isarrow)} {
5204 # Line currently goes left too much;
5205 # insert pads in the previous row, then optimize it
5206 set npad [expr {-1 - $z + $isarrow}]
5207 insert_pad $y0 $x0 $npad
5209 optimize_rows $y0 $x0 $row
5211 set previdlist [lindex $rowidlist $y0]
5212 set x0 [lsearch -exact $previdlist $id]
5213 set z [expr {$x0 - $col}]
5215 set pprevidlist [lindex $rowidlist $ym]
5216 set xm [lsearch -exact $pprevidlist $id]
5217 set z0 [expr {$xm - $x0}]
5219 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5220 # Line currently goes right too much;
5221 # insert pads in this line
5222 set npad [expr {$z - 1 + $isarrow}]
5223 insert_pad $row $col $npad
5224 set idlist [lindex $rowidlist $row]
5226 set z [expr {$x0 - $col}]
5229 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5230 # this line links to its first child on row $row-2
5231 set id [lindex $displayorder $ym]
5232 set xc [lsearch -exact $pprevidlist $id]
5234 set z0 [expr {$xc - $x0}]
5237 # avoid lines jigging left then immediately right
5238 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5239 insert_pad $y0 $x0 1
5241 optimize_rows $y0 $x0 $row
5242 set previdlist [lindex $rowidlist $y0]
5246 # Find the first column that doesn't have a line going right
5247 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5248 set id [lindex $idlist $col]
5249 if {$id eq {}} break
5250 set x0 [lsearch -exact $previdlist $id]
5252 # check if this is the link to the first child
5253 set kid [lindex $displayorder $y0]
5254 if {[lindex $children($curview,$id) 0] eq $kid} {
5255 # it is, work out offset to child
5256 set x0 [lsearch -exact $previdlist $kid]
5259 if {$x0 <= $col} break
5261 # Insert a pad at that column as long as it has a line and
5262 # isn't the last column
5263 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5264 set idlist [linsert $idlist $col {}]
5265 lset rowidlist $row $idlist
5273 global canvx0 linespc
5274 return [expr {$canvx0 + $col * $linespc}]
5278 global canvy0 linespc
5279 return [expr {$canvy0 + $row * $linespc}]
5282 proc linewidth {id} {
5283 global thickerline lthickness
5286 if {[info exists thickerline] && $id eq $thickerline} {
5287 set wid [expr {2 * $lthickness}]
5292 proc rowranges {id} {
5293 global curview children uparrowlen downarrowlen
5296 set kids $children($curview,$id)
5302 foreach child $kids {
5303 if {![commitinview $child $curview]} break
5304 set row [rowofcommit $child]
5305 if {![info exists prev]} {
5306 lappend ret [expr {$row + 1}]
5308 if {$row <= $prevrow} {
5309 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5311 # see if the line extends the whole way from prevrow to row
5312 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5313 [lsearch -exact [lindex $rowidlist \
5314 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5315 # it doesn't, see where it ends
5316 set r [expr {$prevrow + $downarrowlen}]
5317 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5318 while {[incr r -1] > $prevrow &&
5319 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5321 while {[incr r] <= $row &&
5322 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5326 # see where it starts up again
5327 set r [expr {$row - $uparrowlen}]
5328 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5329 while {[incr r] < $row &&
5330 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5332 while {[incr r -1] >= $prevrow &&
5333 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5339 if {$child eq $id} {
5348 proc drawlineseg {id row endrow arrowlow} {
5349 global rowidlist displayorder iddrawn linesegs
5350 global canv colormap linespc curview maxlinelen parentlist
5352 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5353 set le [expr {$row + 1}]
5356 set c [lsearch -exact [lindex $rowidlist $le] $id]
5362 set x [lindex $displayorder $le]
5367 if {[info exists iddrawn($x)] || $le == $endrow} {
5368 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5384 if {[info exists linesegs($id)]} {
5385 set lines $linesegs($id)
5387 set r0 [lindex $li 0]
5389 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5399 set li [lindex $lines [expr {$i-1}]]
5400 set r1 [lindex $li 1]
5401 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5406 set x [lindex $cols [expr {$le - $row}]]
5407 set xp [lindex $cols [expr {$le - 1 - $row}]]
5408 set dir [expr {$xp - $x}]
5410 set ith [lindex $lines $i 2]
5411 set coords [$canv coords $ith]
5412 set ah [$canv itemcget $ith -arrow]
5413 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5414 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5415 if {$x2 ne {} && $x - $x2 == $dir} {
5416 set coords [lrange $coords 0 end-2]
5419 set coords [list [xc $le $x] [yc $le]]
5422 set itl [lindex $lines [expr {$i-1}] 2]
5423 set al [$canv itemcget $itl -arrow]
5424 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5425 } elseif {$arrowlow} {
5426 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5427 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5431 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5432 for {set y $le} {[incr y -1] > $row} {} {
5434 set xp [lindex $cols [expr {$y - 1 - $row}]]
5435 set ndir [expr {$xp - $x}]
5436 if {$dir != $ndir || $xp < 0} {
5437 lappend coords [xc $y $x] [yc $y]
5443 # join parent line to first child
5444 set ch [lindex $displayorder $row]
5445 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5447 puts "oops: drawlineseg: child $ch not on row $row"
5448 } elseif {$xc != $x} {
5449 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5450 set d [expr {int(0.5 * $linespc)}]
5453 set x2 [expr {$x1 - $d}]
5455 set x2 [expr {$x1 + $d}]
5458 set y1 [expr {$y2 + $d}]
5459 lappend coords $x1 $y1 $x2 $y2
5460 } elseif {$xc < $x - 1} {
5461 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5462 } elseif {$xc > $x + 1} {
5463 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5467 lappend coords [xc $row $x] [yc $row]
5469 set xn [xc $row $xp]
5471 lappend coords $xn $yn
5475 set t [$canv create line $coords -width [linewidth $id] \
5476 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5479 set lines [linsert $lines $i [list $row $le $t]]
5481 $canv coords $ith $coords
5482 if {$arrow ne $ah} {
5483 $canv itemconf $ith -arrow $arrow
5485 lset lines $i 0 $row
5488 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5489 set ndir [expr {$xo - $xp}]
5490 set clow [$canv coords $itl]
5491 if {$dir == $ndir} {
5492 set clow [lrange $clow 2 end]
5494 set coords [concat $coords $clow]
5496 lset lines [expr {$i-1}] 1 $le
5498 # coalesce two pieces
5500 set b [lindex $lines [expr {$i-1}] 0]
5501 set e [lindex $lines $i 1]
5502 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5504 $canv coords $itl $coords
5505 if {$arrow ne $al} {
5506 $canv itemconf $itl -arrow $arrow
5510 set linesegs($id) $lines
5514 proc drawparentlinks {id row} {
5515 global rowidlist canv colormap curview parentlist
5516 global idpos linespc
5518 set rowids [lindex $rowidlist $row]
5519 set col [lsearch -exact $rowids $id]
5520 if {$col < 0} return
5521 set olds [lindex $parentlist $row]
5522 set row2 [expr {$row + 1}]
5523 set x [xc $row $col]
5526 set d [expr {int(0.5 * $linespc)}]
5527 set ymid [expr {$y + $d}]
5528 set ids [lindex $rowidlist $row2]
5529 # rmx = right-most X coord used
5532 set i [lsearch -exact $ids $p]
5534 puts "oops, parent $p of $id not in list"
5537 set x2 [xc $row2 $i]
5541 set j [lsearch -exact $rowids $p]
5543 # drawlineseg will do this one for us
5547 # should handle duplicated parents here...
5548 set coords [list $x $y]
5550 # if attaching to a vertical segment, draw a smaller
5551 # slant for visual distinctness
5554 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5556 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5558 } elseif {$i < $col && $i < $j} {
5559 # segment slants towards us already
5560 lappend coords [xc $row $j] $y
5562 if {$i < $col - 1} {
5563 lappend coords [expr {$x2 + $linespc}] $y
5564 } elseif {$i > $col + 1} {
5565 lappend coords [expr {$x2 - $linespc}] $y
5567 lappend coords $x2 $y2
5570 lappend coords $x2 $y2
5572 set t [$canv create line $coords -width [linewidth $p] \
5573 -fill $colormap($p) -tags lines.$p]
5577 if {$rmx > [lindex $idpos($id) 1]} {
5578 lset idpos($id) 1 $rmx
5583 proc drawlines {id} {
5586 $canv itemconf lines.$id -width [linewidth $id]
5589 proc drawcmittext {id row col} {
5590 global linespc canv canv2 canv3 fgcolor curview
5591 global cmitlisted commitinfo rowidlist parentlist
5592 global rowtextx idpos idtags idheads idotherrefs
5593 global linehtag linentag linedtag selectedline
5594 global canvxmax boldids boldnameids fgcolor
5595 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5597 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5598 set listed $cmitlisted($curview,$id)
5599 if {$id eq $nullid} {
5601 } elseif {$id eq $nullid2} {
5603 } elseif {$id eq $mainheadid} {
5606 set ofill [lindex $circlecolors $listed]
5608 set x [xc $row $col]
5610 set orad [expr {$linespc / 3}]
5612 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5613 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5614 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5615 } elseif {$listed == 3} {
5616 # triangle pointing left for left-side commits
5617 set t [$canv create polygon \
5618 [expr {$x - $orad}] $y \
5619 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5620 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5621 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5623 # triangle pointing right for right-side commits
5624 set t [$canv create polygon \
5625 [expr {$x + $orad - 1}] $y \
5626 [expr {$x - $orad}] [expr {$y - $orad}] \
5627 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
5628 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5630 set circleitem($row) $t
5632 $canv bind $t <1> {selcanvline {} %x %y}
5633 set rmx [llength [lindex $rowidlist $row]]
5634 set olds [lindex $parentlist $row]
5636 set nextids [lindex $rowidlist [expr {$row + 1}]]
5638 set i [lsearch -exact $nextids $p]
5644 set xt [xc $row $rmx]
5645 set rowtextx($row) $xt
5646 set idpos($id) [list $x $xt $y]
5647 if {[info exists idtags($id)] || [info exists idheads($id)]
5648 || [info exists idotherrefs($id)]} {
5649 set xt [drawtags $id $x $xt $y]
5651 set headline [lindex $commitinfo($id) 0]
5652 set name [lindex $commitinfo($id) 1]
5653 set date [lindex $commitinfo($id) 2]
5654 set date [formatdate $date]
5657 set isbold [ishighlighted $id]
5660 set font mainfontbold
5662 lappend boldnameids $id
5663 set nfont mainfontbold
5666 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
5667 -text $headline -font $font -tags text]
5668 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
5669 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
5670 -text $name -font $nfont -tags text]
5671 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
5672 -text $date -font mainfont -tags text]
5673 if {$selectedline == $row} {
5676 set xr [expr {$xt + [font measure $font $headline]}]
5677 if {$xr > $canvxmax} {
5683 proc drawcmitrow {row} {
5684 global displayorder rowidlist nrows_drawn
5685 global iddrawn markingmatches
5686 global commitinfo numcommits
5687 global filehighlight fhighlights findpattern nhighlights
5688 global hlview vhighlights
5689 global highlight_related rhighlights
5691 if {$row >= $numcommits} return
5693 set id [lindex $displayorder $row]
5694 if {[info exists hlview] && ![info exists vhighlights($id)]} {
5695 askvhighlight $row $id
5697 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
5698 askfilehighlight $row $id
5700 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
5701 askfindhighlight $row $id
5703 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
5704 askrelhighlight $row $id
5706 if {![info exists iddrawn($id)]} {
5707 set col [lsearch -exact [lindex $rowidlist $row] $id]
5709 puts "oops, row $row id $id not in list"
5712 if {![info exists commitinfo($id)]} {
5716 drawcmittext $id $row $col
5720 if {$markingmatches} {
5721 markrowmatches $row $id
5725 proc drawcommits {row {endrow {}}} {
5726 global numcommits iddrawn displayorder curview need_redisplay
5727 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
5732 if {$endrow eq {}} {
5735 if {$endrow >= $numcommits} {
5736 set endrow [expr {$numcommits - 1}]
5739 set rl1 [expr {$row - $downarrowlen - 3}]
5743 set ro1 [expr {$row - 3}]
5747 set r2 [expr {$endrow + $uparrowlen + 3}]
5748 if {$r2 > $numcommits} {
5751 for {set r $rl1} {$r < $r2} {incr r} {
5752 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
5756 set rl1 [expr {$r + 1}]
5762 optimize_rows $ro1 0 $r2
5763 if {$need_redisplay || $nrows_drawn > 2000} {
5767 # make the lines join to already-drawn rows either side
5768 set r [expr {$row - 1}]
5769 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
5772 set er [expr {$endrow + 1}]
5773 if {$er >= $numcommits ||
5774 ![info exists iddrawn([lindex $displayorder $er])]} {
5777 for {} {$r <= $er} {incr r} {
5778 set id [lindex $displayorder $r]
5779 set wasdrawn [info exists iddrawn($id)]
5781 if {$r == $er} break
5782 set nextid [lindex $displayorder [expr {$r + 1}]]
5783 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
5784 drawparentlinks $id $r
5786 set rowids [lindex $rowidlist $r]
5787 foreach lid $rowids {
5788 if {$lid eq {}} continue
5789 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
5791 # see if this is the first child of any of its parents
5792 foreach p [lindex $parentlist $r] {
5793 if {[lsearch -exact $rowids $p] < 0} {
5794 # make this line extend up to the child
5795 set lineend($p) [drawlineseg $p $r $er 0]
5799 set lineend($lid) [drawlineseg $lid $r $er 1]
5805 proc undolayout {row} {
5806 global uparrowlen mingaplen downarrowlen
5807 global rowidlist rowisopt rowfinal need_redisplay
5809 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
5813 if {[llength $rowidlist] > $r} {
5815 set rowidlist [lrange $rowidlist 0 $r]
5816 set rowfinal [lrange $rowfinal 0 $r]
5817 set rowisopt [lrange $rowisopt 0 $r]
5818 set need_redisplay 1
5823 proc drawvisible {} {
5824 global canv linespc curview vrowmod selectedline targetrow targetid
5825 global need_redisplay cscroll numcommits
5827 set fs [$canv yview]
5828 set ymax [lindex [$canv cget -scrollregion] 3]
5829 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
5830 set f0 [lindex $fs 0]
5831 set f1 [lindex $fs 1]
5832 set y0 [expr {int($f0 * $ymax)}]
5833 set y1 [expr {int($f1 * $ymax)}]
5835 if {[info exists targetid]} {
5836 if {[commitinview $targetid $curview]} {
5837 set r [rowofcommit $targetid]
5838 if {$r != $targetrow} {
5839 # Fix up the scrollregion and change the scrolling position
5840 # now that our target row has moved.
5841 set diff [expr {($r - $targetrow) * $linespc}]
5844 set ymax [lindex [$canv cget -scrollregion] 3]
5847 set f0 [expr {$y0 / $ymax}]
5848 set f1 [expr {$y1 / $ymax}]
5849 allcanvs yview moveto $f0
5850 $cscroll set $f0 $f1
5851 set need_redisplay 1
5858 set row [expr {int(($y0 - 3) / $linespc) - 1}]
5859 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
5860 if {$endrow >= $vrowmod($curview)} {
5861 update_arcrows $curview
5863 if {$selectedline ne {} &&
5864 $row <= $selectedline && $selectedline <= $endrow} {
5865 set targetrow $selectedline
5866 } elseif {[info exists targetid]} {
5867 set targetrow [expr {int(($row + $endrow) / 2)}]
5869 if {[info exists targetrow]} {
5870 if {$targetrow >= $numcommits} {
5871 set targetrow [expr {$numcommits - 1}]
5873 set targetid [commitonrow $targetrow]
5875 drawcommits $row $endrow
5878 proc clear_display {} {
5879 global iddrawn linesegs need_redisplay nrows_drawn
5880 global vhighlights fhighlights nhighlights rhighlights
5881 global linehtag linentag linedtag boldids boldnameids
5884 catch {unset iddrawn}
5885 catch {unset linesegs}
5886 catch {unset linehtag}
5887 catch {unset linentag}
5888 catch {unset linedtag}
5891 catch {unset vhighlights}
5892 catch {unset fhighlights}
5893 catch {unset nhighlights}
5894 catch {unset rhighlights}
5895 set need_redisplay 0
5899 proc findcrossings {id} {
5900 global rowidlist parentlist numcommits displayorder
5904 foreach {s e} [rowranges $id] {
5905 if {$e >= $numcommits} {
5906 set e [expr {$numcommits - 1}]
5908 if {$e <= $s} continue
5909 for {set row $e} {[incr row -1] >= $s} {} {
5910 set x [lsearch -exact [lindex $rowidlist $row] $id]
5912 set olds [lindex $parentlist $row]
5913 set kid [lindex $displayorder $row]
5914 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
5915 if {$kidx < 0} continue
5916 set nextrow [lindex $rowidlist [expr {$row + 1}]]
5918 set px [lsearch -exact $nextrow $p]
5919 if {$px < 0} continue
5920 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
5921 if {[lsearch -exact $ccross $p] >= 0} continue
5922 if {$x == $px + ($kidx < $px? -1: 1)} {
5924 } elseif {[lsearch -exact $cross $p] < 0} {
5931 return [concat $ccross {{}} $cross]
5934 proc assigncolor {id} {
5935 global colormap colors nextcolor
5936 global parents children children curview
5938 if {[info exists colormap($id)]} return
5939 set ncolors [llength $colors]
5940 if {[info exists children($curview,$id)]} {
5941 set kids $children($curview,$id)
5945 if {[llength $kids] == 1} {
5946 set child [lindex $kids 0]
5947 if {[info exists colormap($child)]
5948 && [llength $parents($curview,$child)] == 1} {
5949 set colormap($id) $colormap($child)
5955 foreach x [findcrossings $id] {
5957 # delimiter between corner crossings and other crossings
5958 if {[llength $badcolors] >= $ncolors - 1} break
5959 set origbad $badcolors
5961 if {[info exists colormap($x)]
5962 && [lsearch -exact $badcolors $colormap($x)] < 0} {
5963 lappend badcolors $colormap($x)
5966 if {[llength $badcolors] >= $ncolors} {
5967 set badcolors $origbad
5969 set origbad $badcolors
5970 if {[llength $badcolors] < $ncolors - 1} {
5971 foreach child $kids {
5972 if {[info exists colormap($child)]
5973 && [lsearch -exact $badcolors $colormap($child)] < 0} {
5974 lappend badcolors $colormap($child)
5976 foreach p $parents($curview,$child) {
5977 if {[info exists colormap($p)]
5978 && [lsearch -exact $badcolors $colormap($p)] < 0} {
5979 lappend badcolors $colormap($p)
5983 if {[llength $badcolors] >= $ncolors} {
5984 set badcolors $origbad
5987 for {set i 0} {$i <= $ncolors} {incr i} {
5988 set c [lindex $colors $nextcolor]
5989 if {[incr nextcolor] >= $ncolors} {
5992 if {[lsearch -exact $badcolors $c]} break
5994 set colormap($id) $c
5997 proc bindline {t id} {
6000 $canv bind $t <Enter> "lineenter %x %y $id"
6001 $canv bind $t <Motion> "linemotion %x %y $id"
6002 $canv bind $t <Leave> "lineleave $id"
6003 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6006 proc drawtags {id x xt y1} {
6007 global idtags idheads idotherrefs mainhead
6008 global linespc lthickness
6009 global canv rowtextx curview fgcolor bgcolor ctxbut
6014 if {[info exists idtags($id)]} {
6015 set marks $idtags($id)
6016 set ntags [llength $marks]
6018 if {[info exists idheads($id)]} {
6019 set marks [concat $marks $idheads($id)]
6020 set nheads [llength $idheads($id)]
6022 if {[info exists idotherrefs($id)]} {
6023 set marks [concat $marks $idotherrefs($id)]
6029 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6030 set yt [expr {$y1 - 0.5 * $linespc}]
6031 set yb [expr {$yt + $linespc - 1}]
6035 foreach tag $marks {
6037 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6038 set wid [font measure mainfontbold $tag]
6040 set wid [font measure mainfont $tag]
6044 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6046 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6047 -width $lthickness -fill black -tags tag.$id]
6049 foreach tag $marks x $xvals wid $wvals {
6050 set xl [expr {$x + $delta}]
6051 set xr [expr {$x + $delta + $wid + $lthickness}]
6053 if {[incr ntags -1] >= 0} {
6055 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6056 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6057 -width 1 -outline black -fill yellow -tags tag.$id]
6058 $canv bind $t <1> [list showtag $tag 1]
6059 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6061 # draw a head or other ref
6062 if {[incr nheads -1] >= 0} {
6064 if {$tag eq $mainhead} {
6065 set font mainfontbold
6070 set xl [expr {$xl - $delta/2}]
6071 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6072 -width 1 -outline black -fill $col -tags tag.$id
6073 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6074 set rwid [font measure mainfont $remoteprefix]
6075 set xi [expr {$x + 1}]
6076 set yti [expr {$yt + 1}]
6077 set xri [expr {$x + $rwid}]
6078 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6079 -width 0 -fill "#ffddaa" -tags tag.$id
6082 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
6083 -font $font -tags [list tag.$id text]]
6085 $canv bind $t <1> [list showtag $tag 1]
6086 } elseif {$nheads >= 0} {
6087 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag]
6093 proc xcoord {i level ln} {
6094 global canvx0 xspc1 xspc2
6096 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6097 if {$i > 0 && $i == $level} {
6098 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6099 } elseif {$i > $level} {
6100 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6105 proc show_status {msg} {
6109 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6110 -tags text -fill $fgcolor
6113 # Don't change the text pane cursor if it is currently the hand cursor,
6114 # showing that we are over a sha1 ID link.
6115 proc settextcursor {c} {
6116 global ctext curtextcursor
6118 if {[$ctext cget -cursor] == $curtextcursor} {
6119 $ctext config -cursor $c
6121 set curtextcursor $c
6124 proc nowbusy {what {name {}}} {
6125 global isbusy busyname statusw
6127 if {[array names isbusy] eq {}} {
6128 . config -cursor watch
6132 set busyname($what) $name
6134 $statusw conf -text $name
6138 proc notbusy {what} {
6139 global isbusy maincursor textcursor busyname statusw
6143 if {$busyname($what) ne {} &&
6144 [$statusw cget -text] eq $busyname($what)} {
6145 $statusw conf -text {}
6148 if {[array names isbusy] eq {}} {
6149 . config -cursor $maincursor
6150 settextcursor $textcursor
6154 proc findmatches {f} {
6155 global findtype findstring
6156 if {$findtype == [mc "Regexp"]} {
6157 set matches [regexp -indices -all -inline $findstring $f]
6160 if {$findtype == [mc "IgnCase"]} {
6161 set f [string tolower $f]
6162 set fs [string tolower $fs]
6166 set l [string length $fs]
6167 while {[set j [string first $fs $f $i]] >= 0} {
6168 lappend matches [list $j [expr {$j+$l-1}]]
6169 set i [expr {$j + $l}]
6175 proc dofind {{dirn 1} {wrap 1}} {
6176 global findstring findstartline findcurline selectedline numcommits
6177 global gdttype filehighlight fh_serial find_dirn findallowwrap
6179 if {[info exists find_dirn]} {
6180 if {$find_dirn == $dirn} return
6184 if {$findstring eq {} || $numcommits == 0} return
6185 if {$selectedline eq {}} {
6186 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6188 set findstartline $selectedline
6190 set findcurline $findstartline
6191 nowbusy finding [mc "Searching"]
6192 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6193 after cancel do_file_hl $fh_serial
6194 do_file_hl $fh_serial
6197 set findallowwrap $wrap
6201 proc stopfinding {} {
6202 global find_dirn findcurline fprogcoord
6204 if {[info exists find_dirn]} {
6215 global commitdata commitinfo numcommits findpattern findloc
6216 global findstartline findcurline findallowwrap
6217 global find_dirn gdttype fhighlights fprogcoord
6218 global curview varcorder vrownum varccommits vrowmod
6220 if {![info exists find_dirn]} {
6223 set fldtypes [list [mc "Headline"] [mc "Author"] [mc "Date"] [mc "Committer"] [mc "CDate"] [mc "Comments"]]
6226 if {$find_dirn > 0} {
6228 if {$l >= $numcommits} {
6231 if {$l <= $findstartline} {
6232 set lim [expr {$findstartline + 1}]
6235 set moretodo $findallowwrap
6242 if {$l >= $findstartline} {
6243 set lim [expr {$findstartline - 1}]
6246 set moretodo $findallowwrap
6249 set n [expr {($lim - $l) * $find_dirn}]
6254 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6255 update_arcrows $curview
6259 set ai [bsearch $vrownum($curview) $l]
6260 set a [lindex $varcorder($curview) $ai]
6261 set arow [lindex $vrownum($curview) $ai]
6262 set ids [lindex $varccommits($curview,$a)]
6263 set arowend [expr {$arow + [llength $ids]}]
6264 if {$gdttype eq [mc "containing:"]} {
6265 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6266 if {$l < $arow || $l >= $arowend} {
6268 set a [lindex $varcorder($curview) $ai]
6269 set arow [lindex $vrownum($curview) $ai]
6270 set ids [lindex $varccommits($curview,$a)]
6271 set arowend [expr {$arow + [llength $ids]}]
6273 set id [lindex $ids [expr {$l - $arow}]]
6274 # shouldn't happen unless git log doesn't give all the commits...
6275 if {![info exists commitdata($id)] ||
6276 ![doesmatch $commitdata($id)]} {
6279 if {![info exists commitinfo($id)]} {
6282 set info $commitinfo($id)
6283 foreach f $info ty $fldtypes {
6284 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6293 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6294 if {$l < $arow || $l >= $arowend} {
6296 set a [lindex $varcorder($curview) $ai]
6297 set arow [lindex $vrownum($curview) $ai]
6298 set ids [lindex $varccommits($curview,$a)]
6299 set arowend [expr {$arow + [llength $ids]}]
6301 set id [lindex $ids [expr {$l - $arow}]]
6302 if {![info exists fhighlights($id)]} {
6303 # this sets fhighlights($id) to -1
6304 askfilehighlight $l $id
6306 if {$fhighlights($id) > 0} {
6310 if {$fhighlights($id) < 0} {
6313 set findcurline [expr {$l - $find_dirn}]
6318 if {$found || ($domore && !$moretodo)} {
6334 set findcurline [expr {$l - $find_dirn}]
6336 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6340 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6345 proc findselectline {l} {
6346 global findloc commentend ctext findcurline markingmatches gdttype
6348 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6351 if {$markingmatches &&
6352 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6353 # highlight the matches in the comments
6354 set f [$ctext get 1.0 $commentend]
6355 set matches [findmatches $f]
6356 foreach match $matches {
6357 set start [lindex $match 0]
6358 set end [expr {[lindex $match 1] + 1}]
6359 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6365 # mark the bits of a headline or author that match a find string
6366 proc markmatches {canv l str tag matches font row} {
6369 set bbox [$canv bbox $tag]
6370 set x0 [lindex $bbox 0]
6371 set y0 [lindex $bbox 1]
6372 set y1 [lindex $bbox 3]
6373 foreach match $matches {
6374 set start [lindex $match 0]
6375 set end [lindex $match 1]
6376 if {$start > $end} continue
6377 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6378 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6379 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6380 [expr {$x0+$xlen+2}] $y1 \
6381 -outline {} -tags [list match$l matches] -fill yellow]
6383 if {$row == $selectedline} {
6384 $canv raise $t secsel
6389 proc unmarkmatches {} {
6390 global markingmatches
6392 allcanvs delete matches
6393 set markingmatches 0
6397 proc selcanvline {w x y} {
6398 global canv canvy0 ctext linespc
6400 set ymax [lindex [$canv cget -scrollregion] 3]
6401 if {$ymax == {}} return
6402 set yfrac [lindex [$canv yview] 0]
6403 set y [expr {$y + $yfrac * $ymax}]
6404 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6409 set xmax [lindex [$canv cget -scrollregion] 2]
6410 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6411 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6417 proc commit_descriptor {p} {
6419 if {![info exists commitinfo($p)]} {
6423 if {[llength $commitinfo($p)] > 1} {
6424 set l [lindex $commitinfo($p) 0]
6429 # append some text to the ctext widget, and make any SHA1 ID
6430 # that we know about be a clickable link.
6431 proc appendwithlinks {text tags} {
6432 global ctext linknum curview
6434 set start [$ctext index "end - 1c"]
6435 $ctext insert end $text $tags
6436 set links [regexp -indices -all -inline {\m[0-9a-f]{6,40}\M} $text]
6440 set linkid [string range $text $s $e]
6442 $ctext tag delete link$linknum
6443 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6444 setlink $linkid link$linknum
6449 proc setlink {id lk} {
6450 global curview ctext pendinglinks
6453 if {[string length $id] < 40} {
6454 set matches [longid $id]
6455 if {[llength $matches] > 0} {
6456 if {[llength $matches] > 1} return
6458 set id [lindex $matches 0]
6461 set known [commitinview $id $curview]
6464 $ctext tag conf $lk -foreground blue -underline 1
6465 $ctext tag bind $lk <1> [list selbyid $id]
6466 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6467 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6469 lappend pendinglinks($id) $lk
6470 interestedin $id {makelink %P}
6474 proc makelink {id} {
6477 if {![info exists pendinglinks($id)]} return
6478 foreach lk $pendinglinks($id) {
6481 unset pendinglinks($id)
6484 proc linkcursor {w inc} {
6485 global linkentercount curtextcursor
6487 if {[incr linkentercount $inc] > 0} {
6488 $w configure -cursor hand2
6490 $w configure -cursor $curtextcursor
6491 if {$linkentercount < 0} {
6492 set linkentercount 0
6497 proc viewnextline {dir} {
6501 set ymax [lindex [$canv cget -scrollregion] 3]
6502 set wnow [$canv yview]
6503 set wtop [expr {[lindex $wnow 0] * $ymax}]
6504 set newtop [expr {$wtop + $dir * $linespc}]
6507 } elseif {$newtop > $ymax} {
6510 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6513 # add a list of tag or branch names at position pos
6514 # returns the number of names inserted
6515 proc appendrefs {pos ids var} {
6516 global ctext linknum curview $var maxrefs
6518 if {[catch {$ctext index $pos}]} {
6521 $ctext conf -state normal
6522 $ctext delete $pos "$pos lineend"
6525 foreach tag [set $var\($id\)] {
6526 lappend tags [list $tag $id]
6529 if {[llength $tags] > $maxrefs} {
6530 $ctext insert $pos "many ([llength $tags])"
6532 set tags [lsort -index 0 -decreasing $tags]
6535 set id [lindex $ti 1]
6538 $ctext tag delete $lk
6539 $ctext insert $pos $sep
6540 $ctext insert $pos [lindex $ti 0] $lk
6545 $ctext conf -state disabled
6546 return [llength $tags]
6549 # called when we have finished computing the nearby tags
6550 proc dispneartags {delay} {
6551 global selectedline currentid showneartags tagphase
6553 if {$selectedline eq {} || !$showneartags} return
6554 after cancel dispnexttag
6556 after 200 dispnexttag
6559 after idle dispnexttag
6564 proc dispnexttag {} {
6565 global selectedline currentid showneartags tagphase ctext
6567 if {$selectedline eq {} || !$showneartags} return
6568 switch -- $tagphase {
6570 set dtags [desctags $currentid]
6572 appendrefs precedes $dtags idtags
6576 set atags [anctags $currentid]
6578 appendrefs follows $atags idtags
6582 set dheads [descheads $currentid]
6583 if {$dheads ne {}} {
6584 if {[appendrefs branch $dheads idheads] > 1
6585 && [$ctext get "branch -3c"] eq "h"} {
6586 # turn "Branch" into "Branches"
6587 $ctext conf -state normal
6588 $ctext insert "branch -2c" "es"
6589 $ctext conf -state disabled
6594 if {[incr tagphase] <= 2} {
6595 after idle dispnexttag
6599 proc make_secsel {id} {
6600 global linehtag linentag linedtag canv canv2 canv3
6602 if {![info exists linehtag($id)]} return
6604 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
6605 -tags secsel -fill [$canv cget -selectbackground]]
6607 $canv2 delete secsel
6608 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
6609 -tags secsel -fill [$canv2 cget -selectbackground]]
6611 $canv3 delete secsel
6612 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
6613 -tags secsel -fill [$canv3 cget -selectbackground]]
6617 proc selectline {l isnew {desired_loc {}}} {
6618 global canv ctext commitinfo selectedline
6619 global canvy0 linespc parents children curview
6620 global currentid sha1entry
6621 global commentend idtags linknum
6622 global mergemax numcommits pending_select
6623 global cmitmode showneartags allcommits
6624 global targetrow targetid lastscrollrows
6625 global autoselect jump_to_here
6627 catch {unset pending_select}
6632 if {$l < 0 || $l >= $numcommits} return
6633 set id [commitonrow $l]
6638 if {$lastscrollrows < $numcommits} {
6642 set y [expr {$canvy0 + $l * $linespc}]
6643 set ymax [lindex [$canv cget -scrollregion] 3]
6644 set ytop [expr {$y - $linespc - 1}]
6645 set ybot [expr {$y + $linespc + 1}]
6646 set wnow [$canv yview]
6647 set wtop [expr {[lindex $wnow 0] * $ymax}]
6648 set wbot [expr {[lindex $wnow 1] * $ymax}]
6649 set wh [expr {$wbot - $wtop}]
6651 if {$ytop < $wtop} {
6652 if {$ybot < $wtop} {
6653 set newtop [expr {$y - $wh / 2.0}]
6656 if {$newtop > $wtop - $linespc} {
6657 set newtop [expr {$wtop - $linespc}]
6660 } elseif {$ybot > $wbot} {
6661 if {$ytop > $wbot} {
6662 set newtop [expr {$y - $wh / 2.0}]
6664 set newtop [expr {$ybot - $wh}]
6665 if {$newtop < $wtop + $linespc} {
6666 set newtop [expr {$wtop + $linespc}]
6670 if {$newtop != $wtop} {
6674 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6681 addtohistory [list selbyid $id]
6684 $sha1entry delete 0 end
6685 $sha1entry insert 0 $id
6687 $sha1entry selection from 0
6688 $sha1entry selection to end
6692 $ctext conf -state normal
6695 if {![info exists commitinfo($id)]} {
6698 set info $commitinfo($id)
6699 set date [formatdate [lindex $info 2]]
6700 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
6701 set date [formatdate [lindex $info 4]]
6702 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
6703 if {[info exists idtags($id)]} {
6704 $ctext insert end [mc "Tags:"]
6705 foreach tag $idtags($id) {
6706 $ctext insert end " $tag"
6708 $ctext insert end "\n"
6712 set olds $parents($curview,$id)
6713 if {[llength $olds] > 1} {
6716 if {$np >= $mergemax} {
6721 $ctext insert end "[mc "Parent"]: " $tag
6722 appendwithlinks [commit_descriptor $p] {}
6727 append headers "[mc "Parent"]: [commit_descriptor $p]"
6731 foreach c $children($curview,$id) {
6732 append headers "[mc "Child"]: [commit_descriptor $c]"
6735 # make anything that looks like a SHA1 ID be a clickable link
6736 appendwithlinks $headers {}
6737 if {$showneartags} {
6738 if {![info exists allcommits]} {
6741 $ctext insert end "[mc "Branch"]: "
6742 $ctext mark set branch "end -1c"
6743 $ctext mark gravity branch left
6744 $ctext insert end "\n[mc "Follows"]: "
6745 $ctext mark set follows "end -1c"
6746 $ctext mark gravity follows left
6747 $ctext insert end "\n[mc "Precedes"]: "
6748 $ctext mark set precedes "end -1c"
6749 $ctext mark gravity precedes left
6750 $ctext insert end "\n"
6753 $ctext insert end "\n"
6754 set comment [lindex $info 5]
6755 if {[string first "\r" $comment] >= 0} {
6756 set comment [string map {"\r" "\n "} $comment]
6758 appendwithlinks $comment {comment}
6760 $ctext tag remove found 1.0 end
6761 $ctext conf -state disabled
6762 set commentend [$ctext index "end - 1c"]
6764 set jump_to_here $desired_loc
6765 init_flist [mc "Comments"]
6766 if {$cmitmode eq "tree"} {
6768 } elseif {[llength $olds] <= 1} {
6775 proc selfirstline {} {
6780 proc sellastline {} {
6783 set l [expr {$numcommits - 1}]
6787 proc selnextline {dir} {
6790 if {$selectedline eq {}} return
6791 set l [expr {$selectedline + $dir}]
6796 proc selnextpage {dir} {
6797 global canv linespc selectedline numcommits
6799 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
6803 allcanvs yview scroll [expr {$dir * $lpp}] units
6805 if {$selectedline eq {}} return
6806 set l [expr {$selectedline + $dir * $lpp}]
6809 } elseif {$l >= $numcommits} {
6810 set l [expr $numcommits - 1]
6816 proc unselectline {} {
6817 global selectedline currentid
6820 catch {unset currentid}
6821 allcanvs delete secsel
6825 proc reselectline {} {
6828 if {$selectedline ne {}} {
6829 selectline $selectedline 0
6833 proc addtohistory {cmd} {
6834 global history historyindex curview
6836 set elt [list $curview $cmd]
6837 if {$historyindex > 0
6838 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
6842 if {$historyindex < [llength $history]} {
6843 set history [lreplace $history $historyindex end $elt]
6845 lappend history $elt
6848 if {$historyindex > 1} {
6849 .tf.bar.leftbut conf -state normal
6851 .tf.bar.leftbut conf -state disabled
6853 .tf.bar.rightbut conf -state disabled
6859 set view [lindex $elt 0]
6860 set cmd [lindex $elt 1]
6861 if {$curview != $view} {
6868 global history historyindex
6871 if {$historyindex > 1} {
6872 incr historyindex -1
6873 godo [lindex $history [expr {$historyindex - 1}]]
6874 .tf.bar.rightbut conf -state normal
6876 if {$historyindex <= 1} {
6877 .tf.bar.leftbut conf -state disabled
6882 global history historyindex
6885 if {$historyindex < [llength $history]} {
6886 set cmd [lindex $history $historyindex]
6889 .tf.bar.leftbut conf -state normal
6891 if {$historyindex >= [llength $history]} {
6892 .tf.bar.rightbut conf -state disabled
6897 global treefilelist treeidlist diffids diffmergeid treepending
6898 global nullid nullid2
6901 catch {unset diffmergeid}
6902 if {![info exists treefilelist($id)]} {
6903 if {![info exists treepending]} {
6904 if {$id eq $nullid} {
6905 set cmd [list | git ls-files]
6906 } elseif {$id eq $nullid2} {
6907 set cmd [list | git ls-files --stage -t]
6909 set cmd [list | git ls-tree -r $id]
6911 if {[catch {set gtf [open $cmd r]}]} {
6915 set treefilelist($id) {}
6916 set treeidlist($id) {}
6917 fconfigure $gtf -blocking 0 -encoding binary
6918 filerun $gtf [list gettreeline $gtf $id]
6925 proc gettreeline {gtf id} {
6926 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
6929 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
6930 if {$diffids eq $nullid} {
6933 set i [string first "\t" $line]
6934 if {$i < 0} continue
6935 set fname [string range $line [expr {$i+1}] end]
6936 set line [string range $line 0 [expr {$i-1}]]
6937 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
6938 set sha1 [lindex $line 2]
6939 lappend treeidlist($id) $sha1
6941 if {[string index $fname 0] eq "\""} {
6942 set fname [lindex $fname 0]
6944 set fname [encoding convertfrom $fname]
6945 lappend treefilelist($id) $fname
6948 return [expr {$nl >= 1000? 2: 1}]
6952 if {$cmitmode ne "tree"} {
6953 if {![info exists diffmergeid]} {
6954 gettreediffs $diffids
6956 } elseif {$id ne $diffids} {
6965 global treefilelist treeidlist diffids nullid nullid2
6966 global ctext_file_names ctext_file_lines
6967 global ctext commentend
6969 set i [lsearch -exact $treefilelist($diffids) $f]
6971 puts "oops, $f not in list for id $diffids"
6974 if {$diffids eq $nullid} {
6975 if {[catch {set bf [open $f r]} err]} {
6976 puts "oops, can't read $f: $err"
6980 set blob [lindex $treeidlist($diffids) $i]
6981 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
6982 puts "oops, error reading blob $blob: $err"
6986 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
6987 filerun $bf [list getblobline $bf $diffids]
6988 $ctext config -state normal
6989 clear_ctext $commentend
6990 lappend ctext_file_names $f
6991 lappend ctext_file_lines [lindex [split $commentend "."] 0]
6992 $ctext insert end "\n"
6993 $ctext insert end "$f\n" filesep
6994 $ctext config -state disabled
6995 $ctext yview $commentend
6999 proc getblobline {bf id} {
7000 global diffids cmitmode ctext
7002 if {$id ne $diffids || $cmitmode ne "tree"} {
7006 $ctext config -state normal
7008 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7009 $ctext insert end "$line\n"
7012 global jump_to_here ctext_file_names commentend
7014 # delete last newline
7015 $ctext delete "end - 2c" "end - 1c"
7017 if {$jump_to_here ne {} &&
7018 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7019 set lnum [expr {[lindex $jump_to_here 1] +
7020 [lindex [split $commentend .] 0]}]
7021 mark_ctext_line $lnum
7025 $ctext config -state disabled
7026 return [expr {$nl >= 1000? 2: 1}]
7029 proc mark_ctext_line {lnum} {
7030 global ctext markbgcolor
7032 $ctext tag delete omark
7033 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7034 $ctext tag conf omark -background $markbgcolor
7038 proc mergediff {id} {
7040 global diffids treediffs
7041 global parents curview
7045 set treediffs($id) {}
7046 set np [llength $parents($curview,$id)]
7051 proc startdiff {ids} {
7052 global treediffs diffids treepending diffmergeid nullid nullid2
7056 catch {unset diffmergeid}
7057 if {![info exists treediffs($ids)] ||
7058 [lsearch -exact $ids $nullid] >= 0 ||
7059 [lsearch -exact $ids $nullid2] >= 0} {
7060 if {![info exists treepending]} {
7068 proc path_filter {filter name} {
7070 set l [string length $p]
7071 if {[string index $p end] eq "/"} {
7072 if {[string compare -length $l $p $name] == 0} {
7076 if {[string compare -length $l $p $name] == 0 &&
7077 ([string length $name] == $l ||
7078 [string index $name $l] eq "/")} {
7086 proc addtocflist {ids} {
7089 add_flist $treediffs($ids)
7093 proc diffcmd {ids flags} {
7094 global nullid nullid2
7096 set i [lsearch -exact $ids $nullid]
7097 set j [lsearch -exact $ids $nullid2]
7099 if {[llength $ids] > 1 && $j < 0} {
7100 # comparing working directory with some specific revision
7101 set cmd [concat | git diff-index $flags]
7103 lappend cmd -R [lindex $ids 1]
7105 lappend cmd [lindex $ids 0]
7108 # comparing working directory with index
7109 set cmd [concat | git diff-files $flags]
7114 } elseif {$j >= 0} {
7115 set cmd [concat | git diff-index --cached $flags]
7116 if {[llength $ids] > 1} {
7117 # comparing index with specific revision
7119 lappend cmd -R [lindex $ids 1]
7121 lappend cmd [lindex $ids 0]
7124 # comparing index with HEAD
7128 set cmd [concat | git diff-tree -r $flags $ids]
7133 proc gettreediffs {ids} {
7134 global treediff treepending
7136 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
7138 set treepending $ids
7140 fconfigure $gdtf -blocking 0 -encoding binary
7141 filerun $gdtf [list gettreediffline $gdtf $ids]
7144 proc gettreediffline {gdtf ids} {
7145 global treediff treediffs treepending diffids diffmergeid
7146 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7151 if {$perfile_attrs} {
7152 # cache_gitattr is slow, and even slower on win32 where we
7153 # have to invoke it for only about 30 paths at a time
7155 if {[tk windowingsystem] == "win32"} {
7159 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7160 set i [string first "\t" $line]
7162 set file [string range $line [expr {$i+1}] end]
7163 if {[string index $file 0] eq "\""} {
7164 set file [lindex $file 0]
7166 set file [encoding convertfrom $file]
7167 if {$file ne [lindex $treediff end]} {
7168 lappend treediff $file
7169 lappend sublist $file
7173 if {$perfile_attrs} {
7174 cache_gitattr encoding $sublist
7177 return [expr {$nr >= $max? 2: 1}]
7180 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7182 foreach f $treediff {
7183 if {[path_filter $vfilelimit($curview) $f]} {
7187 set treediffs($ids) $flist
7189 set treediffs($ids) $treediff
7192 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7194 } elseif {$ids != $diffids} {
7195 if {![info exists diffmergeid]} {
7196 gettreediffs $diffids
7204 # empty string or positive integer
7205 proc diffcontextvalidate {v} {
7206 return [regexp {^(|[1-9][0-9]*)$} $v]
7209 proc diffcontextchange {n1 n2 op} {
7210 global diffcontextstring diffcontext
7212 if {[string is integer -strict $diffcontextstring]} {
7213 if {$diffcontextstring > 0} {
7214 set diffcontext $diffcontextstring
7220 proc changeignorespace {} {
7224 proc getblobdiffs {ids} {
7225 global blobdifffd diffids env
7226 global diffinhdr treediffs
7229 global limitdiffs vfilelimit curview
7230 global diffencoding targetline diffnparents
7232 set cmd [diffcmd $ids "-p -C --cc --no-commit-id -U$diffcontext"]
7236 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7237 set cmd [concat $cmd -- $vfilelimit($curview)]
7239 if {[catch {set bdf [open $cmd r]} err]} {
7240 error_popup [mc "Error getting diffs: %s" $err]
7246 set diffencoding [get_path_encoding {}]
7247 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7248 set blobdifffd($ids) $bdf
7249 filerun $bdf [list getblobdiffline $bdf $diffids]
7252 proc setinlist {var i val} {
7255 while {[llength [set $var]] < $i} {
7258 if {[llength [set $var]] == $i} {
7265 proc makediffhdr {fname ids} {
7266 global ctext curdiffstart treediffs diffencoding
7267 global ctext_file_names jump_to_here targetline diffline
7269 set fname [encoding convertfrom $fname]
7270 set diffencoding [get_path_encoding $fname]
7271 set i [lsearch -exact $treediffs($ids) $fname]
7273 setinlist difffilestart $i $curdiffstart
7275 lset ctext_file_names end $fname
7276 set l [expr {(78 - [string length $fname]) / 2}]
7277 set pad [string range "----------------------------------------" 1 $l]
7278 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7280 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7281 set targetline [lindex $jump_to_here 1]
7286 proc getblobdiffline {bdf ids} {
7287 global diffids blobdifffd ctext curdiffstart
7288 global diffnexthead diffnextnote difffilestart
7289 global ctext_file_names ctext_file_lines
7290 global diffinhdr treediffs mergemax diffnparents
7291 global diffencoding jump_to_here targetline diffline
7294 $ctext conf -state normal
7295 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7296 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7300 if {![string compare -length 5 "diff " $line]} {
7301 if {![regexp {^diff (--cc|--git) } $line m type]} {
7302 set line [encoding convertfrom $line]
7303 $ctext insert end "$line\n" hunksep
7306 # start of a new file
7308 $ctext insert end "\n"
7309 set curdiffstart [$ctext index "end - 1c"]
7310 lappend ctext_file_names ""
7311 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7312 $ctext insert end "\n" filesep
7314 if {$type eq "--cc"} {
7315 # start of a new file in a merge diff
7316 set fname [string range $line 10 end]
7317 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7318 lappend treediffs($ids) $fname
7319 add_flist [list $fname]
7323 set line [string range $line 11 end]
7324 # If the name hasn't changed the length will be odd,
7325 # the middle char will be a space, and the two bits either
7326 # side will be a/name and b/name, or "a/name" and "b/name".
7327 # If the name has changed we'll get "rename from" and
7328 # "rename to" or "copy from" and "copy to" lines following
7329 # this, and we'll use them to get the filenames.
7330 # This complexity is necessary because spaces in the
7331 # filename(s) don't get escaped.
7332 set l [string length $line]
7333 set i [expr {$l / 2}]
7334 if {!(($l & 1) && [string index $line $i] eq " " &&
7335 [string range $line 2 [expr {$i - 1}]] eq \
7336 [string range $line [expr {$i + 3}] end])} {
7339 # unescape if quoted and chop off the a/ from the front
7340 if {[string index $line 0] eq "\""} {
7341 set fname [string range [lindex $line 0] 2 end]
7343 set fname [string range $line 2 [expr {$i - 1}]]
7346 makediffhdr $fname $ids
7348 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7349 set fname [encoding convertfrom [string range $line 16 end]]
7350 $ctext insert end "\n"
7351 set curdiffstart [$ctext index "end - 1c"]
7352 lappend ctext_file_names $fname
7353 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7354 $ctext insert end "$line\n" filesep
7355 set i [lsearch -exact $treediffs($ids) $fname]
7357 setinlist difffilestart $i $curdiffstart
7360 } elseif {![string compare -length 2 "@@" $line]} {
7361 regexp {^@@+} $line ats
7362 set line [encoding convertfrom $diffencoding $line]
7363 $ctext insert end "$line\n" hunksep
7364 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7367 set diffnparents [expr {[string length $ats] - 1}]
7370 } elseif {$diffinhdr} {
7371 if {![string compare -length 12 "rename from " $line]} {
7372 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7373 if {[string index $fname 0] eq "\""} {
7374 set fname [lindex $fname 0]
7376 set fname [encoding convertfrom $fname]
7377 set i [lsearch -exact $treediffs($ids) $fname]
7379 setinlist difffilestart $i $curdiffstart
7381 } elseif {![string compare -length 10 $line "rename to "] ||
7382 ![string compare -length 8 $line "copy to "]} {
7383 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7384 if {[string index $fname 0] eq "\""} {
7385 set fname [lindex $fname 0]
7387 makediffhdr $fname $ids
7388 } elseif {[string compare -length 3 $line "---"] == 0} {
7391 } elseif {[string compare -length 3 $line "+++"] == 0} {
7395 $ctext insert end "$line\n" filesep
7398 set line [string map {\x1A ^Z} \
7399 [encoding convertfrom $diffencoding $line]]
7400 # parse the prefix - one ' ', '-' or '+' for each parent
7401 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7402 set tag [expr {$diffnparents > 1? "m": "d"}]
7403 if {[string trim $prefix " -+"] eq {}} {
7404 # prefix only has " ", "-" and "+" in it: normal diff line
7405 set num [string first "-" $prefix]
7407 # removed line, first parent with line is $num
7408 if {$num >= $mergemax} {
7411 $ctext insert end "$line\n" $tag$num
7414 if {[string first "+" $prefix] >= 0} {
7416 lappend tags ${tag}result
7417 if {$diffnparents > 1} {
7418 set num [string first " " $prefix]
7420 if {$num >= $mergemax} {
7427 if {$targetline ne {}} {
7428 if {$diffline == $targetline} {
7429 set seehere [$ctext index "end - 1 chars"]
7435 $ctext insert end "$line\n" $tags
7438 # "\ No newline at end of file",
7439 # or something else we don't recognize
7440 $ctext insert end "$line\n" hunksep
7444 if {[info exists seehere]} {
7445 mark_ctext_line [lindex [split $seehere .] 0]
7447 $ctext conf -state disabled
7452 return [expr {$nr >= 1000? 2: 1}]
7455 proc changediffdisp {} {
7456 global ctext diffelide
7458 $ctext tag conf d0 -elide [lindex $diffelide 0]
7459 $ctext tag conf dresult -elide [lindex $diffelide 1]
7462 proc highlightfile {loc cline} {
7463 global ctext cflist cflist_top
7466 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
7467 $cflist tag add highlight $cline.0 "$cline.0 lineend"
7468 $cflist see $cline.0
7469 set cflist_top $cline
7473 global difffilestart ctext cmitmode
7475 if {$cmitmode eq "tree"} return
7478 set here [$ctext index @0,0]
7479 foreach loc $difffilestart {
7480 if {[$ctext compare $loc >= $here]} {
7481 highlightfile $prev $prevline
7487 highlightfile $prev $prevline
7491 global difffilestart ctext cmitmode
7493 if {$cmitmode eq "tree"} return
7494 set here [$ctext index @0,0]
7496 foreach loc $difffilestart {
7498 if {[$ctext compare $loc > $here]} {
7499 highlightfile $loc $line
7505 proc clear_ctext {{first 1.0}} {
7506 global ctext smarktop smarkbot
7507 global ctext_file_names ctext_file_lines
7510 set l [lindex [split $first .] 0]
7511 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
7514 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
7517 $ctext delete $first end
7518 if {$first eq "1.0"} {
7519 catch {unset pendinglinks}
7521 set ctext_file_names {}
7522 set ctext_file_lines {}
7525 proc settabs {{firstab {}}} {
7526 global firsttabstop tabstop ctext have_tk85
7528 if {$firstab ne {} && $have_tk85} {
7529 set firsttabstop $firstab
7531 set w [font measure textfont "0"]
7532 if {$firsttabstop != 0} {
7533 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
7534 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
7535 } elseif {$have_tk85 || $tabstop != 8} {
7536 $ctext conf -tabs [expr {$tabstop * $w}]
7538 $ctext conf -tabs {}
7542 proc incrsearch {name ix op} {
7543 global ctext searchstring searchdirn
7545 $ctext tag remove found 1.0 end
7546 if {[catch {$ctext index anchor}]} {
7547 # no anchor set, use start of selection, or of visible area
7548 set sel [$ctext tag ranges sel]
7550 $ctext mark set anchor [lindex $sel 0]
7551 } elseif {$searchdirn eq "-forwards"} {
7552 $ctext mark set anchor @0,0
7554 $ctext mark set anchor @0,[winfo height $ctext]
7557 if {$searchstring ne {}} {
7558 set here [$ctext search $searchdirn -- $searchstring anchor]
7567 global sstring ctext searchstring searchdirn
7570 $sstring icursor end
7571 set searchdirn -forwards
7572 if {$searchstring ne {}} {
7573 set sel [$ctext tag ranges sel]
7575 set start "[lindex $sel 0] + 1c"
7576 } elseif {[catch {set start [$ctext index anchor]}]} {
7579 set match [$ctext search -count mlen -- $searchstring $start]
7580 $ctext tag remove sel 1.0 end
7586 set mend "$match + $mlen c"
7587 $ctext tag add sel $match $mend
7588 $ctext mark unset anchor
7592 proc dosearchback {} {
7593 global sstring ctext searchstring searchdirn
7596 $sstring icursor end
7597 set searchdirn -backwards
7598 if {$searchstring ne {}} {
7599 set sel [$ctext tag ranges sel]
7601 set start [lindex $sel 0]
7602 } elseif {[catch {set start [$ctext index anchor]}]} {
7603 set start @0,[winfo height $ctext]
7605 set match [$ctext search -backwards -count ml -- $searchstring $start]
7606 $ctext tag remove sel 1.0 end
7612 set mend "$match + $ml c"
7613 $ctext tag add sel $match $mend
7614 $ctext mark unset anchor
7618 proc searchmark {first last} {
7619 global ctext searchstring
7623 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
7624 if {$match eq {}} break
7625 set mend "$match + $mlen c"
7626 $ctext tag add found $match $mend
7630 proc searchmarkvisible {doall} {
7631 global ctext smarktop smarkbot
7633 set topline [lindex [split [$ctext index @0,0] .] 0]
7634 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
7635 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
7636 # no overlap with previous
7637 searchmark $topline $botline
7638 set smarktop $topline
7639 set smarkbot $botline
7641 if {$topline < $smarktop} {
7642 searchmark $topline [expr {$smarktop-1}]
7643 set smarktop $topline
7645 if {$botline > $smarkbot} {
7646 searchmark [expr {$smarkbot+1}] $botline
7647 set smarkbot $botline
7652 proc scrolltext {f0 f1} {
7655 .bleft.bottom.sb set $f0 $f1
7656 if {$searchstring ne {}} {
7662 global linespc charspc canvx0 canvy0
7663 global xspc1 xspc2 lthickness
7665 set linespc [font metrics mainfont -linespace]
7666 set charspc [font measure mainfont "m"]
7667 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
7668 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
7669 set lthickness [expr {int($linespc / 9) + 1}]
7670 set xspc1(0) $linespc
7678 set ymax [lindex [$canv cget -scrollregion] 3]
7679 if {$ymax eq {} || $ymax == 0} return
7680 set span [$canv yview]
7683 allcanvs yview moveto [lindex $span 0]
7685 if {$selectedline ne {}} {
7686 selectline $selectedline 0
7687 allcanvs yview moveto [lindex $span 0]
7691 proc parsefont {f n} {
7694 set fontattr($f,family) [lindex $n 0]
7696 if {$s eq {} || $s == 0} {
7699 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
7701 set fontattr($f,size) $s
7702 set fontattr($f,weight) normal
7703 set fontattr($f,slant) roman
7704 foreach style [lrange $n 2 end] {
7707 "bold" {set fontattr($f,weight) $style}
7709 "italic" {set fontattr($f,slant) $style}
7714 proc fontflags {f {isbold 0}} {
7717 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
7718 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
7719 -slant $fontattr($f,slant)]
7725 set n [list $fontattr($f,family) $fontattr($f,size)]
7726 if {$fontattr($f,weight) eq "bold"} {
7729 if {$fontattr($f,slant) eq "italic"} {
7735 proc incrfont {inc} {
7736 global mainfont textfont ctext canv cflist showrefstop
7737 global stopped entries fontattr
7740 set s $fontattr(mainfont,size)
7745 set fontattr(mainfont,size) $s
7746 font config mainfont -size $s
7747 font config mainfontbold -size $s
7748 set mainfont [fontname mainfont]
7749 set s $fontattr(textfont,size)
7754 set fontattr(textfont,size) $s
7755 font config textfont -size $s
7756 font config textfontbold -size $s
7757 set textfont [fontname textfont]
7764 global sha1entry sha1string
7765 if {[string length $sha1string] == 40} {
7766 $sha1entry delete 0 end
7770 proc sha1change {n1 n2 op} {
7771 global sha1string currentid sha1but
7772 if {$sha1string == {}
7773 || ([info exists currentid] && $sha1string == $currentid)} {
7778 if {[$sha1but cget -state] == $state} return
7779 if {$state == "normal"} {
7780 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
7782 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
7786 proc gotocommit {} {
7787 global sha1string tagids headids curview varcid
7789 if {$sha1string == {}
7790 || ([info exists currentid] && $sha1string == $currentid)} return
7791 if {[info exists tagids($sha1string)]} {
7792 set id $tagids($sha1string)
7793 } elseif {[info exists headids($sha1string)]} {
7794 set id $headids($sha1string)
7796 set id [string tolower $sha1string]
7797 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
7798 set matches [longid $id]
7799 if {$matches ne {}} {
7800 if {[llength $matches] > 1} {
7801 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
7804 set id [lindex $matches 0]
7808 if {[commitinview $id $curview]} {
7809 selectline [rowofcommit $id] 1
7812 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
7813 set msg [mc "SHA1 id %s is not known" $sha1string]
7815 set msg [mc "Tag/Head %s is not known" $sha1string]
7820 proc lineenter {x y id} {
7821 global hoverx hovery hoverid hovertimer
7822 global commitinfo canv
7824 if {![info exists commitinfo($id)] && ![getcommit $id]} return
7828 if {[info exists hovertimer]} {
7829 after cancel $hovertimer
7831 set hovertimer [after 500 linehover]
7835 proc linemotion {x y id} {
7836 global hoverx hovery hoverid hovertimer
7838 if {[info exists hoverid] && $id == $hoverid} {
7841 if {[info exists hovertimer]} {
7842 after cancel $hovertimer
7844 set hovertimer [after 500 linehover]
7848 proc lineleave {id} {
7849 global hoverid hovertimer canv
7851 if {[info exists hoverid] && $id == $hoverid} {
7853 if {[info exists hovertimer]} {
7854 after cancel $hovertimer
7862 global hoverx hovery hoverid hovertimer
7863 global canv linespc lthickness
7866 set text [lindex $commitinfo($hoverid) 0]
7867 set ymax [lindex [$canv cget -scrollregion] 3]
7868 if {$ymax == {}} return
7869 set yfrac [lindex [$canv yview] 0]
7870 set x [expr {$hoverx + 2 * $linespc}]
7871 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
7872 set x0 [expr {$x - 2 * $lthickness}]
7873 set y0 [expr {$y - 2 * $lthickness}]
7874 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
7875 set y1 [expr {$y + $linespc + 2 * $lthickness}]
7876 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
7877 -fill \#ffff80 -outline black -width 1 -tags hover]
7879 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
7884 proc clickisonarrow {id y} {
7887 set ranges [rowranges $id]
7888 set thresh [expr {2 * $lthickness + 6}]
7889 set n [expr {[llength $ranges] - 1}]
7890 for {set i 1} {$i < $n} {incr i} {
7891 set row [lindex $ranges $i]
7892 if {abs([yc $row] - $y) < $thresh} {
7899 proc arrowjump {id n y} {
7902 # 1 <-> 2, 3 <-> 4, etc...
7903 set n [expr {(($n - 1) ^ 1) + 1}]
7904 set row [lindex [rowranges $id] $n]
7906 set ymax [lindex [$canv cget -scrollregion] 3]
7907 if {$ymax eq {} || $ymax <= 0} return
7908 set view [$canv yview]
7909 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
7910 set yfrac [expr {$yt / $ymax - $yspan / 2}]
7914 allcanvs yview moveto $yfrac
7917 proc lineclick {x y id isnew} {
7918 global ctext commitinfo children canv thickerline curview
7920 if {![info exists commitinfo($id)] && ![getcommit $id]} return
7925 # draw this line thicker than normal
7929 set ymax [lindex [$canv cget -scrollregion] 3]
7930 if {$ymax eq {}} return
7931 set yfrac [lindex [$canv yview] 0]
7932 set y [expr {$y + $yfrac * $ymax}]
7934 set dirn [clickisonarrow $id $y]
7936 arrowjump $id $dirn $y
7941 addtohistory [list lineclick $x $y $id 0]
7943 # fill the details pane with info about this line
7944 $ctext conf -state normal
7947 $ctext insert end "[mc "Parent"]:\t"
7948 $ctext insert end $id link0
7950 set info $commitinfo($id)
7951 $ctext insert end "\n\t[lindex $info 0]\n"
7952 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
7953 set date [formatdate [lindex $info 2]]
7954 $ctext insert end "\t[mc "Date"]:\t$date\n"
7955 set kids $children($curview,$id)
7957 $ctext insert end "\n[mc "Children"]:"
7959 foreach child $kids {
7961 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
7962 set info $commitinfo($child)
7963 $ctext insert end "\n\t"
7964 $ctext insert end $child link$i
7965 setlink $child link$i
7966 $ctext insert end "\n\t[lindex $info 0]"
7967 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
7968 set date [formatdate [lindex $info 2]]
7969 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
7972 $ctext conf -state disabled
7976 proc normalline {} {
7978 if {[info exists thickerline]} {
7987 if {[commitinview $id $curview]} {
7988 selectline [rowofcommit $id] 1
7994 if {![info exists startmstime]} {
7995 set startmstime [clock clicks -milliseconds]
7997 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8000 proc rowmenu {x y id} {
8001 global rowctxmenu selectedline rowmenuid curview
8002 global nullid nullid2 fakerowmenu mainhead
8006 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8011 if {$id ne $nullid && $id ne $nullid2} {
8012 set menu $rowctxmenu
8013 if {$mainhead ne {}} {
8014 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8016 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8019 set menu $fakerowmenu
8021 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8022 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8023 $menu entryconfigure [mca "Make patch"] -state $state
8024 tk_popup $menu $x $y
8027 proc diffvssel {dirn} {
8028 global rowmenuid selectedline
8030 if {$selectedline eq {}} return
8032 set oldid [commitonrow $selectedline]
8033 set newid $rowmenuid
8035 set oldid $rowmenuid
8036 set newid [commitonrow $selectedline]
8038 addtohistory [list doseldiff $oldid $newid]
8039 doseldiff $oldid $newid
8042 proc doseldiff {oldid newid} {
8046 $ctext conf -state normal
8048 init_flist [mc "Top"]
8049 $ctext insert end "[mc "From"] "
8050 $ctext insert end $oldid link0
8051 setlink $oldid link0
8052 $ctext insert end "\n "
8053 $ctext insert end [lindex $commitinfo($oldid) 0]
8054 $ctext insert end "\n\n[mc "To"] "
8055 $ctext insert end $newid link1
8056 setlink $newid link1
8057 $ctext insert end "\n "
8058 $ctext insert end [lindex $commitinfo($newid) 0]
8059 $ctext insert end "\n"
8060 $ctext conf -state disabled
8061 $ctext tag remove found 1.0 end
8062 startdiff [list $oldid $newid]
8066 global rowmenuid currentid commitinfo patchtop patchnum
8068 if {![info exists currentid]} return
8069 set oldid $currentid
8070 set oldhead [lindex $commitinfo($oldid) 0]
8071 set newid $rowmenuid
8072 set newhead [lindex $commitinfo($newid) 0]
8075 catch {destroy $top}
8077 make_transient $top .
8078 label $top.title -text [mc "Generate patch"]
8079 grid $top.title - -pady 10
8080 label $top.from -text [mc "From:"]
8081 entry $top.fromsha1 -width 40 -relief flat
8082 $top.fromsha1 insert 0 $oldid
8083 $top.fromsha1 conf -state readonly
8084 grid $top.from $top.fromsha1 -sticky w
8085 entry $top.fromhead -width 60 -relief flat
8086 $top.fromhead insert 0 $oldhead
8087 $top.fromhead conf -state readonly
8088 grid x $top.fromhead -sticky w
8089 label $top.to -text [mc "To:"]
8090 entry $top.tosha1 -width 40 -relief flat
8091 $top.tosha1 insert 0 $newid
8092 $top.tosha1 conf -state readonly
8093 grid $top.to $top.tosha1 -sticky w
8094 entry $top.tohead -width 60 -relief flat
8095 $top.tohead insert 0 $newhead
8096 $top.tohead conf -state readonly
8097 grid x $top.tohead -sticky w
8098 button $top.rev -text [mc "Reverse"] -command mkpatchrev -padx 5
8099 grid $top.rev x -pady 10
8100 label $top.flab -text [mc "Output file:"]
8101 entry $top.fname -width 60
8102 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
8104 grid $top.flab $top.fname -sticky w
8106 button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
8107 button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
8108 bind $top <Key-Return> mkpatchgo
8109 bind $top <Key-Escape> mkpatchcan
8110 grid $top.buts.gen $top.buts.can
8111 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8112 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8113 grid $top.buts - -pady 10 -sticky ew
8117 proc mkpatchrev {} {
8120 set oldid [$patchtop.fromsha1 get]
8121 set oldhead [$patchtop.fromhead get]
8122 set newid [$patchtop.tosha1 get]
8123 set newhead [$patchtop.tohead get]
8124 foreach e [list fromsha1 fromhead tosha1 tohead] \
8125 v [list $newid $newhead $oldid $oldhead] {
8126 $patchtop.$e conf -state normal
8127 $patchtop.$e delete 0 end
8128 $patchtop.$e insert 0 $v
8129 $patchtop.$e conf -state readonly
8134 global patchtop nullid nullid2
8136 set oldid [$patchtop.fromsha1 get]
8137 set newid [$patchtop.tosha1 get]
8138 set fname [$patchtop.fname get]
8139 set cmd [diffcmd [list $oldid $newid] -p]
8140 # trim off the initial "|"
8141 set cmd [lrange $cmd 1 end]
8142 lappend cmd >$fname &
8143 if {[catch {eval exec $cmd} err]} {
8144 error_popup "[mc "Error creating patch:"] $err" $patchtop
8146 catch {destroy $patchtop}
8150 proc mkpatchcan {} {
8153 catch {destroy $patchtop}
8158 global rowmenuid mktagtop commitinfo
8162 catch {destroy $top}
8164 make_transient $top .
8165 label $top.title -text [mc "Create tag"]
8166 grid $top.title - -pady 10
8167 label $top.id -text [mc "ID:"]
8168 entry $top.sha1 -width 40 -relief flat
8169 $top.sha1 insert 0 $rowmenuid
8170 $top.sha1 conf -state readonly
8171 grid $top.id $top.sha1 -sticky w
8172 entry $top.head -width 60 -relief flat
8173 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8174 $top.head conf -state readonly
8175 grid x $top.head -sticky w
8176 label $top.tlab -text [mc "Tag name:"]
8177 entry $top.tag -width 60
8178 grid $top.tlab $top.tag -sticky w
8180 button $top.buts.gen -text [mc "Create"] -command mktaggo
8181 button $top.buts.can -text [mc "Cancel"] -command mktagcan
8182 bind $top <Key-Return> mktaggo
8183 bind $top <Key-Escape> mktagcan
8184 grid $top.buts.gen $top.buts.can
8185 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8186 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8187 grid $top.buts - -pady 10 -sticky ew
8192 global mktagtop env tagids idtags
8194 set id [$mktagtop.sha1 get]
8195 set tag [$mktagtop.tag get]
8197 error_popup [mc "No tag name specified"] $mktagtop
8200 if {[info exists tagids($tag)]} {
8201 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
8205 exec git tag $tag $id
8207 error_popup "[mc "Error creating tag:"] $err" $mktagtop
8211 set tagids($tag) $id
8212 lappend idtags($id) $tag
8220 proc redrawtags {id} {
8221 global canv linehtag idpos currentid curview cmitlisted
8222 global canvxmax iddrawn circleitem mainheadid circlecolors
8224 if {![commitinview $id $curview]} return
8225 if {![info exists iddrawn($id)]} return
8226 set row [rowofcommit $id]
8227 if {$id eq $mainheadid} {
8230 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
8232 $canv itemconf $circleitem($row) -fill $ofill
8233 $canv delete tag.$id
8234 set xt [eval drawtags $id $idpos($id)]
8235 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
8236 set text [$canv itemcget $linehtag($id) -text]
8237 set font [$canv itemcget $linehtag($id) -font]
8238 set xr [expr {$xt + [font measure $font $text]}]
8239 if {$xr > $canvxmax} {
8243 if {[info exists currentid] && $currentid == $id} {
8251 catch {destroy $mktagtop}
8256 if {![domktag]} return
8260 proc writecommit {} {
8261 global rowmenuid wrcomtop commitinfo wrcomcmd
8263 set top .writecommit
8265 catch {destroy $top}
8267 make_transient $top .
8268 label $top.title -text [mc "Write commit to file"]
8269 grid $top.title - -pady 10
8270 label $top.id -text [mc "ID:"]
8271 entry $top.sha1 -width 40 -relief flat
8272 $top.sha1 insert 0 $rowmenuid
8273 $top.sha1 conf -state readonly
8274 grid $top.id $top.sha1 -sticky w
8275 entry $top.head -width 60 -relief flat
8276 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8277 $top.head conf -state readonly
8278 grid x $top.head -sticky w
8279 label $top.clab -text [mc "Command:"]
8280 entry $top.cmd -width 60 -textvariable wrcomcmd
8281 grid $top.clab $top.cmd -sticky w -pady 10
8282 label $top.flab -text [mc "Output file:"]
8283 entry $top.fname -width 60
8284 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
8285 grid $top.flab $top.fname -sticky w
8287 button $top.buts.gen -text [mc "Write"] -command wrcomgo
8288 button $top.buts.can -text [mc "Cancel"] -command wrcomcan
8289 bind $top <Key-Return> wrcomgo
8290 bind $top <Key-Escape> wrcomcan
8291 grid $top.buts.gen $top.buts.can
8292 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8293 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8294 grid $top.buts - -pady 10 -sticky ew
8301 set id [$wrcomtop.sha1 get]
8302 set cmd "echo $id | [$wrcomtop.cmd get]"
8303 set fname [$wrcomtop.fname get]
8304 if {[catch {exec sh -c $cmd >$fname &} err]} {
8305 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
8307 catch {destroy $wrcomtop}
8314 catch {destroy $wrcomtop}
8319 global rowmenuid mkbrtop
8322 catch {destroy $top}
8324 make_transient $top .
8325 label $top.title -text [mc "Create new branch"]
8326 grid $top.title - -pady 10
8327 label $top.id -text [mc "ID:"]
8328 entry $top.sha1 -width 40 -relief flat
8329 $top.sha1 insert 0 $rowmenuid
8330 $top.sha1 conf -state readonly
8331 grid $top.id $top.sha1 -sticky w
8332 label $top.nlab -text [mc "Name:"]
8333 entry $top.name -width 40
8334 grid $top.nlab $top.name -sticky w
8336 button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
8337 button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
8338 bind $top <Key-Return> [list mkbrgo $top]
8339 bind $top <Key-Escape> "catch {destroy $top}"
8340 grid $top.buts.go $top.buts.can
8341 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8342 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8343 grid $top.buts - -pady 10 -sticky ew
8348 global headids idheads
8350 set name [$top.name get]
8351 set id [$top.sha1 get]
8355 error_popup [mc "Please specify a name for the new branch"] $top
8358 if {[info exists headids($name)]} {
8359 if {![confirm_popup [mc \
8360 "Branch '%s' already exists. Overwrite?" $name] $top]} {
8363 set old_id $headids($name)
8366 catch {destroy $top}
8367 lappend cmdargs $name $id
8371 eval exec git branch $cmdargs
8377 if {$old_id ne {}} {
8383 set headids($name) $id
8384 lappend idheads($id) $name
8393 proc exec_citool {tool_args {baseid {}}} {
8394 global commitinfo env
8396 set save_env [array get env GIT_AUTHOR_*]
8398 if {$baseid ne {}} {
8399 if {![info exists commitinfo($baseid)]} {
8402 set author [lindex $commitinfo($baseid) 1]
8403 set date [lindex $commitinfo($baseid) 2]
8404 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
8405 $author author name email]
8407 set env(GIT_AUTHOR_NAME) $name
8408 set env(GIT_AUTHOR_EMAIL) $email
8409 set env(GIT_AUTHOR_DATE) $date
8413 eval exec git citool $tool_args &
8415 array unset env GIT_AUTHOR_*
8416 array set env $save_env
8419 proc cherrypick {} {
8420 global rowmenuid curview
8421 global mainhead mainheadid
8423 set oldhead [exec git rev-parse HEAD]
8424 set dheads [descheads $rowmenuid]
8425 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
8426 set ok [confirm_popup [mc "Commit %s is already\
8427 included in branch %s -- really re-apply it?" \
8428 [string range $rowmenuid 0 7] $mainhead]]
8431 nowbusy cherrypick [mc "Cherry-picking"]
8433 # Unfortunately git-cherry-pick writes stuff to stderr even when
8434 # no error occurs, and exec takes that as an indication of error...
8435 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
8438 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
8440 error_popup [mc "Cherry-pick failed because of local changes\
8441 to file '%s'.\nPlease commit, reset or stash\
8442 your changes and try again." $fname]
8443 } elseif {[regexp -line \
8444 {^(CONFLICT \(.*\):|Automatic cherry-pick failed)} \
8446 if {[confirm_popup [mc "Cherry-pick failed because of merge\
8447 conflict.\nDo you wish to run git citool to\
8449 # Force citool to read MERGE_MSG
8450 file delete [file join [gitdir] "GITGUI_MSG"]
8451 exec_citool {} $rowmenuid
8459 set newhead [exec git rev-parse HEAD]
8460 if {$newhead eq $oldhead} {
8462 error_popup [mc "No changes committed"]
8465 addnewchild $newhead $oldhead
8466 if {[commitinview $oldhead $curview]} {
8467 # XXX this isn't right if we have a path limit...
8468 insertrow $newhead $oldhead $curview
8469 if {$mainhead ne {}} {
8470 movehead $newhead $mainhead
8471 movedhead $newhead $mainhead
8473 set mainheadid $newhead
8482 global mainhead rowmenuid confirm_ok resettype
8485 set w ".confirmreset"
8488 wm title $w [mc "Confirm reset"]
8489 message $w.m -text \
8490 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]] \
8491 -justify center -aspect 1000
8492 pack $w.m -side top -fill x -padx 20 -pady 20
8493 frame $w.f -relief sunken -border 2
8494 message $w.f.rt -text [mc "Reset type:"] -aspect 1000
8495 grid $w.f.rt -sticky w
8497 radiobutton $w.f.soft -value soft -variable resettype -justify left \
8498 -text [mc "Soft: Leave working tree and index untouched"]
8499 grid $w.f.soft -sticky w
8500 radiobutton $w.f.mixed -value mixed -variable resettype -justify left \
8501 -text [mc "Mixed: Leave working tree untouched, reset index"]
8502 grid $w.f.mixed -sticky w
8503 radiobutton $w.f.hard -value hard -variable resettype -justify left \
8504 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
8505 grid $w.f.hard -sticky w
8506 pack $w.f -side top -fill x
8507 button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
8508 pack $w.ok -side left -fill x -padx 20 -pady 20
8509 button $w.cancel -text [mc Cancel] -command "destroy $w"
8510 bind $w <Key-Escape> [list destroy $w]
8511 pack $w.cancel -side right -fill x -padx 20 -pady 20
8512 bind $w <Visibility> "grab $w; focus $w"
8514 if {!$confirm_ok} return
8515 if {[catch {set fd [open \
8516 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
8520 filerun $fd [list readresetstat $fd]
8521 nowbusy reset [mc "Resetting"]
8526 proc readresetstat {fd} {
8527 global mainhead mainheadid showlocalchanges rprogcoord
8529 if {[gets $fd line] >= 0} {
8530 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
8531 set rprogcoord [expr {1.0 * $m / $n}]
8539 if {[catch {close $fd} err]} {
8542 set oldhead $mainheadid
8543 set newhead [exec git rev-parse HEAD]
8544 if {$newhead ne $oldhead} {
8545 movehead $newhead $mainhead
8546 movedhead $newhead $mainhead
8547 set mainheadid $newhead
8551 if {$showlocalchanges} {
8557 # context menu for a head
8558 proc headmenu {x y id head} {
8559 global headmenuid headmenuhead headctxmenu mainhead
8563 set headmenuhead $head
8565 if {$head eq $mainhead} {
8568 $headctxmenu entryconfigure 0 -state $state
8569 $headctxmenu entryconfigure 1 -state $state
8570 tk_popup $headctxmenu $x $y
8574 global headmenuid headmenuhead headids
8575 global showlocalchanges
8577 # check the tree is clean first??
8578 nowbusy checkout [mc "Checking out"]
8582 set fd [open [list | git checkout $headmenuhead 2>@1] r]
8586 if {$showlocalchanges} {
8590 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
8594 proc readcheckoutstat {fd newhead newheadid} {
8595 global mainhead mainheadid headids showlocalchanges progresscoords
8596 global viewmainheadid curview
8598 if {[gets $fd line] >= 0} {
8599 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
8600 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
8605 set progresscoords {0 0}
8608 if {[catch {close $fd} err]} {
8611 set oldmainid $mainheadid
8612 set mainhead $newhead
8613 set mainheadid $newheadid
8614 set viewmainheadid($curview) $newheadid
8615 redrawtags $oldmainid
8616 redrawtags $newheadid
8618 if {$showlocalchanges} {
8624 global headmenuid headmenuhead mainhead
8627 set head $headmenuhead
8629 # this check shouldn't be needed any more...
8630 if {$head eq $mainhead} {
8631 error_popup [mc "Cannot delete the currently checked-out branch"]
8634 set dheads [descheads $id]
8635 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
8636 # the stuff on this branch isn't on any other branch
8637 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
8638 branch.\nReally delete branch %s?" $head $head]]} return
8642 if {[catch {exec git branch -D $head} err]} {
8647 removehead $id $head
8648 removedhead $id $head
8655 # Display a list of tags and heads
8657 global showrefstop bgcolor fgcolor selectbgcolor
8658 global bglist fglist reflistfilter reflist maincursor
8661 set showrefstop $top
8662 if {[winfo exists $top]} {
8668 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
8669 make_transient $top .
8670 text $top.list -background $bgcolor -foreground $fgcolor \
8671 -selectbackground $selectbgcolor -font mainfont \
8672 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
8673 -width 30 -height 20 -cursor $maincursor \
8674 -spacing1 1 -spacing3 1 -state disabled
8675 $top.list tag configure highlight -background $selectbgcolor
8676 lappend bglist $top.list
8677 lappend fglist $top.list
8678 scrollbar $top.ysb -command "$top.list yview" -orient vertical
8679 scrollbar $top.xsb -command "$top.list xview" -orient horizontal
8680 grid $top.list $top.ysb -sticky nsew
8681 grid $top.xsb x -sticky ew
8683 label $top.f.l -text "[mc "Filter"]: "
8684 entry $top.f.e -width 20 -textvariable reflistfilter
8685 set reflistfilter "*"
8686 trace add variable reflistfilter write reflistfilter_change
8687 pack $top.f.e -side right -fill x -expand 1
8688 pack $top.f.l -side left
8689 grid $top.f - -sticky ew -pady 2
8690 button $top.close -command [list destroy $top] -text [mc "Close"]
8691 bind $top <Key-Escape> [list destroy $top]
8693 grid columnconfigure $top 0 -weight 1
8694 grid rowconfigure $top 0 -weight 1
8695 bind $top.list <1> {break}
8696 bind $top.list <B1-Motion> {break}
8697 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
8702 proc sel_reflist {w x y} {
8703 global showrefstop reflist headids tagids otherrefids
8705 if {![winfo exists $showrefstop]} return
8706 set l [lindex [split [$w index "@$x,$y"] "."] 0]
8707 set ref [lindex $reflist [expr {$l-1}]]
8708 set n [lindex $ref 0]
8709 switch -- [lindex $ref 1] {
8710 "H" {selbyid $headids($n)}
8711 "T" {selbyid $tagids($n)}
8712 "o" {selbyid $otherrefids($n)}
8714 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
8717 proc unsel_reflist {} {
8720 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
8721 $showrefstop.list tag remove highlight 0.0 end
8724 proc reflistfilter_change {n1 n2 op} {
8725 global reflistfilter
8727 after cancel refill_reflist
8728 after 200 refill_reflist
8731 proc refill_reflist {} {
8732 global reflist reflistfilter showrefstop headids tagids otherrefids
8735 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
8737 foreach n [array names headids] {
8738 if {[string match $reflistfilter $n]} {
8739 if {[commitinview $headids($n) $curview]} {
8740 lappend refs [list $n H]
8742 interestedin $headids($n) {run refill_reflist}
8746 foreach n [array names tagids] {
8747 if {[string match $reflistfilter $n]} {
8748 if {[commitinview $tagids($n) $curview]} {
8749 lappend refs [list $n T]
8751 interestedin $tagids($n) {run refill_reflist}
8755 foreach n [array names otherrefids] {
8756 if {[string match $reflistfilter $n]} {
8757 if {[commitinview $otherrefids($n) $curview]} {
8758 lappend refs [list $n o]
8760 interestedin $otherrefids($n) {run refill_reflist}
8764 set refs [lsort -index 0 $refs]
8765 if {$refs eq $reflist} return
8767 # Update the contents of $showrefstop.list according to the
8768 # differences between $reflist (old) and $refs (new)
8769 $showrefstop.list conf -state normal
8770 $showrefstop.list insert end "\n"
8773 while {$i < [llength $reflist] || $j < [llength $refs]} {
8774 if {$i < [llength $reflist]} {
8775 if {$j < [llength $refs]} {
8776 set cmp [string compare [lindex $reflist $i 0] \
8777 [lindex $refs $j 0]]
8779 set cmp [string compare [lindex $reflist $i 1] \
8780 [lindex $refs $j 1]]
8790 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
8798 set l [expr {$j + 1}]
8799 $showrefstop.list image create $l.0 -align baseline \
8800 -image reficon-[lindex $refs $j 1] -padx 2
8801 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
8807 # delete last newline
8808 $showrefstop.list delete end-2c end-1c
8809 $showrefstop.list conf -state disabled
8812 # Stuff for finding nearby tags
8813 proc getallcommits {} {
8814 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
8815 global idheads idtags idotherrefs allparents tagobjid
8817 if {![info exists allcommits]} {
8823 set allccache [file join [gitdir] "gitk.cache"]
8825 set f [open $allccache r]
8834 set cmd [list | git rev-list --parents]
8835 set allcupdate [expr {$seeds ne {}}]
8839 set refs [concat [array names idheads] [array names idtags] \
8840 [array names idotherrefs]]
8843 foreach name [array names tagobjid] {
8844 lappend tagobjs $tagobjid($name)
8846 foreach id [lsort -unique $refs] {
8847 if {![info exists allparents($id)] &&
8848 [lsearch -exact $tagobjs $id] < 0} {
8859 set fd [open [concat $cmd $ids] r]
8860 fconfigure $fd -blocking 0
8863 filerun $fd [list getallclines $fd]
8869 # Since most commits have 1 parent and 1 child, we group strings of
8870 # such commits into "arcs" joining branch/merge points (BMPs), which
8871 # are commits that either don't have 1 parent or don't have 1 child.
8873 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
8874 # arcout(id) - outgoing arcs for BMP
8875 # arcids(a) - list of IDs on arc including end but not start
8876 # arcstart(a) - BMP ID at start of arc
8877 # arcend(a) - BMP ID at end of arc
8878 # growing(a) - arc a is still growing
8879 # arctags(a) - IDs out of arcids (excluding end) that have tags
8880 # archeads(a) - IDs out of arcids (excluding end) that have heads
8881 # The start of an arc is at the descendent end, so "incoming" means
8882 # coming from descendents, and "outgoing" means going towards ancestors.
8884 proc getallclines {fd} {
8885 global allparents allchildren idtags idheads nextarc
8886 global arcnos arcids arctags arcout arcend arcstart archeads growing
8887 global seeds allcommits cachedarcs allcupdate
8890 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
8891 set id [lindex $line 0]
8892 if {[info exists allparents($id)]} {
8897 set olds [lrange $line 1 end]
8898 set allparents($id) $olds
8899 if {![info exists allchildren($id)]} {
8900 set allchildren($id) {}
8905 if {[llength $olds] == 1 && [llength $a] == 1} {
8906 lappend arcids($a) $id
8907 if {[info exists idtags($id)]} {
8908 lappend arctags($a) $id
8910 if {[info exists idheads($id)]} {
8911 lappend archeads($a) $id
8913 if {[info exists allparents($olds)]} {
8914 # seen parent already
8915 if {![info exists arcout($olds)]} {
8918 lappend arcids($a) $olds
8919 set arcend($a) $olds
8922 lappend allchildren($olds) $id
8923 lappend arcnos($olds) $a
8927 foreach a $arcnos($id) {
8928 lappend arcids($a) $id
8935 lappend allchildren($p) $id
8936 set a [incr nextarc]
8937 set arcstart($a) $id
8944 if {[info exists allparents($p)]} {
8945 # seen it already, may need to make a new branch
8946 if {![info exists arcout($p)]} {
8949 lappend arcids($a) $p
8953 lappend arcnos($p) $a
8958 global cached_dheads cached_dtags cached_atags
8959 catch {unset cached_dheads}
8960 catch {unset cached_dtags}
8961 catch {unset cached_atags}
8964 return [expr {$nid >= 1000? 2: 1}]
8968 fconfigure $fd -blocking 1
8971 # got an error reading the list of commits
8972 # if we were updating, try rereading the whole thing again
8978 error_popup "[mc "Error reading commit topology information;\
8979 branch and preceding/following tag information\
8980 will be incomplete."]\n($err)"
8983 if {[incr allcommits -1] == 0} {
8993 proc recalcarc {a} {
8994 global arctags archeads arcids idtags idheads
8998 foreach id [lrange $arcids($a) 0 end-1] {
8999 if {[info exists idtags($id)]} {
9002 if {[info exists idheads($id)]} {
9007 set archeads($a) $ah
9011 global arcnos arcids nextarc arctags archeads idtags idheads
9012 global arcstart arcend arcout allparents growing
9015 if {[llength $a] != 1} {
9016 puts "oops splitarc called but [llength $a] arcs already"
9020 set i [lsearch -exact $arcids($a) $p]
9022 puts "oops splitarc $p not in arc $a"
9025 set na [incr nextarc]
9026 if {[info exists arcend($a)]} {
9027 set arcend($na) $arcend($a)
9029 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9030 set j [lsearch -exact $arcnos($l) $a]
9031 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9033 set tail [lrange $arcids($a) [expr {$i+1}] end]
9034 set arcids($a) [lrange $arcids($a) 0 $i]
9036 set arcstart($na) $p
9038 set arcids($na) $tail
9039 if {[info exists growing($a)]} {
9045 if {[llength $arcnos($id)] == 1} {
9048 set j [lsearch -exact $arcnos($id) $a]
9049 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
9053 # reconstruct tags and heads lists
9054 if {$arctags($a) ne {} || $archeads($a) ne {}} {
9059 set archeads($na) {}
9063 # Update things for a new commit added that is a child of one
9064 # existing commit. Used when cherry-picking.
9065 proc addnewchild {id p} {
9066 global allparents allchildren idtags nextarc
9067 global arcnos arcids arctags arcout arcend arcstart archeads growing
9068 global seeds allcommits
9070 if {![info exists allcommits] || ![info exists arcnos($p)]} return
9071 set allparents($id) [list $p]
9072 set allchildren($id) {}
9075 lappend allchildren($p) $id
9076 set a [incr nextarc]
9077 set arcstart($a) $id
9080 set arcids($a) [list $p]
9082 if {![info exists arcout($p)]} {
9085 lappend arcnos($p) $a
9086 set arcout($id) [list $a]
9089 # This implements a cache for the topology information.
9090 # The cache saves, for each arc, the start and end of the arc,
9091 # the ids on the arc, and the outgoing arcs from the end.
9092 proc readcache {f} {
9093 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
9094 global idtags idheads allparents cachedarcs possible_seeds seeds growing
9099 if {$lim - $a > 500} {
9100 set lim [expr {$a + 500}]
9104 # finish reading the cache and setting up arctags, etc.
9106 if {$line ne "1"} {error "bad final version"}
9108 foreach id [array names idtags] {
9109 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9110 [llength $allparents($id)] == 1} {
9111 set a [lindex $arcnos($id) 0]
9112 if {$arctags($a) eq {}} {
9117 foreach id [array names idheads] {
9118 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9119 [llength $allparents($id)] == 1} {
9120 set a [lindex $arcnos($id) 0]
9121 if {$archeads($a) eq {}} {
9126 foreach id [lsort -unique $possible_seeds] {
9127 if {$arcnos($id) eq {}} {
9133 while {[incr a] <= $lim} {
9135 if {[llength $line] != 3} {error "bad line"}
9136 set s [lindex $line 0]
9138 lappend arcout($s) $a
9139 if {![info exists arcnos($s)]} {
9140 lappend possible_seeds $s
9143 set e [lindex $line 1]
9148 if {![info exists arcout($e)]} {
9152 set arcids($a) [lindex $line 2]
9153 foreach id $arcids($a) {
9154 lappend allparents($s) $id
9156 lappend arcnos($id) $a
9158 if {![info exists allparents($s)]} {
9159 set allparents($s) {}
9164 set nextarc [expr {$a - 1}]
9177 global nextarc cachedarcs possible_seeds
9181 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
9182 # make sure it's an integer
9183 set cachedarcs [expr {int([lindex $line 1])}]
9184 if {$cachedarcs < 0} {error "bad number of arcs"}
9186 set possible_seeds {}
9194 proc dropcache {err} {
9195 global allcwait nextarc cachedarcs seeds
9197 #puts "dropping cache ($err)"
9198 foreach v {arcnos arcout arcids arcstart arcend growing \
9199 arctags archeads allparents allchildren} {
9210 proc writecache {f} {
9211 global cachearc cachedarcs allccache
9212 global arcstart arcend arcnos arcids arcout
9216 if {$lim - $a > 1000} {
9217 set lim [expr {$a + 1000}]
9220 while {[incr a] <= $lim} {
9221 if {[info exists arcend($a)]} {
9222 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
9224 puts $f [list $arcstart($a) {} $arcids($a)]
9229 catch {file delete $allccache}
9230 #puts "writing cache failed ($err)"
9233 set cachearc [expr {$a - 1}]
9234 if {$a > $cachedarcs} {
9243 global nextarc cachedarcs cachearc allccache
9245 if {$nextarc == $cachedarcs} return
9247 set cachedarcs $nextarc
9249 set f [open $allccache w]
9250 puts $f [list 1 $cachedarcs]
9255 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
9256 # or 0 if neither is true.
9257 proc anc_or_desc {a b} {
9258 global arcout arcstart arcend arcnos cached_isanc
9260 if {$arcnos($a) eq $arcnos($b)} {
9261 # Both are on the same arc(s); either both are the same BMP,
9262 # or if one is not a BMP, the other is also not a BMP or is
9263 # the BMP at end of the arc (and it only has 1 incoming arc).
9264 # Or both can be BMPs with no incoming arcs.
9265 if {$a eq $b || $arcnos($a) eq {}} {
9268 # assert {[llength $arcnos($a)] == 1}
9269 set arc [lindex $arcnos($a) 0]
9270 set i [lsearch -exact $arcids($arc) $a]
9271 set j [lsearch -exact $arcids($arc) $b]
9272 if {$i < 0 || $i > $j} {
9279 if {![info exists arcout($a)]} {
9280 set arc [lindex $arcnos($a) 0]
9281 if {[info exists arcend($arc)]} {
9282 set aend $arcend($arc)
9286 set a $arcstart($arc)
9290 if {![info exists arcout($b)]} {
9291 set arc [lindex $arcnos($b) 0]
9292 if {[info exists arcend($arc)]} {
9293 set bend $arcend($arc)
9297 set b $arcstart($arc)
9307 if {[info exists cached_isanc($a,$bend)]} {
9308 if {$cached_isanc($a,$bend)} {
9312 if {[info exists cached_isanc($b,$aend)]} {
9313 if {$cached_isanc($b,$aend)} {
9316 if {[info exists cached_isanc($a,$bend)]} {
9321 set todo [list $a $b]
9324 for {set i 0} {$i < [llength $todo]} {incr i} {
9325 set x [lindex $todo $i]
9326 if {$anc($x) eq {}} {
9329 foreach arc $arcnos($x) {
9330 set xd $arcstart($arc)
9332 set cached_isanc($a,$bend) 1
9333 set cached_isanc($b,$aend) 0
9335 } elseif {$xd eq $aend} {
9336 set cached_isanc($b,$aend) 1
9337 set cached_isanc($a,$bend) 0
9340 if {![info exists anc($xd)]} {
9341 set anc($xd) $anc($x)
9343 } elseif {$anc($xd) ne $anc($x)} {
9348 set cached_isanc($a,$bend) 0
9349 set cached_isanc($b,$aend) 0
9353 # This identifies whether $desc has an ancestor that is
9354 # a growing tip of the graph and which is not an ancestor of $anc
9355 # and returns 0 if so and 1 if not.
9356 # If we subsequently discover a tag on such a growing tip, and that
9357 # turns out to be a descendent of $anc (which it could, since we
9358 # don't necessarily see children before parents), then $desc
9359 # isn't a good choice to display as a descendent tag of
9360 # $anc (since it is the descendent of another tag which is
9361 # a descendent of $anc). Similarly, $anc isn't a good choice to
9362 # display as a ancestor tag of $desc.
9364 proc is_certain {desc anc} {
9365 global arcnos arcout arcstart arcend growing problems
9368 if {[llength $arcnos($anc)] == 1} {
9369 # tags on the same arc are certain
9370 if {$arcnos($desc) eq $arcnos($anc)} {
9373 if {![info exists arcout($anc)]} {
9374 # if $anc is partway along an arc, use the start of the arc instead
9375 set a [lindex $arcnos($anc) 0]
9376 set anc $arcstart($a)
9379 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
9382 set a [lindex $arcnos($desc) 0]
9388 set anclist [list $x]
9392 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
9393 set x [lindex $anclist $i]
9398 foreach a $arcout($x) {
9399 if {[info exists growing($a)]} {
9400 if {![info exists growanc($x)] && $dl($x)} {
9406 if {[info exists dl($y)]} {
9410 if {![info exists done($y)]} {
9413 if {[info exists growanc($x)]} {
9417 for {set k 0} {$k < [llength $xl]} {incr k} {
9418 set z [lindex $xl $k]
9419 foreach c $arcout($z) {
9420 if {[info exists arcend($c)]} {
9422 if {[info exists dl($v)] && $dl($v)} {
9424 if {![info exists done($v)]} {
9427 if {[info exists growanc($v)]} {
9437 } elseif {$y eq $anc || !$dl($x)} {
9448 foreach x [array names growanc] {
9457 proc validate_arctags {a} {
9458 global arctags idtags
9462 foreach id $arctags($a) {
9464 if {![info exists idtags($id)]} {
9465 set na [lreplace $na $i $i]
9472 proc validate_archeads {a} {
9473 global archeads idheads
9476 set na $archeads($a)
9477 foreach id $archeads($a) {
9479 if {![info exists idheads($id)]} {
9480 set na [lreplace $na $i $i]
9484 set archeads($a) $na
9487 # Return the list of IDs that have tags that are descendents of id,
9488 # ignoring IDs that are descendents of IDs already reported.
9489 proc desctags {id} {
9490 global arcnos arcstart arcids arctags idtags allparents
9491 global growing cached_dtags
9493 if {![info exists allparents($id)]} {
9496 set t1 [clock clicks -milliseconds]
9498 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
9499 # part-way along an arc; check that arc first
9500 set a [lindex $arcnos($id) 0]
9501 if {$arctags($a) ne {}} {
9503 set i [lsearch -exact $arcids($a) $id]
9505 foreach t $arctags($a) {
9506 set j [lsearch -exact $arcids($a) $t]
9514 set id $arcstart($a)
9515 if {[info exists idtags($id)]} {
9519 if {[info exists cached_dtags($id)]} {
9520 return $cached_dtags($id)
9527 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
9528 set id [lindex $todo $i]
9530 set ta [info exists hastaggedancestor($id)]
9534 # ignore tags on starting node
9535 if {!$ta && $i > 0} {
9536 if {[info exists idtags($id)]} {
9539 } elseif {[info exists cached_dtags($id)]} {
9540 set tagloc($id) $cached_dtags($id)
9544 foreach a $arcnos($id) {
9546 if {!$ta && $arctags($a) ne {}} {
9548 if {$arctags($a) ne {}} {
9549 lappend tagloc($id) [lindex $arctags($a) end]
9552 if {$ta || $arctags($a) ne {}} {
9553 set tomark [list $d]
9554 for {set j 0} {$j < [llength $tomark]} {incr j} {
9555 set dd [lindex $tomark $j]
9556 if {![info exists hastaggedancestor($dd)]} {
9557 if {[info exists done($dd)]} {
9558 foreach b $arcnos($dd) {
9559 lappend tomark $arcstart($b)
9561 if {[info exists tagloc($dd)]} {
9564 } elseif {[info exists queued($dd)]} {
9567 set hastaggedancestor($dd) 1
9571 if {![info exists queued($d)]} {
9574 if {![info exists hastaggedancestor($d)]} {
9581 foreach id [array names tagloc] {
9582 if {![info exists hastaggedancestor($id)]} {
9583 foreach t $tagloc($id) {
9584 if {[lsearch -exact $tags $t] < 0} {
9590 set t2 [clock clicks -milliseconds]
9593 # remove tags that are descendents of other tags
9594 for {set i 0} {$i < [llength $tags]} {incr i} {
9595 set a [lindex $tags $i]
9596 for {set j 0} {$j < $i} {incr j} {
9597 set b [lindex $tags $j]
9598 set r [anc_or_desc $a $b]
9600 set tags [lreplace $tags $j $j]
9603 } elseif {$r == -1} {
9604 set tags [lreplace $tags $i $i]
9611 if {[array names growing] ne {}} {
9612 # graph isn't finished, need to check if any tag could get
9613 # eclipsed by another tag coming later. Simply ignore any
9614 # tags that could later get eclipsed.
9617 if {[is_certain $t $origid]} {
9621 if {$tags eq $ctags} {
9622 set cached_dtags($origid) $tags
9627 set cached_dtags($origid) $tags
9629 set t3 [clock clicks -milliseconds]
9630 if {0 && $t3 - $t1 >= 100} {
9631 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
9632 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
9638 global arcnos arcids arcout arcend arctags idtags allparents
9639 global growing cached_atags
9641 if {![info exists allparents($id)]} {
9644 set t1 [clock clicks -milliseconds]
9646 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
9647 # part-way along an arc; check that arc first
9648 set a [lindex $arcnos($id) 0]
9649 if {$arctags($a) ne {}} {
9651 set i [lsearch -exact $arcids($a) $id]
9652 foreach t $arctags($a) {
9653 set j [lsearch -exact $arcids($a) $t]
9659 if {![info exists arcend($a)]} {
9663 if {[info exists idtags($id)]} {
9667 if {[info exists cached_atags($id)]} {
9668 return $cached_atags($id)
9676 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
9677 set id [lindex $todo $i]
9679 set td [info exists hastaggeddescendent($id)]
9683 # ignore tags on starting node
9684 if {!$td && $i > 0} {
9685 if {[info exists idtags($id)]} {
9688 } elseif {[info exists cached_atags($id)]} {
9689 set tagloc($id) $cached_atags($id)
9693 foreach a $arcout($id) {
9694 if {!$td && $arctags($a) ne {}} {
9696 if {$arctags($a) ne {}} {
9697 lappend tagloc($id) [lindex $arctags($a) 0]
9700 if {![info exists arcend($a)]} continue
9702 if {$td || $arctags($a) ne {}} {
9703 set tomark [list $d]
9704 for {set j 0} {$j < [llength $tomark]} {incr j} {
9705 set dd [lindex $tomark $j]
9706 if {![info exists hastaggeddescendent($dd)]} {
9707 if {[info exists done($dd)]} {
9708 foreach b $arcout($dd) {
9709 if {[info exists arcend($b)]} {
9710 lappend tomark $arcend($b)
9713 if {[info exists tagloc($dd)]} {
9716 } elseif {[info exists queued($dd)]} {
9719 set hastaggeddescendent($dd) 1
9723 if {![info exists queued($d)]} {
9726 if {![info exists hastaggeddescendent($d)]} {
9732 set t2 [clock clicks -milliseconds]
9735 foreach id [array names tagloc] {
9736 if {![info exists hastaggeddescendent($id)]} {
9737 foreach t $tagloc($id) {
9738 if {[lsearch -exact $tags $t] < 0} {
9745 # remove tags that are ancestors of other tags
9746 for {set i 0} {$i < [llength $tags]} {incr i} {
9747 set a [lindex $tags $i]
9748 for {set j 0} {$j < $i} {incr j} {
9749 set b [lindex $tags $j]
9750 set r [anc_or_desc $a $b]
9752 set tags [lreplace $tags $j $j]
9755 } elseif {$r == 1} {
9756 set tags [lreplace $tags $i $i]
9763 if {[array names growing] ne {}} {
9764 # graph isn't finished, need to check if any tag could get
9765 # eclipsed by another tag coming later. Simply ignore any
9766 # tags that could later get eclipsed.
9769 if {[is_certain $origid $t]} {
9773 if {$tags eq $ctags} {
9774 set cached_atags($origid) $tags
9779 set cached_atags($origid) $tags
9781 set t3 [clock clicks -milliseconds]
9782 if {0 && $t3 - $t1 >= 100} {
9783 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
9784 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
9789 # Return the list of IDs that have heads that are descendents of id,
9790 # including id itself if it has a head.
9791 proc descheads {id} {
9792 global arcnos arcstart arcids archeads idheads cached_dheads
9795 if {![info exists allparents($id)]} {
9799 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
9800 # part-way along an arc; check it first
9801 set a [lindex $arcnos($id) 0]
9802 if {$archeads($a) ne {}} {
9803 validate_archeads $a
9804 set i [lsearch -exact $arcids($a) $id]
9805 foreach t $archeads($a) {
9806 set j [lsearch -exact $arcids($a) $t]
9811 set id $arcstart($a)
9817 for {set i 0} {$i < [llength $todo]} {incr i} {
9818 set id [lindex $todo $i]
9819 if {[info exists cached_dheads($id)]} {
9820 set ret [concat $ret $cached_dheads($id)]
9822 if {[info exists idheads($id)]} {
9825 foreach a $arcnos($id) {
9826 if {$archeads($a) ne {}} {
9827 validate_archeads $a
9828 if {$archeads($a) ne {}} {
9829 set ret [concat $ret $archeads($a)]
9833 if {![info exists seen($d)]} {
9840 set ret [lsort -unique $ret]
9841 set cached_dheads($origid) $ret
9842 return [concat $ret $aret]
9845 proc addedtag {id} {
9846 global arcnos arcout cached_dtags cached_atags
9848 if {![info exists arcnos($id)]} return
9849 if {![info exists arcout($id)]} {
9850 recalcarc [lindex $arcnos($id) 0]
9852 catch {unset cached_dtags}
9853 catch {unset cached_atags}
9856 proc addedhead {hid head} {
9857 global arcnos arcout cached_dheads
9859 if {![info exists arcnos($hid)]} return
9860 if {![info exists arcout($hid)]} {
9861 recalcarc [lindex $arcnos($hid) 0]
9863 catch {unset cached_dheads}
9866 proc removedhead {hid head} {
9867 global cached_dheads
9869 catch {unset cached_dheads}
9872 proc movedhead {hid head} {
9873 global arcnos arcout cached_dheads
9875 if {![info exists arcnos($hid)]} return
9876 if {![info exists arcout($hid)]} {
9877 recalcarc [lindex $arcnos($hid) 0]
9879 catch {unset cached_dheads}
9882 proc changedrefs {} {
9883 global cached_dheads cached_dtags cached_atags
9884 global arctags archeads arcnos arcout idheads idtags
9886 foreach id [concat [array names idheads] [array names idtags]] {
9887 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
9888 set a [lindex $arcnos($id) 0]
9889 if {![info exists donearc($a)]} {
9895 catch {unset cached_dtags}
9896 catch {unset cached_atags}
9897 catch {unset cached_dheads}
9900 proc rereadrefs {} {
9901 global idtags idheads idotherrefs mainheadid
9903 set refids [concat [array names idtags] \
9904 [array names idheads] [array names idotherrefs]]
9905 foreach id $refids {
9906 if {![info exists ref($id)]} {
9907 set ref($id) [listrefs $id]
9910 set oldmainhead $mainheadid
9913 set refids [lsort -unique [concat $refids [array names idtags] \
9914 [array names idheads] [array names idotherrefs]]]
9915 foreach id $refids {
9916 set v [listrefs $id]
9917 if {![info exists ref($id)] || $ref($id) != $v} {
9921 if {$oldmainhead ne $mainheadid} {
9922 redrawtags $oldmainhead
9923 redrawtags $mainheadid
9928 proc listrefs {id} {
9929 global idtags idheads idotherrefs
9932 if {[info exists idtags($id)]} {
9936 if {[info exists idheads($id)]} {
9940 if {[info exists idotherrefs($id)]} {
9941 set z $idotherrefs($id)
9943 return [list $x $y $z]
9946 proc showtag {tag isnew} {
9947 global ctext tagcontents tagids linknum tagobjid
9950 addtohistory [list showtag $tag 0]
9952 $ctext conf -state normal
9956 if {![info exists tagcontents($tag)]} {
9958 set tagcontents($tag) [exec git cat-file tag $tagobjid($tag)]
9961 if {[info exists tagcontents($tag)]} {
9962 set text $tagcontents($tag)
9964 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
9966 appendwithlinks $text {}
9967 $ctext conf -state disabled
9979 if {[info exists gitktmpdir]} {
9980 catch {file delete -force $gitktmpdir}
9984 proc mkfontdisp {font top which} {
9985 global fontattr fontpref $font
9987 set fontpref($font) [set $font]
9988 button $top.${font}but -text $which -font optionfont \
9989 -command [list choosefont $font $which]
9990 label $top.$font -relief flat -font $font \
9991 -text $fontattr($font,family) -justify left
9992 grid x $top.${font}but $top.$font -sticky w
9995 proc choosefont {font which} {
9996 global fontparam fontlist fonttop fontattr
9999 set fontparam(which) $which
10000 set fontparam(font) $font
10001 set fontparam(family) [font actual $font -family]
10002 set fontparam(size) $fontattr($font,size)
10003 set fontparam(weight) $fontattr($font,weight)
10004 set fontparam(slant) $fontattr($font,slant)
10007 if {![winfo exists $top]} {
10009 eval font config sample [font actual $font]
10011 make_transient $top $prefstop
10012 wm title $top [mc "Gitk font chooser"]
10013 label $top.l -textvariable fontparam(which)
10014 pack $top.l -side top
10015 set fontlist [lsort [font families]]
10017 listbox $top.f.fam -listvariable fontlist \
10018 -yscrollcommand [list $top.f.sb set]
10019 bind $top.f.fam <<ListboxSelect>> selfontfam
10020 scrollbar $top.f.sb -command [list $top.f.fam yview]
10021 pack $top.f.sb -side right -fill y
10022 pack $top.f.fam -side left -fill both -expand 1
10023 pack $top.f -side top -fill both -expand 1
10025 spinbox $top.g.size -from 4 -to 40 -width 4 \
10026 -textvariable fontparam(size) \
10027 -validatecommand {string is integer -strict %s}
10028 checkbutton $top.g.bold -padx 5 \
10029 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10030 -variable fontparam(weight) -onvalue bold -offvalue normal
10031 checkbutton $top.g.ital -padx 5 \
10032 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10033 -variable fontparam(slant) -onvalue italic -offvalue roman
10034 pack $top.g.size $top.g.bold $top.g.ital -side left
10035 pack $top.g -side top
10036 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10038 $top.c create text 100 25 -anchor center -text $which -font sample \
10039 -fill black -tags text
10040 bind $top.c <Configure> [list centertext $top.c]
10041 pack $top.c -side top -fill x
10043 button $top.buts.ok -text [mc "OK"] -command fontok -default active
10044 button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10045 bind $top <Key-Return> fontok
10046 bind $top <Key-Escape> fontcan
10047 grid $top.buts.ok $top.buts.can
10048 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10049 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10050 pack $top.buts -side bottom -fill x
10051 trace add variable fontparam write chg_fontparam
10054 $top.c itemconf text -text $which
10056 set i [lsearch -exact $fontlist $fontparam(family)]
10058 $top.f.fam selection set $i
10063 proc centertext {w} {
10064 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
10068 global fontparam fontpref prefstop
10070 set f $fontparam(font)
10071 set fontpref($f) [list $fontparam(family) $fontparam(size)]
10072 if {$fontparam(weight) eq "bold"} {
10073 lappend fontpref($f) "bold"
10075 if {$fontparam(slant) eq "italic"} {
10076 lappend fontpref($f) "italic"
10079 $w conf -text $fontparam(family) -font $fontpref($f)
10085 global fonttop fontparam
10087 if {[info exists fonttop]} {
10088 catch {destroy $fonttop}
10089 catch {font delete sample}
10095 proc selfontfam {} {
10096 global fonttop fontparam
10098 set i [$fonttop.f.fam curselection]
10100 set fontparam(family) [$fonttop.f.fam get $i]
10104 proc chg_fontparam {v sub op} {
10107 font config sample -$sub $fontparam($sub)
10111 global maxwidth maxgraphpct
10112 global oldprefs prefstop showneartags showlocalchanges
10113 global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
10114 global tabstop limitdiffs autoselect extdifftool perfile_attrs
10118 if {[winfo exists $top]} {
10122 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
10123 limitdiffs tabstop perfile_attrs} {
10124 set oldprefs($v) [set $v]
10127 wm title $top [mc "Gitk preferences"]
10128 make_transient $top .
10129 label $top.ldisp -text [mc "Commit list display options"]
10130 grid $top.ldisp - -sticky w -pady 10
10131 label $top.spacer -text " "
10132 label $top.maxwidthl -text [mc "Maximum graph width (lines)"] \
10134 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
10135 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
10136 label $top.maxpctl -text [mc "Maximum graph width (% of pane)"] \
10138 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
10139 grid x $top.maxpctl $top.maxpct -sticky w
10140 checkbutton $top.showlocal -text [mc "Show local changes"] \
10141 -font optionfont -variable showlocalchanges
10142 grid x $top.showlocal -sticky w
10143 checkbutton $top.autoselect -text [mc "Auto-select SHA1"] \
10144 -font optionfont -variable autoselect
10145 grid x $top.autoselect -sticky w
10147 label $top.ddisp -text [mc "Diff display options"]
10148 grid $top.ddisp - -sticky w -pady 10
10149 label $top.tabstopl -text [mc "Tab spacing"] -font optionfont
10150 spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
10151 grid x $top.tabstopl $top.tabstop -sticky w
10152 checkbutton $top.ntag -text [mc "Display nearby tags"] \
10153 -font optionfont -variable showneartags
10154 grid x $top.ntag -sticky w
10155 checkbutton $top.ldiff -text [mc "Limit diffs to listed paths"] \
10156 -font optionfont -variable limitdiffs
10157 grid x $top.ldiff -sticky w
10158 checkbutton $top.lattr -text [mc "Support per-file encodings"] \
10159 -font optionfont -variable perfile_attrs
10160 grid x $top.lattr -sticky w
10162 entry $top.extdifft -textvariable extdifftool
10163 frame $top.extdifff
10164 label $top.extdifff.l -text [mc "External diff tool" ] -font optionfont \
10166 button $top.extdifff.b -text [mc "Choose..."] -font optionfont \
10167 -command choose_extdiff
10168 pack $top.extdifff.l $top.extdifff.b -side left
10169 grid x $top.extdifff $top.extdifft -sticky w
10171 label $top.cdisp -text [mc "Colors: press to choose"]
10172 grid $top.cdisp - -sticky w -pady 10
10173 label $top.bg -padx 40 -relief sunk -background $bgcolor
10174 button $top.bgbut -text [mc "Background"] -font optionfont \
10175 -command [list choosecolor bgcolor {} $top.bg [mc "background"] setbg]
10176 grid x $top.bgbut $top.bg -sticky w
10177 label $top.fg -padx 40 -relief sunk -background $fgcolor
10178 button $top.fgbut -text [mc "Foreground"] -font optionfont \
10179 -command [list choosecolor fgcolor {} $top.fg [mc "foreground"] setfg]
10180 grid x $top.fgbut $top.fg -sticky w
10181 label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
10182 button $top.diffoldbut -text [mc "Diff: old lines"] -font optionfont \
10183 -command [list choosecolor diffcolors 0 $top.diffold [mc "diff old lines"] \
10184 [list $ctext tag conf d0 -foreground]]
10185 grid x $top.diffoldbut $top.diffold -sticky w
10186 label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
10187 button $top.diffnewbut -text [mc "Diff: new lines"] -font optionfont \
10188 -command [list choosecolor diffcolors 1 $top.diffnew [mc "diff new lines"] \
10189 [list $ctext tag conf dresult -foreground]]
10190 grid x $top.diffnewbut $top.diffnew -sticky w
10191 label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
10192 button $top.hunksepbut -text [mc "Diff: hunk header"] -font optionfont \
10193 -command [list choosecolor diffcolors 2 $top.hunksep \
10194 [mc "diff hunk header"] \
10195 [list $ctext tag conf hunksep -foreground]]
10196 grid x $top.hunksepbut $top.hunksep -sticky w
10197 label $top.markbgsep -padx 40 -relief sunk -background $markbgcolor
10198 button $top.markbgbut -text [mc "Marked line bg"] -font optionfont \
10199 -command [list choosecolor markbgcolor {} $top.markbgsep \
10200 [mc "marked line background"] \
10201 [list $ctext tag conf omark -background]]
10202 grid x $top.markbgbut $top.markbgsep -sticky w
10203 label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor
10204 button $top.selbgbut -text [mc "Select bg"] -font optionfont \
10205 -command [list choosecolor selectbgcolor {} $top.selbgsep [mc "background"] setselbg]
10206 grid x $top.selbgbut $top.selbgsep -sticky w
10208 label $top.cfont -text [mc "Fonts: press to choose"]
10209 grid $top.cfont - -sticky w -pady 10
10210 mkfontdisp mainfont $top [mc "Main font"]
10211 mkfontdisp textfont $top [mc "Diff display font"]
10212 mkfontdisp uifont $top [mc "User interface font"]
10215 button $top.buts.ok -text [mc "OK"] -command prefsok -default active
10216 button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
10217 bind $top <Key-Return> prefsok
10218 bind $top <Key-Escape> prefscan
10219 grid $top.buts.ok $top.buts.can
10220 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10221 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10222 grid $top.buts - - -pady 10 -sticky ew
10223 bind $top <Visibility> "focus $top.buts.ok"
10226 proc choose_extdiff {} {
10229 set prog [tk_getOpenFile -title "External diff tool" -multiple false]
10231 set extdifftool $prog
10235 proc choosecolor {v vi w x cmd} {
10238 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
10239 -title [mc "Gitk: choose color for %s" $x]]
10240 if {$c eq {}} return
10241 $w conf -background $c
10246 proc setselbg {c} {
10247 global bglist cflist
10248 foreach w $bglist {
10249 $w configure -selectbackground $c
10251 $cflist tag configure highlight \
10252 -background [$cflist cget -selectbackground]
10253 allcanvs itemconf secsel -fill $c
10259 foreach w $bglist {
10260 $w conf -background $c
10267 foreach w $fglist {
10268 $w conf -foreground $c
10270 allcanvs itemconf text -fill $c
10271 $canv itemconf circle -outline $c
10275 global oldprefs prefstop
10277 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
10278 limitdiffs tabstop perfile_attrs} {
10280 set $v $oldprefs($v)
10282 catch {destroy $prefstop}
10288 global maxwidth maxgraphpct
10289 global oldprefs prefstop showneartags showlocalchanges
10290 global fontpref mainfont textfont uifont
10291 global limitdiffs treediffs perfile_attrs
10293 catch {destroy $prefstop}
10297 if {$mainfont ne $fontpref(mainfont)} {
10298 set mainfont $fontpref(mainfont)
10299 parsefont mainfont $mainfont
10300 eval font configure mainfont [fontflags mainfont]
10301 eval font configure mainfontbold [fontflags mainfont 1]
10305 if {$textfont ne $fontpref(textfont)} {
10306 set textfont $fontpref(textfont)
10307 parsefont textfont $textfont
10308 eval font configure textfont [fontflags textfont]
10309 eval font configure textfontbold [fontflags textfont 1]
10311 if {$uifont ne $fontpref(uifont)} {
10312 set uifont $fontpref(uifont)
10313 parsefont uifont $uifont
10314 eval font configure uifont [fontflags uifont]
10317 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
10318 if {$showlocalchanges} {
10324 if {$limitdiffs != $oldprefs(limitdiffs) ||
10325 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
10326 # treediffs elements are limited by path;
10327 # won't have encodings cached if perfile_attrs was just turned on
10328 catch {unset treediffs}
10330 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
10331 || $maxgraphpct != $oldprefs(maxgraphpct)} {
10333 } elseif {$showneartags != $oldprefs(showneartags) ||
10334 $limitdiffs != $oldprefs(limitdiffs)} {
10339 proc formatdate {d} {
10340 global datetimeformat
10342 set d [clock format $d -format $datetimeformat]
10347 # This list of encoding names and aliases is distilled from
10348 # http://www.iana.org/assignments/character-sets.
10349 # Not all of them are supported by Tcl.
10350 set encoding_aliases {
10351 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
10352 ISO646-US US-ASCII us IBM367 cp367 csASCII }
10353 { ISO-10646-UTF-1 csISO10646UTF1 }
10354 { ISO_646.basic:1983 ref csISO646basic1983 }
10355 { INVARIANT csINVARIANT }
10356 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
10357 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
10358 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
10359 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
10360 { NATS-DANO iso-ir-9-1 csNATSDANO }
10361 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
10362 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
10363 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
10364 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
10365 { ISO-2022-KR csISO2022KR }
10367 { ISO-2022-JP csISO2022JP }
10368 { ISO-2022-JP-2 csISO2022JP2 }
10369 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
10370 csISO13JISC6220jp }
10371 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
10372 { IT iso-ir-15 ISO646-IT csISO15Italian }
10373 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
10374 { ES iso-ir-17 ISO646-ES csISO17Spanish }
10375 { greek7-old iso-ir-18 csISO18Greek7Old }
10376 { latin-greek iso-ir-19 csISO19LatinGreek }
10377 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
10378 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
10379 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
10380 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
10381 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
10382 { BS_viewdata iso-ir-47 csISO47BSViewdata }
10383 { INIS iso-ir-49 csISO49INIS }
10384 { INIS-8 iso-ir-50 csISO50INIS8 }
10385 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
10386 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
10387 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
10388 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
10389 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
10390 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
10391 csISO60Norwegian1 }
10392 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
10393 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
10394 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
10395 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
10396 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
10397 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
10398 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
10399 { greek7 iso-ir-88 csISO88Greek7 }
10400 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
10401 { iso-ir-90 csISO90 }
10402 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
10403 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
10404 csISO92JISC62991984b }
10405 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
10406 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
10407 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
10408 csISO95JIS62291984handadd }
10409 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
10410 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
10411 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
10412 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
10413 CP819 csISOLatin1 }
10414 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
10415 { T.61-7bit iso-ir-102 csISO102T617bit }
10416 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
10417 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
10418 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
10419 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
10420 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
10421 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
10422 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
10423 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
10424 arabic csISOLatinArabic }
10425 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
10426 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
10427 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
10428 greek greek8 csISOLatinGreek }
10429 { T.101-G2 iso-ir-128 csISO128T101G2 }
10430 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
10432 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
10433 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
10434 { CSN_369103 iso-ir-139 csISO139CSN369103 }
10435 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
10436 { ISO_6937-2-add iso-ir-142 csISOTextComm }
10437 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
10438 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
10439 csISOLatinCyrillic }
10440 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
10441 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
10442 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
10443 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
10444 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
10445 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
10446 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
10447 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
10448 { ISO_10367-box iso-ir-155 csISO10367Box }
10449 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
10450 { latin-lap lap iso-ir-158 csISO158Lap }
10451 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
10452 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
10455 { JIS_X0201 X0201 csHalfWidthKatakana }
10456 { KSC5636 ISO646-KR csKSC5636 }
10457 { ISO-10646-UCS-2 csUnicode }
10458 { ISO-10646-UCS-4 csUCS4 }
10459 { DEC-MCS dec csDECMCS }
10460 { hp-roman8 roman8 r8 csHPRoman8 }
10461 { macintosh mac csMacintosh }
10462 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
10464 { IBM038 EBCDIC-INT cp038 csIBM038 }
10465 { IBM273 CP273 csIBM273 }
10466 { IBM274 EBCDIC-BE CP274 csIBM274 }
10467 { IBM275 EBCDIC-BR cp275 csIBM275 }
10468 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
10469 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
10470 { IBM280 CP280 ebcdic-cp-it csIBM280 }
10471 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
10472 { IBM284 CP284 ebcdic-cp-es csIBM284 }
10473 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
10474 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
10475 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
10476 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
10477 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
10478 { IBM424 cp424 ebcdic-cp-he csIBM424 }
10479 { IBM437 cp437 437 csPC8CodePage437 }
10480 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
10481 { IBM775 cp775 csPC775Baltic }
10482 { IBM850 cp850 850 csPC850Multilingual }
10483 { IBM851 cp851 851 csIBM851 }
10484 { IBM852 cp852 852 csPCp852 }
10485 { IBM855 cp855 855 csIBM855 }
10486 { IBM857 cp857 857 csIBM857 }
10487 { IBM860 cp860 860 csIBM860 }
10488 { IBM861 cp861 861 cp-is csIBM861 }
10489 { IBM862 cp862 862 csPC862LatinHebrew }
10490 { IBM863 cp863 863 csIBM863 }
10491 { IBM864 cp864 csIBM864 }
10492 { IBM865 cp865 865 csIBM865 }
10493 { IBM866 cp866 866 csIBM866 }
10494 { IBM868 CP868 cp-ar csIBM868 }
10495 { IBM869 cp869 869 cp-gr csIBM869 }
10496 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
10497 { IBM871 CP871 ebcdic-cp-is csIBM871 }
10498 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
10499 { IBM891 cp891 csIBM891 }
10500 { IBM903 cp903 csIBM903 }
10501 { IBM904 cp904 904 csIBBM904 }
10502 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
10503 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
10504 { IBM1026 CP1026 csIBM1026 }
10505 { EBCDIC-AT-DE csIBMEBCDICATDE }
10506 { EBCDIC-AT-DE-A csEBCDICATDEA }
10507 { EBCDIC-CA-FR csEBCDICCAFR }
10508 { EBCDIC-DK-NO csEBCDICDKNO }
10509 { EBCDIC-DK-NO-A csEBCDICDKNOA }
10510 { EBCDIC-FI-SE csEBCDICFISE }
10511 { EBCDIC-FI-SE-A csEBCDICFISEA }
10512 { EBCDIC-FR csEBCDICFR }
10513 { EBCDIC-IT csEBCDICIT }
10514 { EBCDIC-PT csEBCDICPT }
10515 { EBCDIC-ES csEBCDICES }
10516 { EBCDIC-ES-A csEBCDICESA }
10517 { EBCDIC-ES-S csEBCDICESS }
10518 { EBCDIC-UK csEBCDICUK }
10519 { EBCDIC-US csEBCDICUS }
10520 { UNKNOWN-8BIT csUnknown8BiT }
10521 { MNEMONIC csMnemonic }
10523 { VISCII csVISCII }
10526 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
10527 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
10528 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
10529 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
10530 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
10531 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
10532 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
10533 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
10534 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
10535 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
10536 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
10537 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
10538 { IBM1047 IBM-1047 }
10539 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
10540 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
10541 { UNICODE-1-1 csUnicode11 }
10542 { CESU-8 csCESU-8 }
10543 { BOCU-1 csBOCU-1 }
10544 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
10545 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
10547 { ISO-8859-15 ISO_8859-15 Latin-9 }
10548 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
10549 { GBK CP936 MS936 windows-936 }
10550 { JIS_Encoding csJISEncoding }
10551 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
10552 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
10554 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
10555 { ISO-10646-UCS-Basic csUnicodeASCII }
10556 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
10557 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
10558 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
10559 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
10560 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
10561 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
10562 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
10563 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
10564 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
10565 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
10566 { Adobe-Standard-Encoding csAdobeStandardEncoding }
10567 { Ventura-US csVenturaUS }
10568 { Ventura-International csVenturaInternational }
10569 { PC8-Danish-Norwegian csPC8DanishNorwegian }
10570 { PC8-Turkish csPC8Turkish }
10571 { IBM-Symbols csIBMSymbols }
10572 { IBM-Thai csIBMThai }
10573 { HP-Legal csHPLegal }
10574 { HP-Pi-font csHPPiFont }
10575 { HP-Math8 csHPMath8 }
10576 { Adobe-Symbol-Encoding csHPPSMath }
10577 { HP-DeskTop csHPDesktop }
10578 { Ventura-Math csVenturaMath }
10579 { Microsoft-Publishing csMicrosoftPublishing }
10580 { Windows-31J csWindows31J }
10581 { GB2312 csGB2312 }
10585 proc tcl_encoding {enc} {
10586 global encoding_aliases tcl_encoding_cache
10587 if {[info exists tcl_encoding_cache($enc)]} {
10588 return $tcl_encoding_cache($enc)
10590 set names [encoding names]
10591 set lcnames [string tolower $names]
10592 set enc [string tolower $enc]
10593 set i [lsearch -exact $lcnames $enc]
10595 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
10596 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
10597 set i [lsearch -exact $lcnames $encx]
10601 foreach l $encoding_aliases {
10602 set ll [string tolower $l]
10603 if {[lsearch -exact $ll $enc] < 0} continue
10604 # look through the aliases for one that tcl knows about
10606 set i [lsearch -exact $lcnames $e]
10608 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
10609 set i [lsearch -exact $lcnames $ex]
10619 set tclenc [lindex $names $i]
10621 set tcl_encoding_cache($enc) $tclenc
10625 proc gitattr {path attr default} {
10626 global path_attr_cache
10627 if {[info exists path_attr_cache($attr,$path)]} {
10628 set r $path_attr_cache($attr,$path)
10630 set r "unspecified"
10631 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
10632 regexp "(.*): encoding: (.*)" $line m f r
10634 set path_attr_cache($attr,$path) $r
10636 if {$r eq "unspecified"} {
10642 proc cache_gitattr {attr pathlist} {
10643 global path_attr_cache
10645 foreach path $pathlist {
10646 if {![info exists path_attr_cache($attr,$path)]} {
10647 lappend newlist $path
10651 if {[tk windowingsystem] == "win32"} {
10652 # windows has a 32k limit on the arguments to a command...
10655 while {$newlist ne {}} {
10656 set head [lrange $newlist 0 [expr {$lim - 1}]]
10657 set newlist [lrange $newlist $lim end]
10658 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
10659 foreach row [split $rlist "\n"] {
10660 if {[regexp "(.*): encoding: (.*)" $row m path value]} {
10661 if {[string index $path 0] eq "\""} {
10662 set path [encoding convertfrom [lindex $path 0]]
10664 set path_attr_cache($attr,$path) $value
10671 proc get_path_encoding {path} {
10672 global gui_encoding perfile_attrs
10673 set tcl_enc $gui_encoding
10674 if {$path ne {} && $perfile_attrs} {
10675 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
10683 # First check that Tcl/Tk is recent enough
10684 if {[catch {package require Tk 8.4} err]} {
10685 show_error {} . [mc "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
10686 Gitk requires at least Tcl/Tk 8.4."]
10691 set wrcomcmd "git diff-tree --stdin -p --pretty"
10695 set gitencoding [exec git config --get i18n.commitencoding]
10698 set gitencoding [exec git config --get i18n.logoutputencoding]
10700 if {$gitencoding == ""} {
10701 set gitencoding "utf-8"
10703 set tclencoding [tcl_encoding $gitencoding]
10704 if {$tclencoding == {}} {
10705 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
10708 set gui_encoding [encoding system]
10710 set enc [exec git config --get gui.encoding]
10712 set tclenc [tcl_encoding $enc]
10713 if {$tclenc ne {}} {
10714 set gui_encoding $tclenc
10716 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
10721 if {[tk windowingsystem] eq "aqua"} {
10722 set mainfont {{Lucida Grande} 9}
10723 set textfont {Monaco 9}
10724 set uifont {{Lucida Grande} 9 bold}
10726 set mainfont {Helvetica 9}
10727 set textfont {Courier 9}
10728 set uifont {Helvetica 9 bold}
10731 set findmergefiles 0
10739 set cmitmode "patch"
10740 set wrapcomment "none"
10744 set showlocalchanges 1
10746 set datetimeformat "%Y-%m-%d %H:%M:%S"
10748 set perfile_attrs 0
10750 if {[tk windowingsystem] eq "aqua"} {
10751 set extdifftool "opendiff"
10753 set extdifftool "meld"
10756 set colors {green red blue magenta darkgrey brown orange}
10759 set diffcolors {red "#00a000" blue}
10762 set selectbgcolor gray85
10763 set markbgcolor "#e0e0ff"
10765 set circlecolors {white blue gray blue blue}
10767 # button for popping up context menus
10768 if {[tk windowingsystem] eq "aqua"} {
10769 set ctxbut <Button-2>
10771 set ctxbut <Button-3>
10774 ## For msgcat loading, first locate the installation location.
10775 if { [info exists ::env(GITK_MSGSDIR)] } {
10776 ## Msgsdir was manually set in the environment.
10777 set gitk_msgsdir $::env(GITK_MSGSDIR)
10779 ## Let's guess the prefix from argv0.
10780 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
10781 set gitk_libdir [file join $gitk_prefix share gitk lib]
10782 set gitk_msgsdir [file join $gitk_libdir msgs]
10786 ## Internationalization (i18n) through msgcat and gettext. See
10787 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
10788 package require msgcat
10789 namespace import ::msgcat::mc
10790 ## And eventually load the actual message catalog
10791 ::msgcat::mcload $gitk_msgsdir
10793 catch {source ~/.gitk}
10795 font create optionfont -family sans-serif -size -12
10797 parsefont mainfont $mainfont
10798 eval font create mainfont [fontflags mainfont]
10799 eval font create mainfontbold [fontflags mainfont 1]
10801 parsefont textfont $textfont
10802 eval font create textfont [fontflags textfont]
10803 eval font create textfontbold [fontflags textfont 1]
10805 parsefont uifont $uifont
10806 eval font create uifont [fontflags uifont]
10810 # check that we can find a .git directory somewhere...
10811 if {[catch {set gitdir [gitdir]}]} {
10812 show_error {} . [mc "Cannot find a git repository here."]
10815 if {![file isdirectory $gitdir]} {
10816 show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir]
10821 set selectheadid {}
10824 set cmdline_files {}
10826 set revtreeargscmd {}
10827 foreach arg $argv {
10828 switch -glob -- $arg {
10831 set cmdline_files [lrange $argv [expr {$i + 1}] end]
10834 "--select-commit=*" {
10835 set selecthead [string range $arg 16 end]
10838 set revtreeargscmd [string range $arg 10 end]
10841 lappend revtreeargs $arg
10847 if {$selecthead eq "HEAD"} {
10851 if {$i >= [llength $argv] && $revtreeargs ne {}} {
10852 # no -- on command line, but some arguments (other than --argscmd)
10854 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
10855 set cmdline_files [split $f "\n"]
10856 set n [llength $cmdline_files]
10857 set revtreeargs [lrange $revtreeargs 0 end-$n]
10858 # Unfortunately git rev-parse doesn't produce an error when
10859 # something is both a revision and a filename. To be consistent
10860 # with git log and git rev-list, check revtreeargs for filenames.
10861 foreach arg $revtreeargs {
10862 if {[file exists $arg]} {
10863 show_error {} . [mc "Ambiguous argument '%s': both revision\
10864 and filename" $arg]
10869 # unfortunately we get both stdout and stderr in $err,
10870 # so look for "fatal:".
10871 set i [string first "fatal:" $err]
10873 set err [string range $err [expr {$i + 6}] end]
10875 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
10880 set nullid "0000000000000000000000000000000000000000"
10881 set nullid2 "0000000000000000000000000000000000000001"
10882 set nullfile "/dev/null"
10884 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
10891 set highlight_paths {}
10893 set searchdirn -forwards
10896 set diffelide {0 0}
10897 set markingmatches 0
10898 set linkentercount 0
10899 set need_redisplay 0
10906 set selectedhlview [mc "None"]
10907 set highlight_related [mc "None"]
10908 set highlight_files {}
10909 set viewfiles(0) {}
10912 set viewargscmd(0) {}
10914 set selectedline {}
10922 set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
10926 image create photo gitlogo -width 16 -height 16
10928 image create photo gitlogominus -width 4 -height 2
10929 gitlogominus put #C00000 -to 0 0 4 2
10930 gitlogo copy gitlogominus -to 1 5
10931 gitlogo copy gitlogominus -to 6 5
10932 gitlogo copy gitlogominus -to 11 5
10933 image delete gitlogominus
10935 image create photo gitlogoplus -width 4 -height 4
10936 gitlogoplus put #008000 -to 1 0 3 4
10937 gitlogoplus put #008000 -to 0 1 4 3
10938 gitlogo copy gitlogoplus -to 1 9
10939 gitlogo copy gitlogoplus -to 6 9
10940 gitlogo copy gitlogoplus -to 11 9
10941 image delete gitlogoplus
10943 image create photo gitlogo32 -width 32 -height 32
10944 gitlogo32 copy gitlogo -zoom 2 2
10946 wm iconphoto . -default gitlogo gitlogo32
10948 # wait for the window to become visible
10949 tkwait visibility .
10950 wm title . "[file tail $argv0]: [file tail [pwd]]"
10953 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
10954 # create a view for the files/dirs specified on the command line
10958 set viewname(1) [mc "Command line"]
10959 set viewfiles(1) $cmdline_files
10960 set viewargs(1) $revtreeargs
10961 set viewargscmd(1) $revtreeargscmd
10965 .bar.view entryconf [mca "Edit view..."] -state normal
10966 .bar.view entryconf [mca "Delete view"] -state normal
10969 if {[info exists permviews]} {
10970 foreach v $permviews {
10973 set viewname($n) [lindex $v 0]
10974 set viewfiles($n) [lindex $v 1]
10975 set viewargs($n) [lindex $v 2]
10976 set viewargscmd($n) [lindex $v 3]
10982 if {[tk windowingsystem] eq "win32"} {