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]
158 # These request or affect diff output, which we don't want.
159 # Some could be used to set our defaults for diff display.
161 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
162 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
163 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
164 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
165 "--ignore-space-change" - "-U*" - "--unified=*" {
166 lappend diffargs
$arg
168 # These cause our parsing of git log's output to fail, or else
169 # they're options we want to set ourselves, so ignore them.
170 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
171 "--name-only" - "--name-status" - "--color" - "--color-words" -
172 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
173 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
174 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
175 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
176 "--objects" - "--objects-edge" - "--reverse" {
178 # These are harmless, and some are even useful
179 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
180 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
181 "--full-history" - "--dense" - "--sparse" -
182 "--follow" - "--left-right" - "--encoding=*" {
185 # These mean that we get a subset of the commits
186 "--diff-filter=*" - "--no-merges" - "--unpacked" -
187 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
188 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
189 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
190 "--remove-empty" - "--first-parent" - "--cherry-pick" -
191 "-S*" - "--pickaxe-all" - "--pickaxe-regex" - {
195 # This appears to be the only one that has a value as a
196 # separate word following it
203 set notflag
[expr {!$notflag}]
211 # git rev-parse doesn't understand --merge
212 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
214 # Other flag arguments including -<n>
216 if {[string is digit
-strict [string range
$arg 1 end
]]} {
219 # a flag argument that we don't recognize;
220 # that means we can't optimize
225 # Non-flag arguments specify commits or ranges of commits
227 if {[string match
"*...*" $arg]} {
228 lappend revargs
--gitk-symmetric-diff-marker
234 set vdflags
($n) $diffargs
235 set vflags
($n) $glflags
236 set vrevs
($n) $revargs
237 set vfiltered
($n) $filtered
238 set vorigargs
($n) $origargs
242 proc parseviewrevs
{view revs
} {
243 global vposids vnegids
248 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
249 # we get stdout followed by stderr in $err
250 # for an unknown rev, git rev-parse echoes it and then errors out
251 set errlines
[split $err "\n"]
253 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
254 set line
[lindex
$errlines $l]
255 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
256 if {[string match
"fatal:*" $line]} {
257 if {[string match
"fatal: ambiguous argument*" $line]
259 if {[llength
$badrev] == 1} {
260 set err
"unknown revision $badrev"
262 set err
"unknown revisions: [join $badrev ", "]"
265 set err
[join [lrange
$errlines $l end
] "\n"]
272 error_popup
"[mc "Error parsing revisions
:"] $err"
279 foreach id
[split $ids "\n"] {
280 if {$id eq
"--gitk-symmetric-diff-marker"} {
282 } elseif
{[string match
"^*" $id]} {
289 lappend neg
[string range
$id 1 end
]
294 lset ret end
[lindex
$ret end
]...
$id
300 set vposids
($view) $pos
301 set vnegids
($view) $neg
305 # Start off a git log process and arrange to read its output
306 proc start_rev_list
{view
} {
307 global startmsecs commitidx viewcomplete curview
309 global viewargs viewargscmd viewfiles vfilelimit
310 global showlocalchanges
311 global viewactive viewinstances vmergeonly
313 global vcanopt vflags vrevs vorigargs
315 set startmsecs
[clock clicks
-milliseconds]
316 set commitidx
($view) 0
317 # these are set this way for the error exits
318 set viewcomplete
($view) 1
319 set viewactive
($view) 0
322 set args
$viewargs($view)
323 if {$viewargscmd($view) ne
{}} {
325 set str
[exec sh
-c $viewargscmd($view)]
327 error_popup
"[mc "Error executing
--argscmd command:"] $err"
330 set args
[concat
$args [split $str "\n"]]
332 set vcanopt
($view) [parseviewargs
$view $args]
334 set files
$viewfiles($view)
335 if {$vmergeonly($view)} {
336 set files
[unmerged_files
$files]
339 if {$nr_unmerged == 0} {
340 error_popup
[mc
"No files selected: --merge specified but\
341 no files are unmerged."]
343 error_popup
[mc
"No files selected: --merge specified but\
344 no unmerged files are within file limit."]
349 set vfilelimit
($view) $files
351 if {$vcanopt($view)} {
352 set revs
[parseviewrevs
$view $vrevs($view)]
356 set args
[concat
$vflags($view) $revs]
358 set args
$vorigargs($view)
362 set fd
[open
[concat | git log
--no-color -z --pretty=raw
--parents \
363 --boundary $args "--" $files] r
]
365 error_popup
"[mc "Error executing git log
:"] $err"
368 set i
[reg_instance
$fd]
369 set viewinstances
($view) [list
$i]
370 if {$showlocalchanges && $mainheadid ne
{}} {
371 interestedin
$mainheadid dodiffindex
373 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
374 if {$tclencoding != {}} {
375 fconfigure
$fd -encoding $tclencoding
377 filerun
$fd [list getcommitlines
$fd $i $view 0]
378 nowbusy
$view [mc
"Reading"]
379 set viewcomplete
($view) 0
380 set viewactive
($view) 1
384 proc stop_instance
{inst
} {
385 global commfd leftover
387 set fd
$commfd($inst)
391 if {$
::tcl_platform
(platform
) eq
{windows
}} {
400 unset leftover
($inst)
403 proc stop_backends
{} {
406 foreach inst
[array names commfd
] {
411 proc stop_rev_list
{view
} {
414 foreach inst
$viewinstances($view) {
417 set viewinstances
($view) {}
420 proc reset_pending_select
{selid
} {
421 global pending_select mainheadid selectheadid
424 set pending_select
$selid
425 } elseif
{$selectheadid ne
{}} {
426 set pending_select
$selectheadid
428 set pending_select
$mainheadid
432 proc getcommits
{selid
} {
433 global canv curview need_redisplay viewactive
436 if {[start_rev_list
$curview]} {
437 reset_pending_select
$selid
438 show_status
[mc
"Reading commits..."]
441 show_status
[mc
"No commits selected"]
445 proc updatecommits
{} {
446 global curview vcanopt vorigargs vfilelimit viewinstances
447 global viewactive viewcomplete tclencoding
448 global startmsecs showneartags showlocalchanges
449 global mainheadid pending_select
451 global varcid vposids vnegids vflags vrevs
453 set isworktree
[expr {[exec git rev-parse
--is-inside-work-tree] == "true"}]
454 set oldmainid
$mainheadid
456 if {$showlocalchanges} {
457 if {$mainheadid ne
$oldmainid} {
460 if {[commitinview
$mainheadid $curview]} {
465 if {$vcanopt($view)} {
466 set oldpos
$vposids($view)
467 set oldneg
$vnegids($view)
468 set revs
[parseviewrevs
$view $vrevs($view)]
472 # note: getting the delta when negative refs change is hard,
473 # and could require multiple git log invocations, so in that
474 # case we ask git log for all the commits (not just the delta)
475 if {$oldneg eq
$vnegids($view)} {
478 # take out positive refs that we asked for before or
479 # that we have already seen
481 if {[string length
$rev] == 40} {
482 if {[lsearch
-exact $oldpos $rev] < 0
483 && ![info exists varcid
($view,$rev)]} {
488 lappend
$newrevs $rev
491 if {$npos == 0} return
493 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
495 set args
[concat
$vflags($view) $revs --not $oldpos]
497 set args
$vorigargs($view)
500 set fd
[open
[concat | git log
--no-color -z --pretty=raw
--parents \
501 --boundary $args "--" $vfilelimit($view)] r
]
503 error_popup
"[mc "Error executing git log
:"] $err"
506 if {$viewactive($view) == 0} {
507 set startmsecs
[clock clicks
-milliseconds]
509 set i
[reg_instance
$fd]
510 lappend viewinstances
($view) $i
511 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
512 if {$tclencoding != {}} {
513 fconfigure
$fd -encoding $tclencoding
515 filerun
$fd [list getcommitlines
$fd $i $view 1]
516 incr viewactive
($view)
517 set viewcomplete
($view) 0
518 reset_pending_select
{}
519 nowbusy
$view "Reading"
525 proc reloadcommits
{} {
526 global curview viewcomplete selectedline currentid thickerline
527 global showneartags treediffs commitinterest cached_commitrow
531 if {$selectedline ne
{}} {
535 if {!$viewcomplete($curview)} {
536 stop_rev_list
$curview
540 catch
{unset currentid
}
541 catch
{unset thickerline
}
542 catch
{unset treediffs
}
549 catch
{unset commitinterest
}
550 catch
{unset cached_commitrow
}
551 catch
{unset targetid
}
557 # This makes a string representation of a positive integer which
558 # sorts as a string in numerical order
561 return [format
"%x" $n]
562 } elseif
{$n < 256} {
563 return [format
"x%.2x" $n]
564 } elseif
{$n < 65536} {
565 return [format
"y%.4x" $n]
567 return [format
"z%.8x" $n]
570 # Procedures used in reordering commits from git log (without
571 # --topo-order) into the order for display.
573 proc varcinit
{view
} {
574 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
575 global vtokmod varcmod vrowmod varcix vlastins
577 set varcstart
($view) {{}}
578 set vupptr
($view) {0}
579 set vdownptr
($view) {0}
580 set vleftptr
($view) {0}
581 set vbackptr
($view) {0}
582 set varctok
($view) {{}}
583 set varcrow
($view) {{}}
584 set vtokmod
($view) {}
587 set varcix
($view) {{}}
588 set vlastins
($view) {0}
591 proc resetvarcs
{view
} {
592 global varcid varccommits parents children vseedcount ordertok
594 foreach vid
[array names varcid
$view,*] {
599 # some commits might have children but haven't been seen yet
600 foreach vid
[array names children
$view,*] {
603 foreach va
[array names varccommits
$view,*] {
604 unset varccommits
($va)
606 foreach vd
[array names vseedcount
$view,*] {
607 unset vseedcount
($vd)
609 catch
{unset ordertok
}
612 # returns a list of the commits with no children
614 global vdownptr vleftptr varcstart
617 set a
[lindex
$vdownptr($v) 0]
619 lappend ret
[lindex
$varcstart($v) $a]
620 set a
[lindex
$vleftptr($v) $a]
625 proc newvarc
{view id
} {
626 global varcid varctok parents children vdatemode
627 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
628 global commitdata commitinfo vseedcount varccommits vlastins
630 set a
[llength
$varctok($view)]
632 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
633 if {![info exists commitinfo
($id)]} {
634 parsecommit
$id $commitdata($id) 1
636 set cdate
[lindex
$commitinfo($id) 4]
637 if {![string is integer
-strict $cdate]} {
640 if {![info exists vseedcount
($view,$cdate)]} {
641 set vseedcount
($view,$cdate) -1
643 set c
[incr vseedcount
($view,$cdate)]
644 set cdate
[expr {$cdate ^
0xffffffff}]
645 set tok
"s[strrep $cdate][strrep $c]"
650 if {[llength
$children($vid)] > 0} {
651 set kid
[lindex
$children($vid) end
]
652 set k
$varcid($view,$kid)
653 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
656 set tok
[lindex
$varctok($view) $k]
660 set i
[lsearch
-exact $parents($view,$ki) $id]
661 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
662 append tok
[strrep
$j]
664 set c
[lindex
$vlastins($view) $ka]
665 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
667 set b
[lindex
$vdownptr($view) $ka]
669 set b
[lindex
$vleftptr($view) $c]
671 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
673 set b
[lindex
$vleftptr($view) $c]
676 lset vdownptr
($view) $ka $a
677 lappend vbackptr
($view) 0
679 lset vleftptr
($view) $c $a
680 lappend vbackptr
($view) $c
682 lset vlastins
($view) $ka $a
683 lappend vupptr
($view) $ka
684 lappend vleftptr
($view) $b
686 lset vbackptr
($view) $b $a
688 lappend varctok
($view) $tok
689 lappend varcstart
($view) $id
690 lappend vdownptr
($view) 0
691 lappend varcrow
($view) {}
692 lappend varcix
($view) {}
693 set varccommits
($view,$a) {}
694 lappend vlastins
($view) 0
698 proc splitvarc
{p v
} {
699 global varcid varcstart varccommits varctok
700 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
702 set oa
$varcid($v,$p)
703 set ac
$varccommits($v,$oa)
704 set i
[lsearch
-exact $varccommits($v,$oa) $p]
706 set na
[llength
$varctok($v)]
707 # "%" sorts before "0"...
708 set tok
"[lindex $varctok($v) $oa]%[strrep $i]"
709 lappend varctok
($v) $tok
710 lappend varcrow
($v) {}
711 lappend varcix
($v) {}
712 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
713 set varccommits
($v,$na) [lrange
$ac $i end
]
714 lappend varcstart
($v) $p
715 foreach id
$varccommits($v,$na) {
716 set varcid
($v,$id) $na
718 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
719 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
720 lset vdownptr
($v) $oa $na
721 lset vlastins
($v) $oa 0
722 lappend vupptr
($v) $oa
723 lappend vleftptr
($v) 0
724 lappend vbackptr
($v) 0
725 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
726 lset vupptr
($v) $b $na
730 proc renumbervarc
{a v
} {
731 global parents children varctok varcstart varccommits
732 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
734 set t1
[clock clicks
-milliseconds]
740 if {[info exists isrelated
($a)]} {
742 set id
[lindex
$varccommits($v,$a) end
]
743 foreach p
$parents($v,$id) {
744 if {[info exists varcid
($v,$p)]} {
745 set isrelated
($varcid($v,$p)) 1
750 set b
[lindex
$vdownptr($v) $a]
753 set b
[lindex
$vleftptr($v) $a]
755 set a
[lindex
$vupptr($v) $a]
761 if {![info exists kidchanged
($a)]} continue
762 set id
[lindex
$varcstart($v) $a]
763 if {[llength
$children($v,$id)] > 1} {
764 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
767 set oldtok
[lindex
$varctok($v) $a]
768 if {!$vdatemode($v)} {
774 set kid
[last_real_child
$v,$id]
776 set k
$varcid($v,$kid)
777 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
780 set tok
[lindex
$varctok($v) $k]
784 set i
[lsearch
-exact $parents($v,$ki) $id]
785 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
786 append tok
[strrep
$j]
788 if {$tok eq
$oldtok} {
791 set id
[lindex
$varccommits($v,$a) end
]
792 foreach p
$parents($v,$id) {
793 if {[info exists varcid
($v,$p)]} {
794 set kidchanged
($varcid($v,$p)) 1
799 lset varctok
($v) $a $tok
800 set b
[lindex
$vupptr($v) $a]
802 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
805 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
808 set c
[lindex
$vbackptr($v) $a]
809 set d
[lindex
$vleftptr($v) $a]
811 lset vdownptr
($v) $b $d
813 lset vleftptr
($v) $c $d
816 lset vbackptr
($v) $d $c
818 if {[lindex
$vlastins($v) $b] == $a} {
819 lset vlastins
($v) $b $c
821 lset vupptr
($v) $a $ka
822 set c
[lindex
$vlastins($v) $ka]
824 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
826 set b
[lindex
$vdownptr($v) $ka]
828 set b
[lindex
$vleftptr($v) $c]
831 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
833 set b
[lindex
$vleftptr($v) $c]
836 lset vdownptr
($v) $ka $a
837 lset vbackptr
($v) $a 0
839 lset vleftptr
($v) $c $a
840 lset vbackptr
($v) $a $c
842 lset vleftptr
($v) $a $b
844 lset vbackptr
($v) $b $a
846 lset vlastins
($v) $ka $a
849 foreach id
[array names sortkids
] {
850 if {[llength
$children($v,$id)] > 1} {
851 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
855 set t2
[clock clicks
-milliseconds]
856 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
859 # Fix up the graph after we have found out that in view $v,
860 # $p (a commit that we have already seen) is actually the parent
861 # of the last commit in arc $a.
862 proc fix_reversal
{p a v
} {
863 global varcid varcstart varctok vupptr
865 set pa
$varcid($v,$p)
866 if {$p ne
[lindex
$varcstart($v) $pa]} {
868 set pa
$varcid($v,$p)
870 # seeds always need to be renumbered
871 if {[lindex
$vupptr($v) $pa] == 0 ||
872 [string compare
[lindex
$varctok($v) $a] \
873 [lindex
$varctok($v) $pa]] > 0} {
878 proc insertrow
{id p v
} {
879 global cmitlisted children parents varcid varctok vtokmod
880 global varccommits ordertok commitidx numcommits curview
881 global targetid targetrow
885 set cmitlisted
($vid) 1
886 set children
($vid) {}
887 set parents
($vid) [list
$p]
888 set a
[newvarc
$v $id]
890 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
893 lappend varccommits
($v,$a) $id
895 if {[llength
[lappend children
($vp) $id]] > 1} {
896 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
897 catch
{unset ordertok
}
899 fix_reversal
$p $a $v
901 if {$v == $curview} {
902 set numcommits
$commitidx($v)
904 if {[info exists targetid
]} {
905 if {![comes_before
$targetid $p]} {
912 proc insertfakerow
{id p
} {
913 global varcid varccommits parents children cmitlisted
914 global commitidx varctok vtokmod targetid targetrow curview numcommits
918 set i
[lsearch
-exact $varccommits($v,$a) $p]
920 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
923 set children
($v,$id) {}
924 set parents
($v,$id) [list
$p]
925 set varcid
($v,$id) $a
926 lappend children
($v,$p) $id
927 set cmitlisted
($v,$id) 1
928 set numcommits
[incr commitidx
($v)]
929 # note we deliberately don't update varcstart($v) even if $i == 0
930 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
932 if {[info exists targetid
]} {
933 if {![comes_before
$targetid $p]} {
941 proc removefakerow
{id
} {
942 global varcid varccommits parents children commitidx
943 global varctok vtokmod cmitlisted currentid selectedline
944 global targetid curview numcommits
947 if {[llength
$parents($v,$id)] != 1} {
948 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
951 set p
[lindex
$parents($v,$id) 0]
952 set a
$varcid($v,$id)
953 set i
[lsearch
-exact $varccommits($v,$a) $id]
955 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
959 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
960 unset parents
($v,$id)
961 unset children
($v,$id)
962 unset cmitlisted
($v,$id)
963 set numcommits
[incr commitidx
($v) -1]
964 set j
[lsearch
-exact $children($v,$p) $id]
966 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
969 if {[info exist currentid
] && $id eq
$currentid} {
973 if {[info exists targetid
] && $targetid eq
$id} {
980 proc first_real_child
{vp
} {
981 global children nullid nullid2
983 foreach id
$children($vp) {
984 if {$id ne
$nullid && $id ne
$nullid2} {
991 proc last_real_child
{vp
} {
992 global children nullid nullid2
994 set kids
$children($vp)
995 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
996 set id
[lindex
$kids $i]
997 if {$id ne
$nullid && $id ne
$nullid2} {
1004 proc vtokcmp
{v a b
} {
1005 global varctok varcid
1007 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1008 [lindex
$varctok($v) $varcid($v,$b)]]
1011 # This assumes that if lim is not given, the caller has checked that
1012 # arc a's token is less than $vtokmod($v)
1013 proc modify_arc
{v a
{lim
{}}} {
1014 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1017 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1020 set r
[lindex
$varcrow($v) $a]
1021 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1024 set vtokmod
($v) [lindex
$varctok($v) $a]
1026 if {$v == $curview} {
1027 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1028 set a
[lindex
$vupptr($v) $a]
1034 set lim
[llength
$varccommits($v,$a)]
1036 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1043 proc update_arcrows
{v
} {
1044 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1045 global varcid vrownum varcorder varcix varccommits
1046 global vupptr vdownptr vleftptr varctok
1047 global displayorder parentlist curview cached_commitrow
1049 if {$vrowmod($v) == $commitidx($v)} return
1050 if {$v == $curview} {
1051 if {[llength
$displayorder] > $vrowmod($v)} {
1052 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1053 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1055 catch
{unset cached_commitrow
}
1057 set narctot
[expr {[llength
$varctok($v)] - 1}]
1059 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1060 # go up the tree until we find something that has a row number,
1061 # or we get to a seed
1062 set a
[lindex
$vupptr($v) $a]
1065 set a
[lindex
$vdownptr($v) 0]
1068 set varcorder
($v) [list
$a]
1069 lset varcix
($v) $a 0
1070 lset varcrow
($v) $a 0
1074 set arcn
[lindex
$varcix($v) $a]
1075 if {[llength
$vrownum($v)] > $arcn + 1} {
1076 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1077 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1079 set row
[lindex
$varcrow($v) $a]
1083 incr row
[llength
$varccommits($v,$a)]
1084 # go down if possible
1085 set b
[lindex
$vdownptr($v) $a]
1087 # if not, go left, or go up until we can go left
1089 set b
[lindex
$vleftptr($v) $a]
1091 set a
[lindex
$vupptr($v) $a]
1097 lappend vrownum
($v) $row
1098 lappend varcorder
($v) $a
1099 lset varcix
($v) $a $arcn
1100 lset varcrow
($v) $a $row
1102 set vtokmod
($v) [lindex
$varctok($v) $p]
1104 set vrowmod
($v) $row
1105 if {[info exists currentid
]} {
1106 set selectedline
[rowofcommit
$currentid]
1110 # Test whether view $v contains commit $id
1111 proc commitinview
{id v
} {
1114 return [info exists varcid
($v,$id)]
1117 # Return the row number for commit $id in the current view
1118 proc rowofcommit
{id
} {
1119 global varcid varccommits varcrow curview cached_commitrow
1120 global varctok vtokmod
1123 if {![info exists varcid
($v,$id)]} {
1124 puts
"oops rowofcommit no arc for [shortids $id]"
1127 set a
$varcid($v,$id)
1128 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1131 if {[info exists cached_commitrow
($id)]} {
1132 return $cached_commitrow($id)
1134 set i
[lsearch
-exact $varccommits($v,$a) $id]
1136 puts
"oops didn't find commit [shortids $id] in arc $a"
1139 incr i
[lindex
$varcrow($v) $a]
1140 set cached_commitrow
($id) $i
1144 # Returns 1 if a is on an earlier row than b, otherwise 0
1145 proc comes_before
{a b
} {
1146 global varcid varctok curview
1149 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1150 ![info exists varcid
($v,$b)]} {
1153 if {$varcid($v,$a) != $varcid($v,$b)} {
1154 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1155 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1157 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1160 proc bsearch
{l elt
} {
1161 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1166 while {$hi - $lo > 1} {
1167 set mid
[expr {int
(($lo + $hi) / 2)}]
1168 set t
[lindex
$l $mid]
1171 } elseif
{$elt > $t} {
1180 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1181 proc make_disporder
{start end
} {
1182 global vrownum curview commitidx displayorder parentlist
1183 global varccommits varcorder parents vrowmod varcrow
1184 global d_valid_start d_valid_end
1186 if {$end > $vrowmod($curview)} {
1187 update_arcrows
$curview
1189 set ai
[bsearch
$vrownum($curview) $start]
1190 set start
[lindex
$vrownum($curview) $ai]
1191 set narc
[llength
$vrownum($curview)]
1192 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1193 set a
[lindex
$varcorder($curview) $ai]
1194 set l
[llength
$displayorder]
1195 set al
[llength
$varccommits($curview,$a)]
1196 if {$l < $r + $al} {
1198 set pad
[ntimes
[expr {$r - $l}] {}]
1199 set displayorder
[concat
$displayorder $pad]
1200 set parentlist
[concat
$parentlist $pad]
1201 } elseif
{$l > $r} {
1202 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1203 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1205 foreach id
$varccommits($curview,$a) {
1206 lappend displayorder
$id
1207 lappend parentlist
$parents($curview,$id)
1209 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1211 foreach id
$varccommits($curview,$a) {
1212 lset displayorder
$i $id
1213 lset parentlist
$i $parents($curview,$id)
1221 proc commitonrow
{row
} {
1224 set id
[lindex
$displayorder $row]
1226 make_disporder
$row [expr {$row + 1}]
1227 set id
[lindex
$displayorder $row]
1232 proc closevarcs
{v
} {
1233 global varctok varccommits varcid parents children
1234 global cmitlisted commitidx vtokmod
1236 set missing_parents
0
1238 set narcs
[llength
$varctok($v)]
1239 for {set a
1} {$a < $narcs} {incr a
} {
1240 set id
[lindex
$varccommits($v,$a) end
]
1241 foreach p
$parents($v,$id) {
1242 if {[info exists varcid
($v,$p)]} continue
1243 # add p as a new commit
1244 incr missing_parents
1245 set cmitlisted
($v,$p) 0
1246 set parents
($v,$p) {}
1247 if {[llength
$children($v,$p)] == 1 &&
1248 [llength
$parents($v,$id)] == 1} {
1251 set b
[newvarc
$v $p]
1253 set varcid
($v,$p) $b
1254 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1257 lappend varccommits
($v,$b) $p
1259 set scripts
[check_interest
$p $scripts]
1262 if {$missing_parents > 0} {
1263 foreach s
$scripts {
1269 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1270 # Assumes we already have an arc for $rwid.
1271 proc rewrite_commit
{v id rwid
} {
1272 global children parents varcid varctok vtokmod varccommits
1274 foreach ch
$children($v,$id) {
1275 # make $rwid be $ch's parent in place of $id
1276 set i
[lsearch
-exact $parents($v,$ch) $id]
1278 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1280 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1281 # add $ch to $rwid's children and sort the list if necessary
1282 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1283 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1284 $children($v,$rwid)]
1286 # fix the graph after joining $id to $rwid
1287 set a
$varcid($v,$ch)
1288 fix_reversal
$rwid $a $v
1289 # parentlist is wrong for the last element of arc $a
1290 # even if displayorder is right, hence the 3rd arg here
1291 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1295 # Mechanism for registering a command to be executed when we come
1296 # across a particular commit. To handle the case when only the
1297 # prefix of the commit is known, the commitinterest array is now
1298 # indexed by the first 4 characters of the ID. Each element is a
1299 # list of id, cmd pairs.
1300 proc interestedin
{id cmd
} {
1301 global commitinterest
1303 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1306 proc check_interest
{id scripts
} {
1307 global commitinterest
1309 set prefix
[string range
$id 0 3]
1310 if {[info exists commitinterest
($prefix)]} {
1312 foreach
{i
script} $commitinterest($prefix) {
1313 if {[string match
"$i*" $id]} {
1314 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1316 lappend newlist
$i $script
1319 if {$newlist ne
{}} {
1320 set commitinterest
($prefix) $newlist
1322 unset commitinterest
($prefix)
1328 proc getcommitlines
{fd inst view updating
} {
1329 global cmitlisted leftover
1330 global commitidx commitdata vdatemode
1331 global parents children curview hlview
1332 global idpending ordertok
1333 global varccommits varcid varctok vtokmod vfilelimit
1335 set stuff
[read $fd 500000]
1336 # git log doesn't terminate the last commit with a null...
1337 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1344 global commfd viewcomplete viewactive viewname
1345 global viewinstances
1347 set i
[lsearch
-exact $viewinstances($view) $inst]
1349 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1351 # set it blocking so we wait for the process to terminate
1352 fconfigure
$fd -blocking 1
1353 if {[catch
{close
$fd} err
]} {
1355 if {$view != $curview} {
1356 set fv
" for the \"$viewname($view)\" view"
1358 if {[string range
$err 0 4] == "usage"} {
1359 set err
"Gitk: error reading commits$fv:\
1360 bad arguments to git log."
1361 if {$viewname($view) eq
"Command line"} {
1363 " (Note: arguments to gitk are passed to git log\
1364 to allow selection of commits to be displayed.)"
1367 set err
"Error reading commits$fv: $err"
1371 if {[incr viewactive
($view) -1] <= 0} {
1372 set viewcomplete
($view) 1
1373 # Check if we have seen any ids listed as parents that haven't
1374 # appeared in the list
1378 if {$view == $curview} {
1387 set i
[string first
"\0" $stuff $start]
1389 append leftover
($inst) [string range
$stuff $start end
]
1393 set cmit
$leftover($inst)
1394 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1395 set leftover
($inst) {}
1397 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1399 set start
[expr {$i + 1}]
1400 set j
[string first
"\n" $cmit]
1403 if {$j >= 0 && [string match
"commit *" $cmit]} {
1404 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1405 if {[string match
{[-^
<>]*} $ids]} {
1406 switch
-- [string index
$ids 0] {
1412 set ids
[string range
$ids 1 end
]
1416 if {[string length
$id] != 40} {
1424 if {[string length
$shortcmit] > 80} {
1425 set shortcmit
"[string range $shortcmit 0 80]..."
1427 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1430 set id [lindex $ids 0]
1433 if {!$listed && $updating && ![info exists varcid($vid)] &&
1434 $vfilelimit($view) ne {}} {
1435 # git log doesn't rewrite parents
for unlisted commits
1436 # when doing path limiting, so work around that here
1437 # by working out the rewritten parent with git rev-list
1438 # and if we already know about it, using the rewritten
1439 # parent as a substitute parent for $id's children.
1441 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1442 $id -- $vfilelimit($view)]
1444 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1445 # use $rwid in place of $id
1446 rewrite_commit
$view $id $rwid
1453 if {[info exists varcid
($vid)]} {
1454 if {$cmitlisted($vid) ||
!$listed} continue
1458 set olds
[lrange
$ids 1 end
]
1462 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1463 set cmitlisted
($vid) $listed
1464 set parents
($vid) $olds
1465 if {![info exists children
($vid)]} {
1466 set children
($vid) {}
1467 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1468 set k
[lindex
$children($vid) 0]
1469 if {[llength
$parents($view,$k)] == 1 &&
1470 (!$vdatemode($view) ||
1471 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1472 set a
$varcid($view,$k)
1477 set a
[newvarc
$view $id]
1479 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1482 if {![info exists varcid
($vid)]} {
1484 lappend varccommits
($view,$a) $id
1485 incr commitidx
($view)
1490 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1492 if {[llength
[lappend children
($vp) $id]] > 1 &&
1493 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1494 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1496 catch
{unset ordertok
}
1498 if {[info exists varcid
($view,$p)]} {
1499 fix_reversal
$p $a $view
1505 set scripts
[check_interest
$id $scripts]
1509 global numcommits hlview
1511 if {$view == $curview} {
1512 set numcommits
$commitidx($view)
1515 if {[info exists hlview
] && $view == $hlview} {
1516 # we never actually get here...
1519 foreach s
$scripts {
1526 proc chewcommits
{} {
1527 global curview hlview viewcomplete
1528 global pending_select
1531 if {$viewcomplete($curview)} {
1532 global commitidx varctok
1533 global numcommits startmsecs
1535 if {[info exists pending_select
]} {
1537 reset_pending_select
{}
1539 if {[commitinview
$pending_select $curview]} {
1540 selectline
[rowofcommit
$pending_select] 1
1542 set row
[first_real_row
]
1546 if {$commitidx($curview) > 0} {
1547 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1548 #puts "overall $ms ms for $numcommits commits"
1549 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1551 show_status
[mc
"No commits selected"]
1558 proc readcommit
{id
} {
1559 if {[catch
{set contents
[exec git cat-file commit
$id]}]} return
1560 parsecommit
$id $contents 0
1563 proc parsecommit
{id contents listed
} {
1564 global commitinfo cdate
1573 set hdrend
[string first
"\n\n" $contents]
1575 # should never happen...
1576 set hdrend
[string length
$contents]
1578 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1579 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1580 foreach line
[split $header "\n"] {
1581 set tag
[lindex
$line 0]
1582 if {$tag == "author"} {
1583 set audate
[lindex
$line end-1
]
1584 set auname
[lrange
$line 1 end-2
]
1585 } elseif
{$tag == "committer"} {
1586 set comdate
[lindex
$line end-1
]
1587 set comname
[lrange
$line 1 end-2
]
1591 # take the first non-blank line of the comment as the headline
1592 set headline
[string trimleft
$comment]
1593 set i
[string first
"\n" $headline]
1595 set headline
[string range
$headline 0 $i]
1597 set headline
[string trimright
$headline]
1598 set i
[string first
"\r" $headline]
1600 set headline
[string trimright
[string range
$headline 0 $i]]
1603 # git log indents the comment by 4 spaces;
1604 # if we got this via git cat-file, add the indentation
1606 foreach line
[split $comment "\n"] {
1607 append newcomment
" "
1608 append newcomment
$line
1609 append newcomment
"\n"
1611 set comment
$newcomment
1613 if {$comdate != {}} {
1614 set cdate
($id) $comdate
1616 set commitinfo
($id) [list
$headline $auname $audate \
1617 $comname $comdate $comment]
1620 proc getcommit
{id
} {
1621 global commitdata commitinfo
1623 if {[info exists commitdata
($id)]} {
1624 parsecommit
$id $commitdata($id) 1
1627 if {![info exists commitinfo
($id)]} {
1628 set commitinfo
($id) [list
[mc
"No commit information available"]]
1634 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1635 # and are present in the current view.
1636 # This is fairly slow...
1637 proc longid
{prefix
} {
1638 global varcid curview
1641 foreach match
[array names varcid
"$curview,$prefix*"] {
1642 lappend ids
[lindex
[split $match ","] 1]
1648 global tagids idtags headids idheads tagobjid
1649 global otherrefids idotherrefs mainhead mainheadid
1650 global selecthead selectheadid
1652 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1655 set refd
[open
[list | git show-ref
-d] r
]
1656 while {[gets
$refd line
] >= 0} {
1657 if {[string index
$line 40] ne
" "} continue
1658 set id
[string range
$line 0 39]
1659 set ref
[string range
$line 41 end
]
1660 if {![string match
"refs/*" $ref]} continue
1661 set name
[string range
$ref 5 end
]
1662 if {[string match
"remotes/*" $name]} {
1663 if {![string match
"*/HEAD" $name]} {
1664 set headids
($name) $id
1665 lappend idheads
($id) $name
1667 } elseif
{[string match
"heads/*" $name]} {
1668 set name
[string range
$name 6 end
]
1669 set headids
($name) $id
1670 lappend idheads
($id) $name
1671 } elseif
{[string match
"tags/*" $name]} {
1672 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1673 # which is what we want since the former is the commit ID
1674 set name
[string range
$name 5 end
]
1675 if {[string match
"*^{}" $name]} {
1676 set name
[string range
$name 0 end-3
]
1678 set tagobjid
($name) $id
1680 set tagids
($name) $id
1681 lappend idtags
($id) $name
1683 set otherrefids
($name) $id
1684 lappend idotherrefs
($id) $name
1691 set mainheadid
[exec git rev-parse HEAD
]
1692 set thehead
[exec git symbolic-ref HEAD
]
1693 if {[string match
"refs/heads/*" $thehead]} {
1694 set mainhead
[string range
$thehead 11 end
]
1698 if {$selecthead ne
{}} {
1700 set selectheadid
[exec git rev-parse
--verify $selecthead]
1705 # skip over fake commits
1706 proc first_real_row
{} {
1707 global nullid nullid2 numcommits
1709 for {set row
0} {$row < $numcommits} {incr row
} {
1710 set id
[commitonrow
$row]
1711 if {$id ne
$nullid && $id ne
$nullid2} {
1718 # update things for a head moved to a child of its previous location
1719 proc movehead
{id name
} {
1720 global headids idheads
1722 removehead
$headids($name) $name
1723 set headids
($name) $id
1724 lappend idheads
($id) $name
1727 # update things when a head has been removed
1728 proc removehead
{id name
} {
1729 global headids idheads
1731 if {$idheads($id) eq
$name} {
1734 set i
[lsearch
-exact $idheads($id) $name]
1736 set idheads
($id) [lreplace
$idheads($id) $i $i]
1739 unset headids
($name)
1742 proc show_error
{w top msg
} {
1743 message
$w.m
-text $msg -justify center
-aspect 400
1744 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1745 button
$w.ok
-text [mc OK
] -command "destroy $top"
1746 pack
$w.ok
-side bottom
-fill x
1747 bind $top <Visibility
> "grab $top; focus $top"
1748 bind $top <Key-Return
> "destroy $top"
1752 proc error_popup msg
{
1756 show_error
$w $w $msg
1759 proc confirm_popup msg
{
1765 message
$w.m
-text $msg -justify center
-aspect 400
1766 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1767 button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1768 pack
$w.ok
-side left
-fill x
1769 button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1770 pack
$w.cancel
-side right
-fill x
1771 bind $w <Visibility
> "grab $w; focus $w"
1776 proc setoptions
{} {
1777 option add
*Panedwindow.showHandle
1 startupFile
1778 option add
*Panedwindow.sashRelief raised startupFile
1779 option add
*Button.font uifont startupFile
1780 option add
*Checkbutton.font uifont startupFile
1781 option add
*Radiobutton.font uifont startupFile
1782 option add
*Menu.font uifont startupFile
1783 option add
*Menubutton.font uifont startupFile
1784 option add
*Label.font uifont startupFile
1785 option add
*Message.font uifont startupFile
1786 option add
*Entry.font uifont startupFile
1789 # Make a menu and submenus.
1790 # m is the window name for the menu, items is the list of menu items to add.
1791 # Each item is a list {mc label type description options...}
1792 # mc is ignored; it's so we can put mc there to alert xgettext
1793 # label is the string that appears in the menu
1794 # type is cascade, command or radiobutton (should add checkbutton)
1795 # description depends on type; it's the sublist for cascade, the
1796 # command to invoke for command, or {variable value} for radiobutton
1797 proc makemenu
{m items
} {
1800 set name
[mc
[lindex
$i 1]]
1801 set type [lindex
$i 2]
1802 set thing
[lindex
$i 3]
1803 set params
[list
$type]
1805 set u
[string first
"&" [string map
{&& x
} $name]]
1806 lappend params
-label [string map
{&& & & {}} $name]
1808 lappend params
-underline $u
1813 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1814 lappend params
-menu $m.
$submenu
1817 lappend params
-command $thing
1820 lappend params
-variable [lindex
$thing 0] \
1821 -value [lindex
$thing 1]
1824 eval $m add
$params [lrange
$i 4 end
]
1825 if {$type eq
"cascade"} {
1826 makemenu
$m.
$submenu $thing
1831 # translate string and remove ampersands
1833 return [string map
{&& & & {}} [mc
$str]]
1836 proc makewindow
{} {
1837 global canv canv2 canv3 linespc charspc ctext cflist cscroll
1839 global findtype findtypemenu findloc findstring fstring geometry
1840 global entries sha1entry sha1string sha1but
1841 global diffcontextstring diffcontext
1843 global maincursor textcursor curtextcursor
1844 global rowctxmenu fakerowmenu mergemax wrapcomment
1845 global highlight_files gdttype
1846 global searchstring sstring
1847 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
1848 global headctxmenu progresscanv progressitem progresscoords statusw
1849 global fprogitem fprogcoord lastprogupdate progupdatepending
1850 global rprogitem rprogcoord rownumsel numcommits
1853 # The "mc" arguments here are purely so that xgettext
1854 # sees the following string as needing to be translated
1856 {mc
"File" cascade
{
1857 {mc
"Update" command updatecommits
-accelerator F5
}
1858 {mc
"Reload" command reloadcommits
}
1859 {mc
"Reread references" command rereadrefs
}
1860 {mc
"List references" command showrefs
}
1861 {mc
"Quit" command doquit
}
1863 {mc
"Edit" cascade
{
1864 {mc
"Preferences" command doprefs
}
1866 {mc
"View" cascade
{
1867 {mc
"New view..." command {newview
0}}
1868 {mc
"Edit view..." command editview
-state disabled
}
1869 {mc
"Delete view" command delview
-state disabled
}
1871 {mc
"All files" radiobutton
{selectedview
0} -command {showview
0}}
1873 {mc
"Help" cascade
{
1874 {mc
"About gitk" command about
}
1875 {mc
"Key bindings" command keys
}
1878 . configure
-menu .bar
1880 # the gui has upper and lower half, parts of a paned window.
1881 panedwindow .ctop
-orient vertical
1883 # possibly use assumed geometry
1884 if {![info exists geometry
(pwsash0
)]} {
1885 set geometry
(topheight
) [expr {15 * $linespc}]
1886 set geometry
(topwidth
) [expr {80 * $charspc}]
1887 set geometry
(botheight
) [expr {15 * $linespc}]
1888 set geometry
(botwidth
) [expr {50 * $charspc}]
1889 set geometry
(pwsash0
) "[expr {40 * $charspc}] 2"
1890 set geometry
(pwsash1
) "[expr {60 * $charspc}] 2"
1893 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
1894 frame .tf
-height $geometry(topheight
) -width $geometry(topwidth
)
1896 panedwindow .tf.histframe.pwclist
-orient horizontal
-sashpad 0 -handlesize 4
1898 # create three canvases
1899 set cscroll .tf.histframe.csb
1900 set canv .tf.histframe.pwclist.canv
1902 -selectbackground $selectbgcolor \
1903 -background $bgcolor -bd 0 \
1904 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
1905 .tf.histframe.pwclist add
$canv
1906 set canv2 .tf.histframe.pwclist.canv2
1908 -selectbackground $selectbgcolor \
1909 -background $bgcolor -bd 0 -yscrollincr $linespc
1910 .tf.histframe.pwclist add
$canv2
1911 set canv3 .tf.histframe.pwclist.canv3
1913 -selectbackground $selectbgcolor \
1914 -background $bgcolor -bd 0 -yscrollincr $linespc
1915 .tf.histframe.pwclist add
$canv3
1916 eval .tf.histframe.pwclist sash place
0 $geometry(pwsash0
)
1917 eval .tf.histframe.pwclist sash place
1 $geometry(pwsash1
)
1919 # a scroll bar to rule them
1920 scrollbar
$cscroll -command {allcanvs yview
} -highlightthickness 0
1921 pack
$cscroll -side right
-fill y
1922 bind .tf.histframe.pwclist
<Configure
> {resizeclistpanes
%W
%w
}
1923 lappend bglist
$canv $canv2 $canv3
1924 pack .tf.histframe.pwclist
-fill both
-expand 1 -side left
1926 # we have two button bars at bottom of top frame. Bar 1
1928 frame .tf.lbar
-height 15
1930 set sha1entry .tf.bar.sha1
1931 set entries
$sha1entry
1932 set sha1but .tf.bar.sha1label
1933 button
$sha1but -text [mc
"SHA1 ID: "] -state disabled
-relief flat \
1934 -command gotocommit
-width 8
1935 $sha1but conf
-disabledforeground [$sha1but cget
-foreground]
1936 pack .tf.bar.sha1label
-side left
1937 entry
$sha1entry -width 40 -font textfont
-textvariable sha1string
1938 trace add variable sha1string
write sha1change
1939 pack
$sha1entry -side left
-pady 2
1941 image create bitmap bm-left
-data {
1942 #define left_width 16
1943 #define left_height 16
1944 static unsigned char left_bits
[] = {
1945 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
1946 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
1947 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
1949 image create bitmap bm-right
-data {
1950 #define right_width 16
1951 #define right_height 16
1952 static unsigned char right_bits
[] = {
1953 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
1954 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
1955 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
1957 button .tf.bar.leftbut
-image bm-left
-command goback \
1958 -state disabled
-width 26
1959 pack .tf.bar.leftbut
-side left
-fill y
1960 button .tf.bar.rightbut
-image bm-right
-command goforw \
1961 -state disabled
-width 26
1962 pack .tf.bar.rightbut
-side left
-fill y
1964 label .tf.bar.rowlabel
-text [mc
"Row"]
1966 label .tf.bar.rownum
-width 7 -font textfont
-textvariable rownumsel \
1967 -relief sunken
-anchor e
1968 label .tf.bar.rowlabel2
-text "/"
1969 label .tf.bar.numcommits
-width 7 -font textfont
-textvariable numcommits \
1970 -relief sunken
-anchor e
1971 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
1974 trace add variable selectedline
write selectedline_change
1976 # Status label and progress bar
1977 set statusw .tf.bar.status
1978 label
$statusw -width 15 -relief sunken
1979 pack
$statusw -side left
-padx 5
1980 set h
[expr {[font metrics uifont
-linespace] + 2}]
1981 set progresscanv .tf.bar.progress
1982 canvas
$progresscanv -relief sunken
-height $h -borderwidth 2
1983 set progressitem
[$progresscanv create rect
-1 0 0 $h -fill green
]
1984 set fprogitem
[$progresscanv create rect
-1 0 0 $h -fill yellow
]
1985 set rprogitem
[$progresscanv create rect
-1 0 0 $h -fill red
]
1986 pack
$progresscanv -side right
-expand 1 -fill x
1987 set progresscoords
{0 0}
1990 bind $progresscanv <Configure
> adjustprogress
1991 set lastprogupdate
[clock clicks
-milliseconds]
1992 set progupdatepending
0
1994 # build up the bottom bar of upper window
1995 label .tf.lbar.flabel
-text "[mc "Find
"] "
1996 button .tf.lbar.fnext
-text [mc
"next"] -command {dofind
1 1}
1997 button .tf.lbar.fprev
-text [mc
"prev"] -command {dofind
-1 1}
1998 label .tf.lbar.flab2
-text " [mc "commit
"] "
1999 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2001 set gdttype
[mc
"containing:"]
2002 set gm
[tk_optionMenu .tf.lbar.gdttype gdttype \
2003 [mc
"containing:"] \
2004 [mc
"touching paths:"] \
2005 [mc
"adding/removing string:"]]
2006 trace add variable gdttype
write gdttype_change
2007 pack .tf.lbar.gdttype
-side left
-fill y
2010 set fstring .tf.lbar.findstring
2011 lappend entries
$fstring
2012 entry
$fstring -width 30 -font textfont
-textvariable findstring
2013 trace add variable findstring
write find_change
2014 set findtype
[mc
"Exact"]
2015 set findtypemenu
[tk_optionMenu .tf.lbar.findtype \
2016 findtype
[mc
"Exact"] [mc
"IgnCase"] [mc
"Regexp"]]
2017 trace add variable findtype
write findcom_change
2018 set findloc
[mc
"All fields"]
2019 tk_optionMenu .tf.lbar.findloc findloc
[mc
"All fields"] [mc
"Headline"] \
2020 [mc
"Comments"] [mc
"Author"] [mc
"Committer"]
2021 trace add variable findloc
write find_change
2022 pack .tf.lbar.findloc
-side right
2023 pack .tf.lbar.findtype
-side right
2024 pack
$fstring -side left
-expand 1 -fill x
2026 # Finish putting the upper half of the viewer together
2027 pack .tf.lbar
-in .tf
-side bottom
-fill x
2028 pack .tf.bar
-in .tf
-side bottom
-fill x
2029 pack .tf.histframe
-fill both
-side top
-expand 1
2031 .ctop paneconfigure .tf
-height $geometry(topheight
)
2032 .ctop paneconfigure .tf
-width $geometry(topwidth
)
2034 # now build up the bottom
2035 panedwindow .pwbottom
-orient horizontal
2037 # lower left, a text box over search bar, scroll bar to the right
2038 # if we know window height, then that will set the lower text height, otherwise
2039 # we set lower text height which will drive window height
2040 if {[info exists geometry
(main
)]} {
2041 frame .bleft
-width $geometry(botwidth
)
2043 frame .bleft
-width $geometry(botwidth
) -height $geometry(botheight
)
2049 button .bleft.top.search
-text [mc
"Search"] -command dosearch
2050 pack .bleft.top.search
-side left
-padx 5
2051 set sstring .bleft.top.sstring
2052 entry
$sstring -width 20 -font textfont
-textvariable searchstring
2053 lappend entries
$sstring
2054 trace add variable searchstring
write incrsearch
2055 pack
$sstring -side left
-expand 1 -fill x
2056 radiobutton .bleft.mid.
diff -text [mc
"Diff"] \
2057 -command changediffdisp
-variable diffelide
-value {0 0}
2058 radiobutton .bleft.mid.old
-text [mc
"Old version"] \
2059 -command changediffdisp
-variable diffelide
-value {0 1}
2060 radiobutton .bleft.mid.new
-text [mc
"New version"] \
2061 -command changediffdisp
-variable diffelide
-value {1 0}
2062 label .bleft.mid.labeldiffcontext
-text " [mc "Lines of context
"]: "
2063 pack .bleft.mid.
diff .bleft.mid.old .bleft.mid.new
-side left
2064 spinbox .bleft.mid.diffcontext
-width 5 -font textfont \
2065 -from 1 -increment 1 -to 10000000 \
2066 -validate all
-validatecommand "diffcontextvalidate %P" \
2067 -textvariable diffcontextstring
2068 .bleft.mid.diffcontext
set $diffcontext
2069 trace add variable diffcontextstring
write diffcontextchange
2070 lappend entries .bleft.mid.diffcontext
2071 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext
-side left
2072 checkbutton .bleft.mid.ignspace
-text [mc
"Ignore space change"] \
2073 -command changeignorespace
-variable ignorespace
2074 pack .bleft.mid.ignspace
-side left
-padx 5
2075 set ctext .bleft.bottom.ctext
2076 text
$ctext -background $bgcolor -foreground $fgcolor \
2077 -state disabled
-font textfont \
2078 -yscrollcommand scrolltext
-wrap none \
2079 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2081 $ctext conf
-tabstyle wordprocessor
2083 scrollbar .bleft.bottom.sb
-command "$ctext yview"
2084 scrollbar .bleft.bottom.sbhorizontal
-command "$ctext xview" -orient h \
2086 pack .bleft.top
-side top
-fill x
2087 pack .bleft.mid
-side top
-fill x
2088 grid
$ctext .bleft.bottom.sb
-sticky nsew
2089 grid .bleft.bottom.sbhorizontal
-sticky ew
2090 grid columnconfigure .bleft.bottom
0 -weight 1
2091 grid rowconfigure .bleft.bottom
0 -weight 1
2092 grid rowconfigure .bleft.bottom
1 -weight 0
2093 pack .bleft.bottom
-side top
-fill both
-expand 1
2094 lappend bglist
$ctext
2095 lappend fglist
$ctext
2097 $ctext tag conf comment
-wrap $wrapcomment
2098 $ctext tag conf filesep
-font textfontbold
-back "#aaaaaa"
2099 $ctext tag conf hunksep
-fore [lindex
$diffcolors 2]
2100 $ctext tag conf d0
-fore [lindex
$diffcolors 0]
2101 $ctext tag conf d1
-fore [lindex
$diffcolors 1]
2102 $ctext tag conf m0
-fore red
2103 $ctext tag conf m1
-fore blue
2104 $ctext tag conf m2
-fore green
2105 $ctext tag conf m3
-fore purple
2106 $ctext tag conf
m4 -fore brown
2107 $ctext tag conf m5
-fore "#009090"
2108 $ctext tag conf m6
-fore magenta
2109 $ctext tag conf m7
-fore "#808000"
2110 $ctext tag conf m8
-fore "#009000"
2111 $ctext tag conf m9
-fore "#ff0080"
2112 $ctext tag conf m10
-fore cyan
2113 $ctext tag conf m11
-fore "#b07070"
2114 $ctext tag conf m12
-fore "#70b0f0"
2115 $ctext tag conf m13
-fore "#70f0b0"
2116 $ctext tag conf m14
-fore "#f0b070"
2117 $ctext tag conf m15
-fore "#ff70b0"
2118 $ctext tag conf mmax
-fore darkgrey
2120 $ctext tag conf mresult
-font textfontbold
2121 $ctext tag conf msep
-font textfontbold
2122 $ctext tag conf found
-back yellow
2124 .pwbottom add .bleft
2125 .pwbottom paneconfigure .bleft
-width $geometry(botwidth
)
2130 radiobutton .bright.mode.
patch -text [mc
"Patch"] \
2131 -command reselectline
-variable cmitmode
-value "patch"
2132 radiobutton .bright.mode.tree
-text [mc
"Tree"] \
2133 -command reselectline
-variable cmitmode
-value "tree"
2134 grid .bright.mode.
patch .bright.mode.tree
-sticky ew
2135 pack .bright.mode
-side top
-fill x
2136 set cflist .bright.cfiles
2137 set indent
[font measure mainfont
"nn"]
2139 -selectbackground $selectbgcolor \
2140 -background $bgcolor -foreground $fgcolor \
2142 -tabs [list
$indent [expr {2 * $indent}]] \
2143 -yscrollcommand ".bright.sb set" \
2144 -cursor [. cget
-cursor] \
2145 -spacing1 1 -spacing3 1
2146 lappend bglist
$cflist
2147 lappend fglist
$cflist
2148 scrollbar .bright.sb
-command "$cflist yview"
2149 pack .bright.sb
-side right
-fill y
2150 pack
$cflist -side left
-fill both
-expand 1
2151 $cflist tag configure highlight \
2152 -background [$cflist cget
-selectbackground]
2153 $cflist tag configure bold
-font mainfontbold
2155 .pwbottom add .bright
2158 # restore window width & height if known
2159 if {[info exists geometry
(main
)]} {
2160 if {[scan
$geometry(main
) "%dx%d" w h
] >= 2} {
2161 if {$w > [winfo screenwidth .
]} {
2162 set w
[winfo screenwidth .
]
2164 if {$h > [winfo screenheight .
]} {
2165 set h
[winfo screenheight .
]
2167 wm geometry .
"${w}x$h"
2171 if {[tk windowingsystem
] eq
{aqua
}} {
2177 bind .pwbottom
<Configure
> {resizecdetpanes
%W
%w
}
2178 pack .ctop
-fill both
-expand 1
2179 bindall
<1> {selcanvline
%W
%x
%y
}
2180 #bindall <B1-Motion> {selcanvline %W %x %y}
2181 if {[tk windowingsystem
] == "win32"} {
2182 bind .
<MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
}
2183 bind $ctext <MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
; break }
2185 bindall
<ButtonRelease-4
> "allcanvs yview scroll -5 units"
2186 bindall
<ButtonRelease-5
> "allcanvs yview scroll 5 units"
2187 if {[tk windowingsystem
] eq
"aqua"} {
2188 bindall
<MouseWheel
> {
2189 set delta
[expr {- (%D
)}]
2190 allcanvs yview scroll
$delta units
2194 bindall
<2> "canvscan mark %W %x %y"
2195 bindall
<B2-Motion
> "canvscan dragto %W %x %y"
2196 bindkey
<Home
> selfirstline
2197 bindkey
<End
> sellastline
2198 bind .
<Key-Up
> "selnextline -1"
2199 bind .
<Key-Down
> "selnextline 1"
2200 bind .
<Shift-Key-Up
> "dofind -1 0"
2201 bind .
<Shift-Key-Down
> "dofind 1 0"
2202 bindkey
<Key-Right
> "goforw"
2203 bindkey
<Key-Left
> "goback"
2204 bind .
<Key-Prior
> "selnextpage -1"
2205 bind .
<Key-Next
> "selnextpage 1"
2206 bind .
<$M1B-Home> "allcanvs yview moveto 0.0"
2207 bind .
<$M1B-End> "allcanvs yview moveto 1.0"
2208 bind .
<$M1B-Key-Up> "allcanvs yview scroll -1 units"
2209 bind .
<$M1B-Key-Down> "allcanvs yview scroll 1 units"
2210 bind .
<$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2211 bind .
<$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2212 bindkey
<Key-Delete
> "$ctext yview scroll -1 pages"
2213 bindkey
<Key-BackSpace
> "$ctext yview scroll -1 pages"
2214 bindkey
<Key-space
> "$ctext yview scroll 1 pages"
2215 bindkey p
"selnextline -1"
2216 bindkey n
"selnextline 1"
2219 bindkey i
"selnextline -1"
2220 bindkey k
"selnextline 1"
2224 bindkey d
"$ctext yview scroll 18 units"
2225 bindkey u
"$ctext yview scroll -18 units"
2226 bindkey
/ {dofind
1 1}
2227 bindkey
<Key-Return
> {dofind
1 1}
2228 bindkey ?
{dofind
-1 1}
2230 bindkey
<F5
> updatecommits
2231 bind .
<$M1B-q> doquit
2232 bind .
<$M1B-f> {dofind
1 1}
2233 bind .
<$M1B-g> {dofind
1 0}
2234 bind .
<$M1B-r> dosearchback
2235 bind .
<$M1B-s> dosearch
2236 bind .
<$M1B-equal> {incrfont
1}
2237 bind .
<$M1B-plus> {incrfont
1}
2238 bind .
<$M1B-KP_Add> {incrfont
1}
2239 bind .
<$M1B-minus> {incrfont
-1}
2240 bind .
<$M1B-KP_Subtract> {incrfont
-1}
2241 wm protocol . WM_DELETE_WINDOW doquit
2242 bind .
<Destroy
> {stop_backends
}
2243 bind .
<Button-1
> "click %W"
2244 bind $fstring <Key-Return
> {dofind
1 1}
2245 bind $sha1entry <Key-Return
> {gotocommit
; break}
2246 bind $sha1entry <<PasteSelection>> clearsha1
2247 bind $cflist <1> {sel_flist %W %x %y; break}
2248 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2249 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2251 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2252 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2254 set maincursor [. cget -cursor]
2255 set textcursor [$ctext cget -cursor]
2256 set curtextcursor $textcursor
2258 set rowctxmenu .rowctxmenu
2259 makemenu $rowctxmenu {
2260 {mc "Diff this -> selected" command {diffvssel 0}}
2261 {mc "Diff selected -> this" command {diffvssel 1}}
2262 {mc "Make patch" command mkpatch}
2263 {mc "Create tag" command mktag}
2264 {mc "Write commit to file" command writecommit}
2265 {mc "Create new branch" command mkbranch}
2266 {mc "Cherry-pick this commit" command cherrypick}
2267 {mc "Reset HEAD branch to here" command resethead}
2269 $rowctxmenu configure -tearoff 0
2271 set fakerowmenu .fakerowmenu
2272 makemenu $fakerowmenu {
2273 {mc "Diff this -> selected" command {diffvssel 0}}
2274 {mc "Diff selected -> this" command {diffvssel 1}}
2275 {mc "Make patch" command mkpatch}
2277 $fakerowmenu configure -tearoff 0
2279 set headctxmenu .headctxmenu
2280 makemenu $headctxmenu {
2281 {mc "Check out this branch" command cobranch}
2282 {mc "Remove this branch" command rmbranch}
2284 $headctxmenu configure -tearoff 0
2287 set flist_menu .flistctxmenu
2288 makemenu $flist_menu {
2289 {mc "Highlight this too" command {flist_hl 0}}
2290 {mc "Highlight this only" command {flist_hl 1}}
2291 {mc "External diff" command {external_diff}}
2292 {mc "Blame parent commit" command {external_blame 1}}
2294 $flist_menu configure -tearoff 0
2297 set diff_menu .diffctxmenu
2298 makemenu $diff_menu {
2299 {mc "Run git gui blame on this line" command {external_blame_diff}}
2301 $diff_menu configure -tearoff 0
2304 # Windows sends all mouse wheel events to the current focused window, not
2305 # the one where the mouse hovers, so bind those events here and redirect
2306 # to the correct window
2307 proc windows_mousewheel_redirector {W X Y D} {
2308 global canv canv2 canv3
2309 set w [winfo containing -displayof $W $X $Y]
2311 set u [expr {$D < 0 ? 5 : -5}]
2312 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2313 allcanvs yview scroll $u units
2316 $w yview scroll $u units
2322 # Update row number label when selectedline changes
2323 proc selectedline_change {n1 n2 op} {
2324 global selectedline rownumsel
2326 if {$selectedline eq {}} {
2329 set rownumsel [expr {$selectedline + 1}]
2333 # mouse-2 makes all windows scan vertically, but only the one
2334 # the cursor is in scans horizontally
2335 proc canvscan {op w x y} {
2336 global canv canv2 canv3
2337 foreach c [list $canv $canv2 $canv3] {
2346 proc scrollcanv {cscroll f0 f1} {
2347 $cscroll set $f0 $f1
2352 # when we make a key binding for the toplevel, make sure
2353 # it doesn't get triggered when that key is pressed in the
2354 # find string entry widget.
2355 proc bindkey {ev script} {
2358 set escript [bind Entry $ev]
2359 if {$escript == {}} {
2360 set escript [bind Entry <Key>]
2362 foreach e $entries {
2363 bind $e $ev "$escript; break"
2367 # set the focus back to the toplevel for any click outside
2370 global ctext entries
2371 foreach e [concat $entries $ctext] {
2372 if {$w == $e} return
2377 # Adjust the progress bar for a change in requested extent or canvas size
2378 proc adjustprogress {} {
2379 global progresscanv progressitem progresscoords
2380 global fprogitem fprogcoord lastprogupdate progupdatepending
2381 global rprogitem rprogcoord
2383 set w [expr {[winfo width $progresscanv] - 4}]
2384 set x0 [expr {$w * [lindex $progresscoords 0]}]
2385 set x1 [expr {$w * [lindex $progresscoords 1]}]
2386 set h [winfo height $progresscanv]
2387 $progresscanv coords $progressitem $x0 0 $x1 $h
2388 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2389 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2390 set now [clock clicks -milliseconds]
2391 if {$now >= $lastprogupdate + 100} {
2392 set progupdatepending 0
2394 } elseif {!$progupdatepending} {
2395 set progupdatepending 1
2396 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2400 proc doprogupdate {} {
2401 global lastprogupdate progupdatepending
2403 if {$progupdatepending} {
2404 set progupdatepending 0
2405 set lastprogupdate [clock clicks -milliseconds]
2410 proc savestuff {w} {
2411 global canv canv2 canv3 mainfont textfont uifont tabstop
2412 global stuffsaved findmergefiles maxgraphpct
2413 global maxwidth showneartags showlocalchanges
2414 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2415 global cmitmode wrapcomment datetimeformat limitdiffs
2416 global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor
2417 global autoselect extdifftool perfile_attrs
2419 if {$stuffsaved} return
2420 if {![winfo viewable .]} return
2422 set f [open "~/.gitk-new" w]
2423 puts $f [list set mainfont $mainfont]
2424 puts $f [list set textfont $textfont]
2425 puts $f [list set uifont $uifont]
2426 puts $f [list set tabstop $tabstop]
2427 puts $f [list set findmergefiles $findmergefiles]
2428 puts $f [list set maxgraphpct $maxgraphpct]
2429 puts $f [list set maxwidth $maxwidth]
2430 puts $f [list set cmitmode $cmitmode]
2431 puts $f [list set wrapcomment $wrapcomment]
2432 puts $f [list set autoselect $autoselect]
2433 puts $f [list set showneartags $showneartags]
2434 puts $f [list set showlocalchanges $showlocalchanges]
2435 puts $f [list set datetimeformat $datetimeformat]
2436 puts $f [list set limitdiffs $limitdiffs]
2437 puts $f [list set bgcolor $bgcolor]
2438 puts $f [list set fgcolor $fgcolor]
2439 puts $f [list set colors $colors]
2440 puts $f [list set diffcolors $diffcolors]
2441 puts $f [list set diffcontext $diffcontext]
2442 puts $f [list set selectbgcolor $selectbgcolor]
2443 puts $f [list set extdifftool $extdifftool]
2444 puts $f [list set perfile_attrs $perfile_attrs]
2446 puts $f "set geometry(main) [wm geometry .]"
2447 puts $f "set geometry(topwidth) [winfo width .tf]"
2448 puts $f "set geometry(topheight) [winfo height .tf]"
2449 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2450 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2451 puts $f "set geometry(botwidth) [winfo width .bleft]"
2452 puts $f "set geometry(botheight) [winfo height .bleft]"
2454 puts -nonewline $f "set permviews {"
2455 for {set v 0} {$v < $nextviewnum} {incr v} {
2456 if {$viewperm($v)} {
2457 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2462 file rename -force "~/.gitk-new" "~/.gitk"
2467 proc resizeclistpanes {win w} {
2469 if {[info exists oldwidth($win)]} {
2470 set s0 [$win sash coord 0]
2471 set s1 [$win sash coord 1]
2473 set sash0 [expr {int($w/2 - 2)}]
2474 set sash1 [expr {int($w*5/6 - 2)}]
2476 set factor [expr {1.0 * $w / $oldwidth($win)}]
2477 set sash0 [expr {int($factor * [lindex $s0 0])}]
2478 set sash1 [expr {int($factor * [lindex $s1 0])}]
2482 if {$sash1 < $sash0 + 20} {
2483 set sash1 [expr {$sash0 + 20}]
2485 if {$sash1 > $w - 10} {
2486 set sash1 [expr {$w - 10}]
2487 if {$sash0 > $sash1 - 20} {
2488 set sash0 [expr {$sash1 - 20}]
2492 $win sash place 0 $sash0 [lindex $s0 1]
2493 $win sash place 1 $sash1 [lindex $s1 1]
2495 set oldwidth($win) $w
2498 proc resizecdetpanes {win w} {
2500 if {[info exists oldwidth($win)]} {
2501 set s0 [$win sash coord 0]
2503 set sash0 [expr {int($w*3/4 - 2)}]
2505 set factor [expr {1.0 * $w / $oldwidth($win)}]
2506 set sash0 [expr {int($factor * [lindex $s0 0])}]
2510 if {$sash0 > $w - 15} {
2511 set sash0 [expr {$w - 15}]
2514 $win sash place 0 $sash0 [lindex $s0 1]
2516 set oldwidth($win) $w
2519 proc allcanvs args {
2520 global canv canv2 canv3
2526 proc bindall {event action} {
2527 global canv canv2 canv3
2528 bind $canv $event $action
2529 bind $canv2 $event $action
2530 bind $canv3 $event $action
2536 if {[winfo exists $w]} {
2541 wm title $w [mc "About gitk"]
2542 message $w.m -text [mc "
2543 Gitk - a commit viewer for git
2545 Copyright © 2005-2008 Paul Mackerras
2547 Use and redistribute under the terms of the GNU General Public License"] \
2548 -justify center -aspect 400 -border 2 -bg white -relief groove
2549 pack $w.m -side top -fill x -padx 2 -pady 2
2550 button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2551 pack $w.ok -side bottom
2552 bind $w <Visibility> "focus $w.ok"
2553 bind $w <Key-Escape> "destroy $w"
2554 bind $w <Key-Return> "destroy $w"
2559 if {[winfo exists $w]} {
2563 if {[tk windowingsystem] eq {aqua}} {
2569 wm title $w [mc "Gitk key bindings"]
2570 message $w.m -text "
2571 [mc "Gitk key bindings:"]
2573 [mc "<%s-Q> Quit" $M1T]
2574 [mc "<Home> Move to first commit"]
2575 [mc "<End> Move to last commit"]
2576 [mc "<Up>, p, i Move up one commit"]
2577 [mc "<Down>, n, k Move down one commit"]
2578 [mc "<Left>, z, j Go back in history list"]
2579 [mc "<Right>, x, l Go forward in history list"]
2580 [mc "<PageUp> Move up one page in commit list"]
2581 [mc "<PageDown> Move down one page in commit list"]
2582 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2583 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2584 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2585 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2586 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2587 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2588 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2589 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2590 [mc "<Delete>, b Scroll diff view up one page"]
2591 [mc "<Backspace> Scroll diff view up one page"]
2592 [mc "<Space> Scroll diff view down one page"]
2593 [mc "u Scroll diff view up 18 lines"]
2594 [mc "d Scroll diff view down 18 lines"]
2595 [mc "<%s-F> Find" $M1T]
2596 [mc "<%s-G> Move to next find hit" $M1T]
2597 [mc "<Return> Move to next find hit"]
2598 [mc "/ Move to next find hit, or redo find"]
2599 [mc "? Move to previous find hit"]
2600 [mc "f Scroll diff view to next file"]
2601 [mc "<%s-S> Search for next hit in diff view" $M1T]
2602 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2603 [mc "<%s-KP+> Increase font size" $M1T]
2604 [mc "<%s-plus> Increase font size" $M1T]
2605 [mc "<%s-KP-> Decrease font size" $M1T]
2606 [mc "<%s-minus> Decrease font size" $M1T]
2609 -justify left -bg white -border 2 -relief groove
2610 pack $w.m -side top -fill both -padx 2 -pady 2
2611 button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2612 pack $w.ok -side bottom
2613 bind $w <Visibility> "focus $w.ok"
2614 bind $w <Key-Escape> "destroy $w"
2615 bind $w <Key-Return> "destroy $w"
2618 # Procedures for manipulating the file list window at the
2619 # bottom right of the overall window.
2621 proc treeview {w l openlevs} {
2622 global treecontents treediropen treeheight treeparent treeindex
2632 set treecontents() {}
2633 $w conf -state normal
2635 while {[string range $f 0 $prefixend] ne $prefix} {
2636 if {$lev <= $openlevs} {
2637 $w mark set e:$treeindex($prefix) "end -1c"
2638 $w mark gravity e:$treeindex($prefix) left
2640 set treeheight($prefix) $ht
2641 incr ht [lindex $htstack end]
2642 set htstack [lreplace $htstack end end]
2643 set prefixend [lindex $prefendstack end]
2644 set prefendstack [lreplace $prefendstack end end]
2645 set prefix [string range $prefix 0 $prefixend]
2648 set tail [string range $f [expr {$prefixend+1}] end]
2649 while {[set slash [string first "/" $tail]] >= 0} {
2652 lappend prefendstack $prefixend
2653 incr prefixend [expr {$slash + 1}]
2654 set d [string range $tail 0 $slash]
2655 lappend treecontents($prefix) $d
2656 set oldprefix $prefix
2658 set treecontents($prefix) {}
2659 set treeindex($prefix) [incr ix]
2660 set treeparent($prefix) $oldprefix
2661 set tail [string range $tail [expr {$slash+1}] end]
2662 if {$lev <= $openlevs} {
2664 set treediropen($prefix) [expr {$lev < $openlevs}]
2665 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
2666 $w mark set d:$ix "end -1c"
2667 $w mark gravity d:$ix left
2669 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2671 $w image create end -align center -image $bm -padx 1 \
2673 $w insert end $d [highlight_tag $prefix]
2674 $w mark set s:$ix "end -1c"
2675 $w mark gravity s:$ix left
2680 if {$lev <= $openlevs} {
2683 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2685 $w insert end $tail [highlight_tag $f]
2687 lappend treecontents($prefix) $tail
2690 while {$htstack ne {}} {
2691 set treeheight($prefix) $ht
2692 incr ht [lindex $htstack end]
2693 set htstack [lreplace $htstack end end]
2694 set prefixend [lindex $prefendstack end]
2695 set prefendstack [lreplace $prefendstack end end]
2696 set prefix [string range $prefix 0 $prefixend]
2698 $w conf -state disabled
2701 proc linetoelt {l} {
2702 global treeheight treecontents
2707 foreach e $treecontents($prefix) {
2712 if {[string index $e end] eq "/"} {
2713 set n $treeheight($prefix$e)
2725 proc highlight_tree {y prefix} {
2726 global treeheight treecontents cflist
2728 foreach e $treecontents($prefix) {
2730 if {[highlight_tag $path] ne {}} {
2731 $cflist tag add bold $y.0 "$y.0 lineend"
2734 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
2735 set y [highlight_tree $y $path]
2741 proc treeclosedir {w dir} {
2742 global treediropen treeheight treeparent treeindex
2744 set ix $treeindex($dir)
2745 $w conf -state normal
2746 $w delete s:$ix e:$ix
2747 set treediropen($dir) 0
2748 $w image configure a:$ix -image tri-rt
2749 $w conf -state disabled
2750 set n [expr {1 - $treeheight($dir)}]
2751 while {$dir ne {}} {
2752 incr treeheight($dir) $n
2753 set dir $treeparent($dir)
2757 proc treeopendir {w dir} {
2758 global treediropen treeheight treeparent treecontents treeindex
2760 set ix $treeindex($dir)
2761 $w conf -state normal
2762 $w image configure a:$ix -image tri-dn
2763 $w mark set e:$ix s:$ix
2764 $w mark gravity e:$ix right
2767 set n [llength $treecontents($dir)]
2768 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
2771 incr treeheight($x) $n
2773 foreach e $treecontents($dir) {
2775 if {[string index $e end] eq "/"} {
2776 set iy $treeindex($de)
2777 $w mark set d:$iy e:$ix
2778 $w mark gravity d:$iy left
2779 $w insert e:$ix $str
2780 set treediropen($de) 0
2781 $w image create e:$ix -align center -image tri-rt -padx 1 \
2783 $w insert e:$ix $e [highlight_tag $de]
2784 $w mark set s:$iy e:$ix
2785 $w mark gravity s:$iy left
2786 set treeheight($de) 1
2788 $w insert e:$ix $str
2789 $w insert e:$ix $e [highlight_tag $de]
2792 $w mark gravity e:$ix right
2793 $w conf -state disabled
2794 set treediropen($dir) 1
2795 set top [lindex [split [$w index @0,0] .] 0]
2796 set ht [$w cget -height]
2797 set l [lindex [split [$w index s:$ix] .] 0]
2800 } elseif {$l + $n + 1 > $top + $ht} {
2801 set top [expr {$l + $n + 2 - $ht}]
2809 proc treeclick {w x y} {
2810 global treediropen cmitmode ctext cflist cflist_top
2812 if {$cmitmode ne "tree"} return
2813 if {![info exists cflist_top]} return
2814 set l [lindex [split [$w index "@$x,$y"] "."] 0]
2815 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
2816 $cflist tag add highlight $l.0 "$l.0 lineend"
2822 set e [linetoelt $l]
2823 if {[string index $e end] ne "/"} {
2825 } elseif {$treediropen($e)} {
2832 proc setfilelist {id} {
2833 global treefilelist cflist
2835 treeview $cflist $treefilelist($id) 0
2838 image create bitmap tri-rt -background black -foreground blue -data {
2839 #define tri-rt_width 13
2840 #define tri-rt_height 13
2841 static unsigned char tri-rt_bits[] = {
2842 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
2843 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
2846 #define tri-rt-mask_width 13
2847 #define tri-rt-mask_height 13
2848 static unsigned char tri-rt-mask_bits[] = {
2849 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
2850 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
2853 image create bitmap tri-dn -background black -foreground blue -data {
2854 #define tri-dn_width 13
2855 #define tri-dn_height 13
2856 static unsigned char tri-dn_bits[] = {
2857 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
2858 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2861 #define tri-dn-mask_width 13
2862 #define tri-dn-mask_height 13
2863 static unsigned char tri-dn-mask_bits[] = {
2864 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
2865 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
2869 image create bitmap reficon-T -background black -foreground yellow -data {
2870 #define tagicon_width 13
2871 #define tagicon_height 9
2872 static unsigned char tagicon_bits[] = {
2873 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
2874 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
2876 #define tagicon-mask_width 13
2877 #define tagicon-mask_height 9
2878 static unsigned char tagicon-mask_bits[] = {
2879 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
2880 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
2883 #define headicon_width 13
2884 #define headicon_height 9
2885 static unsigned char headicon_bits[] = {
2886 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
2887 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
2890 #define headicon-mask_width 13
2891 #define headicon-mask_height 9
2892 static unsigned char headicon-mask_bits[] = {
2893 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
2894 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
2896 image create bitmap reficon-H -background black -foreground green \
2897 -data $rectdata -maskdata $rectmask
2898 image create bitmap reficon-o -background black -foreground "#ddddff" \
2899 -data $rectdata -maskdata $rectmask
2901 proc init_flist {first} {
2902 global cflist cflist_top difffilestart
2904 $cflist conf -state normal
2905 $cflist delete 0.0 end
2907 $cflist insert end $first
2909 $cflist tag add highlight 1.0 "1.0 lineend"
2911 catch {unset cflist_top}
2913 $cflist conf -state disabled
2914 set difffilestart {}
2917 proc highlight_tag {f} {
2918 global highlight_paths
2920 foreach p $highlight_paths {
2921 if {[string match $p $f]} {
2928 proc highlight_filelist {} {
2929 global cmitmode cflist
2931 $cflist conf -state normal
2932 if {$cmitmode ne "tree"} {
2933 set end [lindex [split [$cflist index end] .] 0]
2934 for {set l 2} {$l < $end} {incr l} {
2935 set line [$cflist get $l.0 "$l.0 lineend"]
2936 if {[highlight_tag $line] ne {}} {
2937 $cflist tag add bold $l.0 "$l.0 lineend"
2943 $cflist conf -state disabled
2946 proc unhighlight_filelist {} {
2949 $cflist conf -state normal
2950 $cflist tag remove bold 1.0 end
2951 $cflist conf -state disabled
2954 proc add_flist {fl} {
2957 $cflist conf -state normal
2959 $cflist insert end "\n"
2960 $cflist insert end $f [highlight_tag $f]
2962 $cflist conf -state disabled
2965 proc sel_flist {w x y} {
2966 global ctext difffilestart cflist cflist_top cmitmode
2968 if {$cmitmode eq "tree"} return
2969 if {![info exists cflist_top]} return
2970 set l [lindex [split [$w index "@$x,$y"] "."] 0]
2971 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
2972 $cflist tag add highlight $l.0 "$l.0 lineend"
2977 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
2981 proc pop_flist_menu {w X Y x y} {
2982 global ctext cflist cmitmode flist_menu flist_menu_file
2983 global treediffs diffids
2986 set l [lindex [split [$w index "@$x,$y"] "."] 0]
2988 if {$cmitmode eq "tree"} {
2989 set e [linetoelt $l]
2990 if {[string index $e end] eq "/"} return
2992 set e [lindex $treediffs($diffids) [expr {$l-2}]]
2994 set flist_menu_file $e
2995 set xdiffstate "normal"
2996 if {$cmitmode eq "tree"} {
2997 set xdiffstate "disabled"
2999 # Disable "External diff" item in tree mode
3000 $flist_menu entryconf 2 -state $xdiffstate
3001 tk_popup $flist_menu $X $Y
3004 proc find_ctext_fileinfo {line} {
3005 global ctext_file_names ctext_file_lines
3007 set ok [bsearch $ctext_file_lines $line]
3008 set tline [lindex $ctext_file_lines $ok]
3010 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3013 return [list [lindex $ctext_file_names $ok] $tline]
3017 proc pop_diff_menu {w X Y x y} {
3018 global ctext diff_menu flist_menu_file
3019 global diff_menu_txtpos diff_menu_line
3020 global diff_menu_filebase
3023 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3024 set diff_menu_line [lindex $diff_menu_txtpos 0]
3025 set f [find_ctext_fileinfo $diff_menu_line]
3026 if {$f eq {}} return
3027 set flist_menu_file [lindex $f 0]
3028 set diff_menu_filebase [lindex $f 1]
3029 tk_popup $diff_menu $X $Y
3032 proc flist_hl {only} {
3033 global flist_menu_file findstring gdttype
3035 set x [shellquote $flist_menu_file]
3036 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3039 append findstring " " $x
3041 set gdttype [mc "touching paths:"]
3044 proc save_file_from_commit {filename output what} {
3047 if {[catch {exec git show $filename -- > $output} err]} {
3048 if {[string match "fatal: bad revision *" $err]} {
3051 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3057 proc external_diff_get_one_file {diffid filename diffdir} {
3058 global nullid nullid2 nullfile
3061 if {$diffid == $nullid} {
3062 set difffile [file join [file dirname $gitdir] $filename]
3063 if {[file exists $difffile]} {
3068 if {$diffid == $nullid2} {
3069 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3070 return [save_file_from_commit :$filename $difffile index]
3072 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3073 return [save_file_from_commit $diffid:$filename $difffile \
3077 proc external_diff {} {
3078 global gitktmpdir nullid nullid2
3079 global flist_menu_file
3082 global gitdir extdifftool
3084 if {[llength $diffids] == 1} {
3085 # no reference commit given
3086 set diffidto [lindex $diffids 0]
3087 if {$diffidto eq $nullid} {
3088 # diffing working copy with index
3089 set diffidfrom $nullid2
3090 } elseif {$diffidto eq $nullid2} {
3091 # diffing index with HEAD
3092 set diffidfrom "HEAD"
3094 # use first parent commit
3095 global parentlist selectedline
3096 set diffidfrom [lindex $parentlist $selectedline 0]
3099 set diffidfrom [lindex $diffids 0]
3100 set diffidto [lindex $diffids 1]
3103 # make sure that several diffs wont collide
3104 if {![info exists gitktmpdir]} {
3105 set gitktmpdir [file join [file dirname $gitdir] \
3106 [format ".gitk-tmp.%s" [pid]]]
3107 if {[catch {file mkdir $gitktmpdir} err]} {
3108 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3115 set diffdir [file join $gitktmpdir $diffnum]
3116 if {[catch {file mkdir $diffdir} err]} {
3117 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3121 # gather files to diff
3122 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3123 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3125 if {$difffromfile ne {} && $difftofile ne {}} {
3126 set cmd [concat | [shellsplit $extdifftool] \
3127 [list $difffromfile $difftofile]]
3128 if {[catch {set fl [open $cmd r]} err]} {
3129 file delete -force $diffdir
3130 error_popup "$extdifftool: [mc "command failed:"] $err"
3132 fconfigure $fl -blocking 0
3133 filerun $fl [list delete_at_eof $fl $diffdir]
3138 proc find_hunk_blamespec {base line} {
3141 # Find and parse the hunk header
3142 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3143 if {$s_lix eq {}} return
3145 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3146 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3147 s_line old_specs osz osz1 new_line nsz]} {
3151 # base lines for the parents
3152 set base_lines [list $new_line]
3153 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3154 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3155 old_spec old_line osz]} {
3158 lappend base_lines $old_line
3161 # Now scan the lines to determine offset within the hunk
3163 set max_parent [expr {[llength $base_lines]-2}]
3165 set s_lno [lindex [split $s_lix "."] 0]
3167 for {set i $line} {$i > $s_lno} {incr i -1} {
3168 set c_line [$ctext get $i.0 "$i.0 + 1 lines"]
3169 # Determine if the line is removed
3170 set chunk [string range $c_line 0 $max_parent]
3171 set removed_idx [string first "-" $chunk]
3172 # Choose a parent index
3173 if {$parent eq {}} {
3174 if {$removed_idx >= 0} {
3175 set parent $removed_idx
3177 set unchanged_idx [string first " " $chunk]
3178 if {$unchanged_idx >= 0} {
3179 set parent $unchanged_idx
3181 # blame the current commit
3186 # then count other lines that belong to it
3188 set code [string index $c_line $parent]
3189 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3193 if {$removed_idx < 0} {
3199 if {$parent eq {}} { set parent -1 }
3201 incr dline [lindex $base_lines $parent]
3202 return [list $parent $dline]
3205 proc external_blame_diff {} {
3206 global currentid diffmergeid cmitmode
3207 global diff_menu_txtpos diff_menu_line
3208 global diff_menu_filebase flist_menu_file
3210 if {$cmitmode eq "tree"} {
3212 set line [expr {$diff_menu_line - $diff_menu_filebase - 1}]
3214 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3216 set parent_idx [lindex $hinfo 0]
3217 set line [lindex $hinfo 1]
3224 external_blame $parent_idx $line
3227 proc external_blame {parent_idx {line {}}} {
3228 global flist_menu_file
3229 global nullid nullid2
3230 global parentlist selectedline currentid
3232 if {$parent_idx > 0} {
3233 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3235 set base_commit $currentid
3238 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3239 error_popup [mc "No such commit"]
3243 set cmdline [list git gui blame]
3244 if {$line ne {} && $line > 1} {
3245 lappend cmdline "--line=$line"
3247 lappend cmdline $base_commit $flist_menu_file
3248 if {[catch {eval exec $cmdline &} err]} {
3249 error_popup "[mc "git gui blame: command failed:"] $err"
3253 # delete $dir when we see eof on $f (presumably because the child has exited)
3254 proc delete_at_eof {f dir} {
3255 while {[gets $f line] >= 0} {}
3257 if {[catch {close $f} err]} {
3258 error_popup "[mc "External diff viewer failed:"] $err"
3260 file delete -force $dir
3266 # Functions for adding and removing shell-type quoting
3268 proc shellquote {str} {
3269 if {![string match "*\['\"\\ \t]*" $str]} {
3272 if {![string match "*\['\"\\]*" $str]} {
3275 if {![string match "*'*" $str]} {
3278 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3281 proc shellarglist {l} {
3287 append str [shellquote $a]
3292 proc shelldequote {str} {
3297 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3298 append ret [string range $str $used end]
3299 set used [string length $str]
3302 set first [lindex $first 0]
3303 set ch [string index $str $first]
3304 if {$first > $used} {
3305 append ret [string range $str $used [expr {$first - 1}]]
3308 if {$ch eq " " || $ch eq "\t"} break
3311 set first [string first "'" $str $used]
3313 error "unmatched single-quote"
3315 append ret [string range $str $used [expr {$first - 1}]]
3320 if {$used >= [string length $str]} {
3321 error "trailing backslash"
3323 append ret [string index $str $used]
3328 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3329 error "unmatched double-quote"
3331 set first [lindex $first 0]
3332 set ch [string index $str $first]
3333 if {$first > $used} {
3334 append ret [string range $str $used [expr {$first - 1}]]
3337 if {$ch eq "\""} break
3339 append ret [string index $str $used]
3343 return [list $used $ret]
3346 proc shellsplit {str} {
3349 set str [string trimleft $str]
3350 if {$str eq {}} break
3351 set dq [shelldequote $str]
3352 set n [lindex $dq 0]
3353 set word [lindex $dq 1]
3354 set str [string range $str $n end]
3360 # Code to implement multiple views
3362 proc newview {ishighlight} {
3363 global nextviewnum newviewname newviewperm newishighlight
3364 global newviewargs revtreeargs viewargscmd newviewargscmd curview
3366 set newishighlight $ishighlight
3368 if {[winfo exists $top]} {
3372 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3373 set newviewperm($nextviewnum) 0
3374 set newviewargs($nextviewnum) [shellarglist $revtreeargs]
3375 set newviewargscmd($nextviewnum) $viewargscmd($curview)
3376 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3381 global viewname viewperm newviewname newviewperm
3382 global viewargs newviewargs viewargscmd newviewargscmd
3384 set top .gitkvedit-$curview
3385 if {[winfo exists $top]} {
3389 set newviewname($curview) $viewname($curview)
3390 set newviewperm($curview) $viewperm($curview)
3391 set newviewargs($curview) [shellarglist $viewargs($curview)]
3392 set newviewargscmd($curview) $viewargscmd($curview)
3393 vieweditor $top $curview "Gitk: edit view $viewname($curview)"
3396 proc vieweditor {top n title} {
3397 global newviewname newviewperm viewfiles bgcolor
3400 wm title $top $title
3401 label $top.nl -text [mc "Name"]
3402 entry $top.name -width 20 -textvariable newviewname($n)
3403 grid $top.nl $top.name -sticky w -pady 5
3404 checkbutton $top.perm -text [mc "Remember this view"] \
3405 -variable newviewperm($n)
3406 grid $top.perm - -pady 5 -sticky w
3407 message $top.al -aspect 1000 \
3408 -text [mc "Commits to include (arguments to git log):"]
3409 grid $top.al - -sticky w -pady 5
3410 entry $top.args -width 50 -textvariable newviewargs($n) \
3411 -background $bgcolor
3412 grid $top.args - -sticky ew -padx 5
3414 message $top.ac -aspect 1000 \
3415 -text [mc "Command to generate more commits to include:"]
3416 grid $top.ac - -sticky w -pady 5
3417 entry $top.argscmd -width 50 -textvariable newviewargscmd($n) \
3419 grid $top.argscmd - -sticky ew -padx 5
3421 message $top.l -aspect 1000 \
3422 -text [mc "Enter files and directories to include, one per line:"]
3423 grid $top.l - -sticky w
3424 text $top.t -width 40 -height 10 -background $bgcolor -font uifont
3425 if {[info exists viewfiles($n)]} {
3426 foreach f $viewfiles($n) {
3427 $top.t insert end $f
3428 $top.t insert end "\n"
3430 $top.t delete {end - 1c} end
3431 $top.t mark set insert 0.0
3433 grid $top.t - -sticky ew -padx 5
3435 button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
3436 button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
3437 grid $top.buts.ok $top.buts.can
3438 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3439 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3440 grid $top.buts - -pady 10 -sticky ew
3444 proc doviewmenu {m first cmd op argv} {
3445 set nmenu [$m index end]
3446 for {set i $first} {$i <= $nmenu} {incr i} {
3447 if {[$m entrycget $i -command] eq $cmd} {
3448 eval $m $op $i $argv
3454 proc allviewmenus {n op args} {
3457 doviewmenu .bar.view 5 [list showview $n] $op $args
3458 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
3461 proc newviewok {top n} {
3462 global nextviewnum newviewperm newviewname newishighlight
3463 global viewname viewfiles viewperm selectedview curview
3464 global viewargs newviewargs viewargscmd newviewargscmd viewhlmenu
3467 set newargs [shellsplit $newviewargs($n)]
3469 error_popup "[mc "Error in commit selection arguments:"] $err"
3475 foreach f [split [$top.t get 0.0 end] "\n"] {
3476 set ft [string trim $f]
3481 if {![info exists viewfiles($n)]} {
3482 # creating a new view
3484 set viewname($n) $newviewname($n)
3485 set viewperm($n) $newviewperm($n)
3486 set viewfiles($n) $files
3487 set viewargs($n) $newargs
3488 set viewargscmd($n) $newviewargscmd($n)
3490 if {!$newishighlight} {
3493 run addvhighlight $n
3496 # editing an existing view
3497 set viewperm($n) $newviewperm($n)
3498 if {$newviewname($n) ne $viewname($n)} {
3499 set viewname($n) $newviewname($n)
3500 doviewmenu .bar.view 5 [list showview $n] \
3501 entryconf [list -label $viewname($n)]
3502 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
3503 # entryconf [list -label $viewname($n) -value $viewname($n)]
3505 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
3506 $newviewargscmd($n) ne $viewargscmd($n)} {
3507 set viewfiles($n) $files
3508 set viewargs($n) $newargs
3509 set viewargscmd($n) $newviewargscmd($n)
3510 if {$curview == $n} {
3515 catch {destroy $top}
3519 global curview viewperm hlview selectedhlview
3521 if {$curview == 0} return
3522 if {[info exists hlview] && $hlview == $curview} {
3523 set selectedhlview [mc "None"]
3526 allviewmenus $curview delete
3527 set viewperm($curview) 0
3531 proc addviewmenu {n} {
3532 global viewname viewhlmenu
3534 .bar.view add radiobutton -label $viewname($n) \
3535 -command [list showview $n] -variable selectedview -value $n
3536 #$viewhlmenu add radiobutton -label $viewname($n) \
3537 # -command [list addvhighlight $n] -variable selectedhlview
3541 global curview cached_commitrow ordertok
3542 global displayorder parentlist rowidlist rowisopt rowfinal
3543 global colormap rowtextx nextcolor canvxmax
3544 global numcommits viewcomplete
3545 global selectedline currentid canv canvy0
3547 global pending_select mainheadid
3550 global hlview selectedhlview commitinterest
3552 if {$n == $curview} return
3554 set ymax [lindex [$canv cget -scrollregion] 3]
3555 set span [$canv yview]
3556 set ytop [expr {[lindex $span 0] * $ymax}]
3557 set ybot [expr {[lindex $span 1] * $ymax}]
3558 set yscreen [expr {($ybot - $ytop) / 2}]
3559 if {$selectedline ne {}} {
3560 set selid $currentid
3561 set y [yc $selectedline]
3562 if {$ytop < $y && $y < $ybot} {
3563 set yscreen [expr {$y - $ytop}]
3565 } elseif {[info exists pending_select]} {
3566 set selid $pending_select
3567 unset pending_select
3571 catch {unset treediffs}
3573 if {[info exists hlview] && $hlview == $n} {
3575 set selectedhlview [mc "None"]
3577 catch {unset commitinterest}
3578 catch {unset cached_commitrow}
3579 catch {unset ordertok}
3583 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
3584 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
3587 if {![info exists viewcomplete($n)]} {
3597 set numcommits $commitidx($n)
3599 catch {unset colormap}
3600 catch {unset rowtextx}
3602 set canvxmax [$canv cget -width]
3608 if {$selid ne {} && [commitinview $selid $n]} {
3609 set row [rowofcommit $selid]
3610 # try to get the selected row in the same position on the screen
3611 set ymax [lindex [$canv cget -scrollregion] 3]
3612 set ytop [expr {[yc $row] - $yscreen}]
3616 set yf [expr {$ytop * 1.0 / $ymax}]
3618 allcanvs yview moveto $yf
3622 } elseif {!$viewcomplete($n)} {
3623 reset_pending_select $selid
3625 reset_pending_select {}
3627 if {[commitinview $pending_select $curview]} {
3628 selectline [rowofcommit $pending_select] 1
3630 set row [first_real_row]
3631 if {$row < $numcommits} {
3636 if {!$viewcomplete($n)} {
3637 if {$numcommits == 0} {
3638 show_status [mc "Reading commits..."]
3640 } elseif {$numcommits == 0} {
3641 show_status [mc "No commits selected"]
3645 # Stuff relating to the highlighting facility
3647 proc ishighlighted {id} {
3648 global vhighlights fhighlights nhighlights rhighlights
3650 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
3651 return $nhighlights($id)
3653 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
3654 return $vhighlights($id)
3656 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
3657 return $fhighlights($id)
3659 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
3660 return $rhighlights($id)
3665 proc bolden {row font} {
3666 global canv linehtag selectedline boldrows
3668 lappend boldrows $row
3669 $canv itemconf $linehtag($row) -font $font
3670 if {$row == $selectedline} {
3672 set t [eval $canv create rect [$canv bbox $linehtag($row)] \
3673 -outline {{}} -tags secsel \
3674 -fill [$canv cget -selectbackground]]
3679 proc bolden_name {row font} {
3680 global canv2 linentag selectedline boldnamerows
3682 lappend boldnamerows $row
3683 $canv2 itemconf $linentag($row) -font $font
3684 if {$row == $selectedline} {
3685 $canv2 delete secsel
3686 set t [eval $canv2 create rect [$canv2 bbox $linentag($row)] \
3687 -outline {{}} -tags secsel \
3688 -fill [$canv2 cget -selectbackground]]
3697 foreach row $boldrows {
3698 if {![ishighlighted [commitonrow $row]]} {
3699 bolden $row mainfont
3701 lappend stillbold $row
3704 set boldrows $stillbold
3707 proc addvhighlight {n} {
3708 global hlview viewcomplete curview vhl_done commitidx
3710 if {[info exists hlview]} {
3714 if {$n != $curview && ![info exists viewcomplete($n)]} {
3717 set vhl_done $commitidx($hlview)
3718 if {$vhl_done > 0} {
3723 proc delvhighlight {} {
3724 global hlview vhighlights
3726 if {![info exists hlview]} return
3728 catch {unset vhighlights}
3732 proc vhighlightmore {} {
3733 global hlview vhl_done commitidx vhighlights curview
3735 set max $commitidx($hlview)
3736 set vr [visiblerows]
3737 set r0 [lindex $vr 0]
3738 set r1 [lindex $vr 1]
3739 for {set i $vhl_done} {$i < $max} {incr i} {
3740 set id [commitonrow $i $hlview]
3741 if {[commitinview $id $curview]} {
3742 set row [rowofcommit $id]
3743 if {$r0 <= $row && $row <= $r1} {
3744 if {![highlighted $row]} {
3745 bolden $row mainfontbold
3747 set vhighlights($id) 1
3755 proc askvhighlight {row id} {
3756 global hlview vhighlights iddrawn
3758 if {[commitinview $id $hlview]} {
3759 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
3760 bolden $row mainfontbold
3762 set vhighlights($id) 1
3764 set vhighlights($id) 0
3768 proc hfiles_change {} {
3769 global highlight_files filehighlight fhighlights fh_serial
3770 global highlight_paths gdttype
3772 if {[info exists filehighlight]} {
3773 # delete previous highlights
3774 catch {close $filehighlight}
3776 catch {unset fhighlights}
3778 unhighlight_filelist
3780 set highlight_paths {}
3781 after cancel do_file_hl $fh_serial
3783 if {$highlight_files ne {}} {
3784 after 300 do_file_hl $fh_serial
3788 proc gdttype_change {name ix op} {
3789 global gdttype highlight_files findstring findpattern
3792 if {$findstring ne {}} {
3793 if {$gdttype eq [mc "containing:"]} {
3794 if {$highlight_files ne {}} {
3795 set highlight_files {}
3800 if {$findpattern ne {}} {
3804 set highlight_files $findstring
3809 # enable/disable findtype/findloc menus too
3812 proc find_change {name ix op} {
3813 global gdttype findstring highlight_files
3816 if {$gdttype eq [mc "containing:"]} {
3819 if {$highlight_files ne $findstring} {
3820 set highlight_files $findstring
3827 proc findcom_change args {
3828 global nhighlights boldnamerows
3829 global findpattern findtype findstring gdttype
3832 # delete previous highlights, if any
3833 foreach row $boldnamerows {
3834 bolden_name $row mainfont
3837 catch {unset nhighlights}
3840 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
3842 } elseif {$findtype eq [mc "Regexp"]} {
3843 set findpattern $findstring
3845 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
3847 set findpattern "*$e*"
3851 proc makepatterns {l} {
3854 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
3855 if {[string index $ee end] eq "/"} {
3865 proc do_file_hl {serial} {
3866 global highlight_files filehighlight highlight_paths gdttype fhl_list
3868 if {$gdttype eq [mc "touching paths:"]} {
3869 if {[catch {set paths [shellsplit $highlight_files]}]} return
3870 set highlight_paths [makepatterns $paths]
3872 set gdtargs [concat -- $paths]
3873 } elseif {$gdttype eq [mc "adding/removing string:"]} {
3874 set gdtargs [list "-S$highlight_files"]
3876 # must be "containing:", i.e. we're searching commit info
3879 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
3880 set filehighlight [open $cmd r+]
3881 fconfigure $filehighlight -blocking 0
3882 filerun $filehighlight readfhighlight
3888 proc flushhighlights {} {
3889 global filehighlight fhl_list
3891 if {[info exists filehighlight]} {
3893 puts $filehighlight ""
3894 flush $filehighlight
3898 proc askfilehighlight {row id} {
3899 global filehighlight fhighlights fhl_list
3901 lappend fhl_list $id
3902 set fhighlights($id) -1
3903 puts $filehighlight $id
3906 proc readfhighlight {} {
3907 global filehighlight fhighlights curview iddrawn
3908 global fhl_list find_dirn
3910 if {![info exists filehighlight]} {
3914 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
3915 set line [string trim $line]
3916 set i [lsearch -exact $fhl_list $line]
3917 if {$i < 0} continue
3918 for {set j 0} {$j < $i} {incr j} {
3919 set id [lindex $fhl_list $j]
3920 set fhighlights($id) 0
3922 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
3923 if {$line eq {}} continue
3924 if {![commitinview $line $curview]} continue
3925 set row [rowofcommit $line]
3926 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
3927 bolden $row mainfontbold
3929 set fhighlights($line) 1
3931 if {[eof $filehighlight]} {
3933 puts "oops, git diff-tree died"
3934 catch {close $filehighlight}
3938 if {[info exists find_dirn]} {
3944 proc doesmatch {f} {
3945 global findtype findpattern
3947 if {$findtype eq [mc "Regexp"]} {
3948 return [regexp $findpattern $f]
3949 } elseif {$findtype eq [mc "IgnCase"]} {
3950 return [string match -nocase $findpattern $f]
3952 return [string match $findpattern $f]
3956 proc askfindhighlight {row id} {
3957 global nhighlights commitinfo iddrawn
3959 global markingmatches
3961 if {![info exists commitinfo($id)]} {
3964 set info $commitinfo($id)
3966 set fldtypes [list [mc Headline] [mc Author] [mc Date] [mc Committer] [mc CDate] [mc Comments]]
3967 foreach f $info ty $fldtypes {
3968 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
3970 if {$ty eq [mc "Author"]} {
3977 if {$isbold && [info exists iddrawn($id)]} {
3978 if {![ishighlighted $id]} {
3979 bolden $row mainfontbold
3981 bolden_name $row mainfontbold
3984 if {$markingmatches} {
3985 markrowmatches $row $id
3988 set nhighlights($id) $isbold
3991 proc markrowmatches {row id} {
3992 global canv canv2 linehtag linentag commitinfo findloc
3994 set headline [lindex $commitinfo($id) 0]
3995 set author [lindex $commitinfo($id) 1]
3996 $canv delete match$row
3997 $canv2 delete match$row
3998 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
3999 set m [findmatches $headline]
4001 markmatches $canv $row $headline $linehtag($row) $m \
4002 [$canv itemcget $linehtag($row) -font] $row
4005 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4006 set m [findmatches $author]
4008 markmatches $canv2 $row $author $linentag($row) $m \
4009 [$canv2 itemcget $linentag($row) -font] $row
4014 proc vrel_change {name ix op} {
4015 global highlight_related
4018 if {$highlight_related ne [mc "None"]} {
4023 # prepare for testing whether commits are descendents or ancestors of a
4024 proc rhighlight_sel {a} {
4025 global descendent desc_todo ancestor anc_todo
4026 global highlight_related
4028 catch {unset descendent}
4029 set desc_todo [list $a]
4030 catch {unset ancestor}
4031 set anc_todo [list $a]
4032 if {$highlight_related ne [mc "None"]} {
4038 proc rhighlight_none {} {
4041 catch {unset rhighlights}
4045 proc is_descendent {a} {
4046 global curview children descendent desc_todo
4049 set la [rowofcommit $a]
4053 for {set i 0} {$i < [llength $todo]} {incr i} {
4054 set do [lindex $todo $i]
4055 if {[rowofcommit $do] < $la} {
4056 lappend leftover $do
4059 foreach nk $children($v,$do) {
4060 if {![info exists descendent($nk)]} {
4061 set descendent($nk) 1
4069 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4073 set descendent($a) 0
4074 set desc_todo $leftover
4077 proc is_ancestor {a} {
4078 global curview parents ancestor anc_todo
4081 set la [rowofcommit $a]
4085 for {set i 0} {$i < [llength $todo]} {incr i} {
4086 set do [lindex $todo $i]
4087 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4088 lappend leftover $do
4091 foreach np $parents($v,$do) {
4092 if {![info exists ancestor($np)]} {
4101 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4106 set anc_todo $leftover
4109 proc askrelhighlight {row id} {
4110 global descendent highlight_related iddrawn rhighlights
4111 global selectedline ancestor
4113 if {$selectedline eq {}} return
4115 if {$highlight_related eq [mc "Descendant"] ||
4116 $highlight_related eq [mc "Not descendant"]} {
4117 if {![info exists descendent($id)]} {
4120 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4123 } elseif {$highlight_related eq [mc "Ancestor"] ||
4124 $highlight_related eq [mc "Not ancestor"]} {
4125 if {![info exists ancestor($id)]} {
4128 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4132 if {[info exists iddrawn($id)]} {
4133 if {$isbold && ![ishighlighted $id]} {
4134 bolden $row mainfontbold
4137 set rhighlights($id) $isbold
4140 # Graph layout functions
4142 proc shortids {ids} {
4145 if {[llength $id] > 1} {
4146 lappend res [shortids $id]
4147 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4148 lappend res [string range $id 0 7]
4159 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4160 if {($n & $mask) != 0} {
4161 set ret [concat $ret $o]
4163 set o [concat $o $o]
4168 proc ordertoken {id} {
4169 global ordertok curview varcid varcstart varctok curview parents children
4170 global nullid nullid2
4172 if {[info exists ordertok($id)]} {
4173 return $ordertok($id)
4178 if {[info exists varcid($curview,$id)]} {
4179 set a $varcid($curview,$id)
4180 set p [lindex $varcstart($curview) $a]
4182 set p [lindex $children($curview,$id) 0]
4184 if {[info exists ordertok($p)]} {
4185 set tok $ordertok($p)
4188 set id [first_real_child $curview,$p]
4191 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4194 if {[llength $parents($curview,$id)] == 1} {
4195 lappend todo [list $p {}]
4197 set j [lsearch -exact $parents($curview,$id) $p]
4199 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4201 lappend todo [list $p [strrep $j]]
4204 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4205 set p [lindex $todo $i 0]
4206 append tok [lindex $todo $i 1]
4207 set ordertok($p) $tok
4209 set ordertok($origid) $tok
4213 # Work out where id should go in idlist so that order-token
4214 # values increase from left to right
4215 proc idcol {idlist id {i 0}} {
4216 set t [ordertoken $id]
4220 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
4221 if {$i > [llength $idlist]} {
4222 set i [llength $idlist]
4224 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
4227 if {$t > [ordertoken [lindex $idlist $i]]} {
4228 while {[incr i] < [llength $idlist] &&
4229 $t >= [ordertoken [lindex $idlist $i]]} {}
4235 proc initlayout {} {
4236 global rowidlist rowisopt rowfinal displayorder parentlist
4237 global numcommits canvxmax canv
4239 global colormap rowtextx
4248 set canvxmax [$canv cget -width]
4249 catch {unset colormap}
4250 catch {unset rowtextx}
4254 proc setcanvscroll {} {
4255 global canv canv2 canv3 numcommits linespc canvxmax canvy0
4256 global lastscrollset lastscrollrows
4258 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
4259 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
4260 $canv2 conf -scrollregion [list 0 0 0 $ymax]
4261 $canv3 conf -scrollregion [list 0 0 0 $ymax]
4262 set lastscrollset [clock clicks -milliseconds]
4263 set lastscrollrows $numcommits
4266 proc visiblerows {} {
4267 global canv numcommits linespc
4269 set ymax [lindex [$canv cget -scrollregion] 3]
4270 if {$ymax eq {} || $ymax == 0} return
4272 set y0 [expr {int([lindex $f 0] * $ymax)}]
4273 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
4277 set y1 [expr {int([lindex $f 1] * $ymax)}]
4278 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
4279 if {$r1 >= $numcommits} {
4280 set r1 [expr {$numcommits - 1}]
4282 return [list $r0 $r1]
4285 proc layoutmore {} {
4286 global commitidx viewcomplete curview
4287 global numcommits pending_select curview
4288 global lastscrollset lastscrollrows
4290 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
4291 [clock clicks -milliseconds] - $lastscrollset > 500} {
4294 if {[info exists pending_select] &&
4295 [commitinview $pending_select $curview]} {
4297 selectline [rowofcommit $pending_select] 1
4302 proc doshowlocalchanges {} {
4303 global curview mainheadid
4305 if {$mainheadid eq {}} return
4306 if {[commitinview $mainheadid $curview]} {
4309 interestedin $mainheadid dodiffindex
4313 proc dohidelocalchanges {} {
4314 global nullid nullid2 lserial curview
4316 if {[commitinview $nullid $curview]} {
4317 removefakerow $nullid
4319 if {[commitinview $nullid2 $curview]} {
4320 removefakerow $nullid2
4325 # spawn off a process to do git diff-index --cached HEAD
4326 proc dodiffindex {} {
4327 global lserial showlocalchanges
4330 if {!$showlocalchanges || !$isworktree} return
4332 set fd [open "|git diff-index --cached HEAD" r]
4333 fconfigure $fd -blocking 0
4334 set i [reg_instance $fd]
4335 filerun $fd [list readdiffindex $fd $lserial $i]
4338 proc readdiffindex {fd serial inst} {
4339 global mainheadid nullid nullid2 curview commitinfo commitdata lserial
4342 if {[gets $fd line] < 0} {
4348 # we only need to see one line and we don't really care what it says...
4351 if {$serial != $lserial} {
4355 # now see if there are any local changes not checked in to the index
4356 set fd [open "|git diff-files" r]
4357 fconfigure $fd -blocking 0
4358 set i [reg_instance $fd]
4359 filerun $fd [list readdifffiles $fd $serial $i]
4361 if {$isdiff && ![commitinview $nullid2 $curview]} {
4362 # add the line for the changes in the index to the graph
4363 set hl [mc "Local changes checked in to index but not committed"]
4364 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
4365 set commitdata($nullid2) "\n $hl\n"
4366 if {[commitinview $nullid $curview]} {
4367 removefakerow $nullid
4369 insertfakerow $nullid2 $mainheadid
4370 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
4371 removefakerow $nullid2
4376 proc readdifffiles {fd serial inst} {
4377 global mainheadid nullid nullid2 curview
4378 global commitinfo commitdata lserial
4381 if {[gets $fd line] < 0} {
4387 # we only need to see one line and we don't really care what it says...
4390 if {$serial != $lserial} {
4394 if {$isdiff && ![commitinview $nullid $curview]} {
4395 # add the line for the local diff to the graph
4396 set hl [mc "Local uncommitted changes, not checked in to index"]
4397 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
4398 set commitdata($nullid) "\n $hl\n"
4399 if {[commitinview $nullid2 $curview]} {
4404 insertfakerow $nullid $p
4405 } elseif {!$isdiff && [commitinview $nullid $curview]} {
4406 removefakerow $nullid
4411 proc nextuse {id row} {
4412 global curview children
4414 if {[info exists children($curview,$id)]} {
4415 foreach kid $children($curview,$id) {
4416 if {![commitinview $kid $curview]} {
4419 if {[rowofcommit $kid] > $row} {
4420 return [rowofcommit $kid]
4424 if {[commitinview $id $curview]} {
4425 return [rowofcommit $id]
4430 proc prevuse {id row} {
4431 global curview children
4434 if {[info exists children($curview,$id)]} {
4435 foreach kid $children($curview,$id) {
4436 if {![commitinview $kid $curview]} break
4437 if {[rowofcommit $kid] < $row} {
4438 set ret [rowofcommit $kid]
4445 proc make_idlist {row} {
4446 global displayorder parentlist uparrowlen downarrowlen mingaplen
4447 global commitidx curview children
4449 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
4453 set ra [expr {$row - $downarrowlen}]
4457 set rb [expr {$row + $uparrowlen}]
4458 if {$rb > $commitidx($curview)} {
4459 set rb $commitidx($curview)
4461 make_disporder $r [expr {$rb + 1}]
4463 for {} {$r < $ra} {incr r} {
4464 set nextid [lindex $displayorder [expr {$r + 1}]]
4465 foreach p [lindex $parentlist $r] {
4466 if {$p eq $nextid} continue
4467 set rn [nextuse $p $r]
4469 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
4470 lappend ids [list [ordertoken $p] $p]
4474 for {} {$r < $row} {incr r} {
4475 set nextid [lindex $displayorder [expr {$r + 1}]]
4476 foreach p [lindex $parentlist $r] {
4477 if {$p eq $nextid} continue
4478 set rn [nextuse $p $r]
4479 if {$rn < 0 || $rn >= $row} {
4480 lappend ids [list [ordertoken $p] $p]
4484 set id [lindex $displayorder $row]
4485 lappend ids [list [ordertoken $id] $id]
4487 foreach p [lindex $parentlist $r] {
4488 set firstkid [lindex $children($curview,$p) 0]
4489 if {[rowofcommit $firstkid] < $row} {
4490 lappend ids [list [ordertoken $p] $p]
4494 set id [lindex $displayorder $r]
4496 set firstkid [lindex $children($curview,$id) 0]
4497 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
4498 lappend ids [list [ordertoken $id] $id]
4503 foreach idx [lsort -unique $ids] {
4504 lappend idlist [lindex $idx 1]
4509 proc rowsequal {a b} {
4510 while {[set i [lsearch -exact $a {}]] >= 0} {
4511 set a [lreplace $a $i $i]
4513 while {[set i [lsearch -exact $b {}]] >= 0} {
4514 set b [lreplace $b $i $i]
4516 return [expr {$a eq $b}]
4519 proc makeupline {id row rend col} {
4520 global rowidlist uparrowlen downarrowlen mingaplen
4522 for {set r $rend} {1} {set r $rstart} {
4523 set rstart [prevuse $id $r]
4524 if {$rstart < 0} return
4525 if {$rstart < $row} break
4527 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
4528 set rstart [expr {$rend - $uparrowlen - 1}]
4530 for {set r $rstart} {[incr r] <= $row} {} {
4531 set idlist [lindex $rowidlist $r]
4532 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
4533 set col [idcol $idlist $id $col]
4534 lset rowidlist $r [linsert $idlist $col $id]
4540 proc layoutrows {row endrow} {
4541 global rowidlist rowisopt rowfinal displayorder
4542 global uparrowlen downarrowlen maxwidth mingaplen
4543 global children parentlist
4544 global commitidx viewcomplete curview
4546 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
4549 set rm1 [expr {$row - 1}]
4550 foreach id [lindex $rowidlist $rm1] {
4555 set final [lindex $rowfinal $rm1]
4557 for {} {$row < $endrow} {incr row} {
4558 set rm1 [expr {$row - 1}]
4559 if {$rm1 < 0 || $idlist eq {}} {
4560 set idlist [make_idlist $row]
4563 set id [lindex $displayorder $rm1]
4564 set col [lsearch -exact $idlist $id]
4565 set idlist [lreplace $idlist $col $col]
4566 foreach p [lindex $parentlist $rm1] {
4567 if {[lsearch -exact $idlist $p] < 0} {
4568 set col [idcol $idlist $p $col]
4569 set idlist [linsert $idlist $col $p]
4570 # if not the first child, we have to insert a line going up
4571 if {$id ne [lindex $children($curview,$p) 0]} {
4572 makeupline $p $rm1 $row $col
4576 set id [lindex $displayorder $row]
4577 if {$row > $downarrowlen} {
4578 set termrow [expr {$row - $downarrowlen - 1}]
4579 foreach p [lindex $parentlist $termrow] {
4580 set i [lsearch -exact $idlist $p]
4581 if {$i < 0} continue
4582 set nr [nextuse $p $termrow]
4583 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
4584 set idlist [lreplace $idlist $i $i]
4588 set col [lsearch -exact $idlist $id]
4590 set col [idcol $idlist $id]
4591 set idlist [linsert $idlist $col $id]
4592 if {$children($curview,$id) ne {}} {
4593 makeupline $id $rm1 $row $col
4596 set r [expr {$row + $uparrowlen - 1}]
4597 if {$r < $commitidx($curview)} {
4599 foreach p [lindex $parentlist $r] {
4600 if {[lsearch -exact $idlist $p] >= 0} continue
4601 set fk [lindex $children($curview,$p) 0]
4602 if {[rowofcommit $fk] < $row} {
4603 set x [idcol $idlist $p $x]
4604 set idlist [linsert $idlist $x $p]
4607 if {[incr r] < $commitidx($curview)} {
4608 set p [lindex $displayorder $r]
4609 if {[lsearch -exact $idlist $p] < 0} {
4610 set fk [lindex $children($curview,$p) 0]
4611 if {$fk ne {} && [rowofcommit $fk] < $row} {
4612 set x [idcol $idlist $p $x]
4613 set idlist [linsert $idlist $x $p]
4619 if {$final && !$viewcomplete($curview) &&
4620 $row + $uparrowlen + $mingaplen + $downarrowlen
4621 >= $commitidx($curview)} {
4624 set l [llength $rowidlist]
4626 lappend rowidlist $idlist
4628 lappend rowfinal $final
4629 } elseif {$row < $l} {
4630 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
4631 lset rowidlist $row $idlist
4634 lset rowfinal $row $final
4636 set pad [ntimes [expr {$row - $l}] {}]
4637 set rowidlist [concat $rowidlist $pad]
4638 lappend rowidlist $idlist
4639 set rowfinal [concat $rowfinal $pad]
4640 lappend rowfinal $final
4641 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
4647 proc changedrow {row} {
4648 global displayorder iddrawn rowisopt need_redisplay
4650 set l [llength $rowisopt]
4652 lset rowisopt $row 0
4653 if {$row + 1 < $l} {
4654 lset rowisopt [expr {$row + 1}] 0
4655 if {$row + 2 < $l} {
4656 lset rowisopt [expr {$row + 2}] 0
4660 set id [lindex $displayorder $row]
4661 if {[info exists iddrawn($id)]} {
4662 set need_redisplay 1
4666 proc insert_pad {row col npad} {
4669 set pad [ntimes $npad {}]
4670 set idlist [lindex $rowidlist $row]
4671 set bef [lrange $idlist 0 [expr {$col - 1}]]
4672 set aft [lrange $idlist $col end]
4673 set i [lsearch -exact $aft {}]
4675 set aft [lreplace $aft $i $i]
4677 lset rowidlist $row [concat $bef $pad $aft]
4681 proc optimize_rows {row col endrow} {
4682 global rowidlist rowisopt displayorder curview children
4687 for {} {$row < $endrow} {incr row; set col 0} {
4688 if {[lindex $rowisopt $row]} continue
4690 set y0 [expr {$row - 1}]
4691 set ym [expr {$row - 2}]
4692 set idlist [lindex $rowidlist $row]
4693 set previdlist [lindex $rowidlist $y0]
4694 if {$idlist eq {} || $previdlist eq {}} continue
4696 set pprevidlist [lindex $rowidlist $ym]
4697 if {$pprevidlist eq {}} continue
4703 for {} {$col < [llength $idlist]} {incr col} {
4704 set id [lindex $idlist $col]
4705 if {[lindex $previdlist $col] eq $id} continue
4710 set x0 [lsearch -exact $previdlist $id]
4711 if {$x0 < 0} continue
4712 set z [expr {$x0 - $col}]
4716 set xm [lsearch -exact $pprevidlist $id]
4718 set z0 [expr {$xm - $x0}]
4722 # if row y0 is the first child of $id then it's not an arrow
4723 if {[lindex $children($curview,$id) 0] ne
4724 [lindex $displayorder $y0]} {
4728 if {!$isarrow && $id ne [lindex $displayorder $row] &&
4729 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
4732 # Looking at lines from this row to the previous row,
4733 # make them go straight up if they end in an arrow on
4734 # the previous row; otherwise make them go straight up
4736 if {$z < -1 || ($z < 0 && $isarrow)} {
4737 # Line currently goes left too much;
4738 # insert pads in the previous row, then optimize it
4739 set npad [expr {-1 - $z + $isarrow}]
4740 insert_pad $y0 $x0 $npad
4742 optimize_rows $y0 $x0 $row
4744 set previdlist [lindex $rowidlist $y0]
4745 set x0 [lsearch -exact $previdlist $id]
4746 set z [expr {$x0 - $col}]
4748 set pprevidlist [lindex $rowidlist $ym]
4749 set xm [lsearch -exact $pprevidlist $id]
4750 set z0 [expr {$xm - $x0}]
4752 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
4753 # Line currently goes right too much;
4754 # insert pads in this line
4755 set npad [expr {$z - 1 + $isarrow}]
4756 insert_pad $row $col $npad
4757 set idlist [lindex $rowidlist $row]
4759 set z [expr {$x0 - $col}]
4762 if {$z0 eq {} && !$isarrow && $ym >= 0} {
4763 # this line links to its first child on row $row-2
4764 set id [lindex $displayorder $ym]
4765 set xc [lsearch -exact $pprevidlist $id]
4767 set z0 [expr {$xc - $x0}]
4770 # avoid lines jigging left then immediately right
4771 if {$z0 ne {} && $z < 0 && $z0 > 0} {
4772 insert_pad $y0 $x0 1
4774 optimize_rows $y0 $x0 $row
4775 set previdlist [lindex $rowidlist $y0]
4779 # Find the first column that doesn't have a line going right
4780 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
4781 set id [lindex $idlist $col]
4782 if {$id eq {}} break
4783 set x0 [lsearch -exact $previdlist $id]
4785 # check if this is the link to the first child
4786 set kid [lindex $displayorder $y0]
4787 if {[lindex $children($curview,$id) 0] eq $kid} {
4788 # it is, work out offset to child
4789 set x0 [lsearch -exact $previdlist $kid]
4792 if {$x0 <= $col} break
4794 # Insert a pad at that column as long as it has a line and
4795 # isn't the last column
4796 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
4797 set idlist [linsert $idlist $col {}]
4798 lset rowidlist $row $idlist
4806 global canvx0 linespc
4807 return [expr {$canvx0 + $col * $linespc}]
4811 global canvy0 linespc
4812 return [expr {$canvy0 + $row * $linespc}]
4815 proc linewidth {id} {
4816 global thickerline lthickness
4819 if {[info exists thickerline] && $id eq $thickerline} {
4820 set wid [expr {2 * $lthickness}]
4825 proc rowranges {id} {
4826 global curview children uparrowlen downarrowlen
4829 set kids $children($curview,$id)
4835 foreach child $kids {
4836 if {![commitinview $child $curview]} break
4837 set row [rowofcommit $child]
4838 if {![info exists prev]} {
4839 lappend ret [expr {$row + 1}]
4841 if {$row <= $prevrow} {
4842 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
4844 # see if the line extends the whole way from prevrow to row
4845 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
4846 [lsearch -exact [lindex $rowidlist \
4847 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
4848 # it doesn't, see where it ends
4849 set r [expr {$prevrow + $downarrowlen}]
4850 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
4851 while {[incr r -1] > $prevrow &&
4852 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
4854 while {[incr r] <= $row &&
4855 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
4859 # see where it starts up again
4860 set r [expr {$row - $uparrowlen}]
4861 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
4862 while {[incr r] < $row &&
4863 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
4865 while {[incr r -1] >= $prevrow &&
4866 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
4872 if {$child eq $id} {
4881 proc drawlineseg {id row endrow arrowlow} {
4882 global rowidlist displayorder iddrawn linesegs
4883 global canv colormap linespc curview maxlinelen parentlist
4885 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
4886 set le [expr {$row + 1}]
4889 set c [lsearch -exact [lindex $rowidlist $le] $id]
4895 set x [lindex $displayorder $le]
4900 if {[info exists iddrawn($x)] || $le == $endrow} {
4901 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
4917 if {[info exists linesegs($id)]} {
4918 set lines $linesegs($id)
4920 set r0 [lindex $li 0]
4922 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
4932 set li [lindex $lines [expr {$i-1}]]
4933 set r1 [lindex $li 1]
4934 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
4939 set x [lindex $cols [expr {$le - $row}]]
4940 set xp [lindex $cols [expr {$le - 1 - $row}]]
4941 set dir [expr {$xp - $x}]
4943 set ith [lindex $lines $i 2]
4944 set coords [$canv coords $ith]
4945 set ah [$canv itemcget $ith -arrow]
4946 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
4947 set x2 [lindex $cols [expr {$le + 1 - $row}]]
4948 if {$x2 ne {} && $x - $x2 == $dir} {
4949 set coords [lrange $coords 0 end-2]
4952 set coords [list [xc $le $x] [yc $le]]
4955 set itl [lindex $lines [expr {$i-1}] 2]
4956 set al [$canv itemcget $itl -arrow]
4957 set arrowlow [expr {$al eq "last" || $al eq "both"}]
4958 } elseif {$arrowlow} {
4959 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
4960 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
4964 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
4965 for {set y $le} {[incr y -1] > $row} {} {
4967 set xp [lindex $cols [expr {$y - 1 - $row}]]
4968 set ndir [expr {$xp - $x}]
4969 if {$dir != $ndir || $xp < 0} {
4970 lappend coords [xc $y $x] [yc $y]
4976 # join parent line to first child
4977 set ch [lindex $displayorder $row]
4978 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
4980 puts "oops: drawlineseg: child $ch not on row $row"
4981 } elseif {$xc != $x} {
4982 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
4983 set d [expr {int(0.5 * $linespc)}]
4986 set x2 [expr {$x1 - $d}]
4988 set x2 [expr {$x1 + $d}]
4991 set y1 [expr {$y2 + $d}]
4992 lappend coords $x1 $y1 $x2 $y2
4993 } elseif {$xc < $x - 1} {
4994 lappend coords [xc $row [expr {$x-1}]] [yc $row]
4995 } elseif {$xc > $x + 1} {
4996 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5000 lappend coords [xc $row $x] [yc $row]
5002 set xn [xc $row $xp]
5004 lappend coords $xn $yn
5008 set t [$canv create line $coords -width [linewidth $id] \
5009 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5012 set lines [linsert $lines $i [list $row $le $t]]
5014 $canv coords $ith $coords
5015 if {$arrow ne $ah} {
5016 $canv itemconf $ith -arrow $arrow
5018 lset lines $i 0 $row
5021 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5022 set ndir [expr {$xo - $xp}]
5023 set clow [$canv coords $itl]
5024 if {$dir == $ndir} {
5025 set clow [lrange $clow 2 end]
5027 set coords [concat $coords $clow]
5029 lset lines [expr {$i-1}] 1 $le
5031 # coalesce two pieces
5033 set b [lindex $lines [expr {$i-1}] 0]
5034 set e [lindex $lines $i 1]
5035 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5037 $canv coords $itl $coords
5038 if {$arrow ne $al} {
5039 $canv itemconf $itl -arrow $arrow
5043 set linesegs($id) $lines
5047 proc drawparentlinks {id row} {
5048 global rowidlist canv colormap curview parentlist
5049 global idpos linespc
5051 set rowids [lindex $rowidlist $row]
5052 set col [lsearch -exact $rowids $id]
5053 if {$col < 0} return
5054 set olds [lindex $parentlist $row]
5055 set row2 [expr {$row + 1}]
5056 set x [xc $row $col]
5059 set d [expr {int(0.5 * $linespc)}]
5060 set ymid [expr {$y + $d}]
5061 set ids [lindex $rowidlist $row2]
5062 # rmx = right-most X coord used
5065 set i [lsearch -exact $ids $p]
5067 puts "oops, parent $p of $id not in list"
5070 set x2 [xc $row2 $i]
5074 set j [lsearch -exact $rowids $p]
5076 # drawlineseg will do this one for us
5080 # should handle duplicated parents here...
5081 set coords [list $x $y]
5083 # if attaching to a vertical segment, draw a smaller
5084 # slant for visual distinctness
5087 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5089 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5091 } elseif {$i < $col && $i < $j} {
5092 # segment slants towards us already
5093 lappend coords [xc $row $j] $y
5095 if {$i < $col - 1} {
5096 lappend coords [expr {$x2 + $linespc}] $y
5097 } elseif {$i > $col + 1} {
5098 lappend coords [expr {$x2 - $linespc}] $y
5100 lappend coords $x2 $y2
5103 lappend coords $x2 $y2
5105 set t [$canv create line $coords -width [linewidth $p] \
5106 -fill $colormap($p) -tags lines.$p]
5110 if {$rmx > [lindex $idpos($id) 1]} {
5111 lset idpos($id) 1 $rmx
5116 proc drawlines {id} {
5119 $canv itemconf lines.$id -width [linewidth $id]
5122 proc drawcmittext {id row col} {
5123 global linespc canv canv2 canv3 fgcolor curview
5124 global cmitlisted commitinfo rowidlist parentlist
5125 global rowtextx idpos idtags idheads idotherrefs
5126 global linehtag linentag linedtag selectedline
5127 global canvxmax boldrows boldnamerows fgcolor
5128 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5130 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5131 set listed $cmitlisted($curview,$id)
5132 if {$id eq $nullid} {
5134 } elseif {$id eq $nullid2} {
5136 } elseif {$id eq $mainheadid} {
5139 set ofill [lindex $circlecolors $listed]
5141 set x [xc $row $col]
5143 set orad [expr {$linespc / 3}]
5145 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5146 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5147 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5148 } elseif {$listed == 3} {
5149 # triangle pointing left for left-side commits
5150 set t [$canv create polygon \
5151 [expr {$x - $orad}] $y \
5152 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5153 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5154 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5156 # triangle pointing right for right-side commits
5157 set t [$canv create polygon \
5158 [expr {$x + $orad - 1}] $y \
5159 [expr {$x - $orad}] [expr {$y - $orad}] \
5160 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
5161 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5163 set circleitem($row) $t
5165 $canv bind $t <1> {selcanvline {} %x %y}
5166 set rmx [llength [lindex $rowidlist $row]]
5167 set olds [lindex $parentlist $row]
5169 set nextids [lindex $rowidlist [expr {$row + 1}]]
5171 set i [lsearch -exact $nextids $p]
5177 set xt [xc $row $rmx]
5178 set rowtextx($row) $xt
5179 set idpos($id) [list $x $xt $y]
5180 if {[info exists idtags($id)] || [info exists idheads($id)]
5181 || [info exists idotherrefs($id)]} {
5182 set xt [drawtags $id $x $xt $y]
5184 set headline [lindex $commitinfo($id) 0]
5185 set name [lindex $commitinfo($id) 1]
5186 set date [lindex $commitinfo($id) 2]
5187 set date [formatdate $date]
5190 set isbold [ishighlighted $id]
5192 lappend boldrows $row
5193 set font mainfontbold
5195 lappend boldnamerows $row
5196 set nfont mainfontbold
5199 set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \
5200 -text $headline -font $font -tags text]
5201 $canv bind $linehtag($row) $ctxbut "rowmenu %X %Y $id"
5202 set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
5203 -text $name -font $nfont -tags text]
5204 set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
5205 -text $date -font mainfont -tags text]
5206 if {$selectedline == $row} {
5209 set xr [expr {$xt + [font measure $font $headline]}]
5210 if {$xr > $canvxmax} {
5216 proc drawcmitrow {row} {
5217 global displayorder rowidlist nrows_drawn
5218 global iddrawn markingmatches
5219 global commitinfo numcommits
5220 global filehighlight fhighlights findpattern nhighlights
5221 global hlview vhighlights
5222 global highlight_related rhighlights
5224 if {$row >= $numcommits} return
5226 set id [lindex $displayorder $row]
5227 if {[info exists hlview] && ![info exists vhighlights($id)]} {
5228 askvhighlight $row $id
5230 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
5231 askfilehighlight $row $id
5233 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
5234 askfindhighlight $row $id
5236 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
5237 askrelhighlight $row $id
5239 if {![info exists iddrawn($id)]} {
5240 set col [lsearch -exact [lindex $rowidlist $row] $id]
5242 puts "oops, row $row id $id not in list"
5245 if {![info exists commitinfo($id)]} {
5249 drawcmittext $id $row $col
5253 if {$markingmatches} {
5254 markrowmatches $row $id
5258 proc drawcommits {row {endrow {}}} {
5259 global numcommits iddrawn displayorder curview need_redisplay
5260 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
5265 if {$endrow eq {}} {
5268 if {$endrow >= $numcommits} {
5269 set endrow [expr {$numcommits - 1}]
5272 set rl1 [expr {$row - $downarrowlen - 3}]
5276 set ro1 [expr {$row - 3}]
5280 set r2 [expr {$endrow + $uparrowlen + 3}]
5281 if {$r2 > $numcommits} {
5284 for {set r $rl1} {$r < $r2} {incr r} {
5285 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
5289 set rl1 [expr {$r + 1}]
5295 optimize_rows $ro1 0 $r2
5296 if {$need_redisplay || $nrows_drawn > 2000} {
5301 # make the lines join to already-drawn rows either side
5302 set r [expr {$row - 1}]
5303 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
5306 set er [expr {$endrow + 1}]
5307 if {$er >= $numcommits ||
5308 ![info exists iddrawn([lindex $displayorder $er])]} {
5311 for {} {$r <= $er} {incr r} {
5312 set id [lindex $displayorder $r]
5313 set wasdrawn [info exists iddrawn($id)]
5315 if {$r == $er} break
5316 set nextid [lindex $displayorder [expr {$r + 1}]]
5317 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
5318 drawparentlinks $id $r
5320 set rowids [lindex $rowidlist $r]
5321 foreach lid $rowids {
5322 if {$lid eq {}} continue
5323 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
5325 # see if this is the first child of any of its parents
5326 foreach p [lindex $parentlist $r] {
5327 if {[lsearch -exact $rowids $p] < 0} {
5328 # make this line extend up to the child
5329 set lineend($p) [drawlineseg $p $r $er 0]
5333 set lineend($lid) [drawlineseg $lid $r $er 1]
5339 proc undolayout {row} {
5340 global uparrowlen mingaplen downarrowlen
5341 global rowidlist rowisopt rowfinal need_redisplay
5343 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
5347 if {[llength $rowidlist] > $r} {
5349 set rowidlist [lrange $rowidlist 0 $r]
5350 set rowfinal [lrange $rowfinal 0 $r]
5351 set rowisopt [lrange $rowisopt 0 $r]
5352 set need_redisplay 1
5357 proc drawvisible {} {
5358 global canv linespc curview vrowmod selectedline targetrow targetid
5359 global need_redisplay cscroll numcommits
5361 set fs [$canv yview]
5362 set ymax [lindex [$canv cget -scrollregion] 3]
5363 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
5364 set f0 [lindex $fs 0]
5365 set f1 [lindex $fs 1]
5366 set y0 [expr {int($f0 * $ymax)}]
5367 set y1 [expr {int($f1 * $ymax)}]
5369 if {[info exists targetid]} {
5370 if {[commitinview $targetid $curview]} {
5371 set r [rowofcommit $targetid]
5372 if {$r != $targetrow} {
5373 # Fix up the scrollregion and change the scrolling position
5374 # now that our target row has moved.
5375 set diff [expr {($r - $targetrow) * $linespc}]
5378 set ymax [lindex [$canv cget -scrollregion] 3]
5381 set f0 [expr {$y0 / $ymax}]
5382 set f1 [expr {$y1 / $ymax}]
5383 allcanvs yview moveto $f0
5384 $cscroll set $f0 $f1
5385 set need_redisplay 1
5392 set row [expr {int(($y0 - 3) / $linespc) - 1}]
5393 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
5394 if {$endrow >= $vrowmod($curview)} {
5395 update_arcrows $curview
5397 if {$selectedline ne {} &&
5398 $row <= $selectedline && $selectedline <= $endrow} {
5399 set targetrow $selectedline
5400 } elseif {[info exists targetid]} {
5401 set targetrow [expr {int(($row + $endrow) / 2)}]
5403 if {[info exists targetrow]} {
5404 if {$targetrow >= $numcommits} {
5405 set targetrow [expr {$numcommits - 1}]
5407 set targetid [commitonrow $targetrow]
5409 drawcommits $row $endrow
5412 proc clear_display {} {
5413 global iddrawn linesegs need_redisplay nrows_drawn
5414 global vhighlights fhighlights nhighlights rhighlights
5415 global linehtag linentag linedtag boldrows boldnamerows
5418 catch {unset iddrawn}
5419 catch {unset linesegs}
5420 catch {unset linehtag}
5421 catch {unset linentag}
5422 catch {unset linedtag}
5425 catch {unset vhighlights}
5426 catch {unset fhighlights}
5427 catch {unset nhighlights}
5428 catch {unset rhighlights}
5429 set need_redisplay 0
5433 proc findcrossings {id} {
5434 global rowidlist parentlist numcommits displayorder
5438 foreach {s e} [rowranges $id] {
5439 if {$e >= $numcommits} {
5440 set e [expr {$numcommits - 1}]
5442 if {$e <= $s} continue
5443 for {set row $e} {[incr row -1] >= $s} {} {
5444 set x [lsearch -exact [lindex $rowidlist $row] $id]
5446 set olds [lindex $parentlist $row]
5447 set kid [lindex $displayorder $row]
5448 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
5449 if {$kidx < 0} continue
5450 set nextrow [lindex $rowidlist [expr {$row + 1}]]
5452 set px [lsearch -exact $nextrow $p]
5453 if {$px < 0} continue
5454 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
5455 if {[lsearch -exact $ccross $p] >= 0} continue
5456 if {$x == $px + ($kidx < $px? -1: 1)} {
5458 } elseif {[lsearch -exact $cross $p] < 0} {
5465 return [concat $ccross {{}} $cross]
5468 proc assigncolor {id} {
5469 global colormap colors nextcolor
5470 global parents children children curview
5472 if {[info exists colormap($id)]} return
5473 set ncolors [llength $colors]
5474 if {[info exists children($curview,$id)]} {
5475 set kids $children($curview,$id)
5479 if {[llength $kids] == 1} {
5480 set child [lindex $kids 0]
5481 if {[info exists colormap($child)]
5482 && [llength $parents($curview,$child)] == 1} {
5483 set colormap($id) $colormap($child)
5489 foreach x [findcrossings $id] {
5491 # delimiter between corner crossings and other crossings
5492 if {[llength $badcolors] >= $ncolors - 1} break
5493 set origbad $badcolors
5495 if {[info exists colormap($x)]
5496 && [lsearch -exact $badcolors $colormap($x)] < 0} {
5497 lappend badcolors $colormap($x)
5500 if {[llength $badcolors] >= $ncolors} {
5501 set badcolors $origbad
5503 set origbad $badcolors
5504 if {[llength $badcolors] < $ncolors - 1} {
5505 foreach child $kids {
5506 if {[info exists colormap($child)]
5507 && [lsearch -exact $badcolors $colormap($child)] < 0} {
5508 lappend badcolors $colormap($child)
5510 foreach p $parents($curview,$child) {
5511 if {[info exists colormap($p)]
5512 && [lsearch -exact $badcolors $colormap($p)] < 0} {
5513 lappend badcolors $colormap($p)
5517 if {[llength $badcolors] >= $ncolors} {
5518 set badcolors $origbad
5521 for {set i 0} {$i <= $ncolors} {incr i} {
5522 set c [lindex $colors $nextcolor]
5523 if {[incr nextcolor] >= $ncolors} {
5526 if {[lsearch -exact $badcolors $c]} break
5528 set colormap($id) $c
5531 proc bindline {t id} {
5534 $canv bind $t <Enter> "lineenter %x %y $id"
5535 $canv bind $t <Motion> "linemotion %x %y $id"
5536 $canv bind $t <Leave> "lineleave $id"
5537 $canv bind $t <Button-1> "lineclick %x %y $id 1"
5540 proc drawtags {id x xt y1} {
5541 global idtags idheads idotherrefs mainhead
5542 global linespc lthickness
5543 global canv rowtextx curview fgcolor bgcolor ctxbut
5548 if {[info exists idtags($id)]} {
5549 set marks $idtags($id)
5550 set ntags [llength $marks]
5552 if {[info exists idheads($id)]} {
5553 set marks [concat $marks $idheads($id)]
5554 set nheads [llength $idheads($id)]
5556 if {[info exists idotherrefs($id)]} {
5557 set marks [concat $marks $idotherrefs($id)]
5563 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
5564 set yt [expr {$y1 - 0.5 * $linespc}]
5565 set yb [expr {$yt + $linespc - 1}]
5569 foreach tag $marks {
5571 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
5572 set wid [font measure mainfontbold $tag]
5574 set wid [font measure mainfont $tag]
5578 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
5580 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
5581 -width $lthickness -fill black -tags tag.$id]
5583 foreach tag $marks x $xvals wid $wvals {
5584 set xl [expr {$x + $delta}]
5585 set xr [expr {$x + $delta + $wid + $lthickness}]
5587 if {[incr ntags -1] >= 0} {
5589 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
5590 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
5591 -width 1 -outline black -fill yellow -tags tag.$id]
5592 $canv bind $t <1> [list showtag $tag 1]
5593 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
5595 # draw a head or other ref
5596 if {[incr nheads -1] >= 0} {
5598 if {$tag eq $mainhead} {
5599 set font mainfontbold
5604 set xl [expr {$xl - $delta/2}]
5605 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
5606 -width 1 -outline black -fill $col -tags tag.$id
5607 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
5608 set rwid [font measure mainfont $remoteprefix]
5609 set xi [expr {$x + 1}]
5610 set yti [expr {$yt + 1}]
5611 set xri [expr {$x + $rwid}]
5612 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
5613 -width 0 -fill "#ffddaa" -tags tag.$id
5616 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
5617 -font $font -tags [list tag.$id text]]
5619 $canv bind $t <1> [list showtag $tag 1]
5620 } elseif {$nheads >= 0} {
5621 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag]
5627 proc xcoord {i level ln} {
5628 global canvx0 xspc1 xspc2
5630 set x [expr {$canvx0 + $i * $xspc1($ln)}]
5631 if {$i > 0 && $i == $level} {
5632 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
5633 } elseif {$i > $level} {
5634 set x [expr {$x + $xspc2 - $xspc1($ln)}]
5639 proc show_status {msg} {
5643 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
5644 -tags text -fill $fgcolor
5647 # Don't change the text pane cursor if it is currently the hand cursor,
5648 # showing that we are over a sha1 ID link.
5649 proc settextcursor {c} {
5650 global ctext curtextcursor
5652 if {[$ctext cget -cursor] == $curtextcursor} {
5653 $ctext config -cursor $c
5655 set curtextcursor $c
5658 proc nowbusy {what {name {}}} {
5659 global isbusy busyname statusw
5661 if {[array names isbusy] eq {}} {
5662 . config -cursor watch
5666 set busyname($what) $name
5668 $statusw conf -text $name
5672 proc notbusy {what} {
5673 global isbusy maincursor textcursor busyname statusw
5677 if {$busyname($what) ne {} &&
5678 [$statusw cget -text] eq $busyname($what)} {
5679 $statusw conf -text {}
5682 if {[array names isbusy] eq {}} {
5683 . config -cursor $maincursor
5684 settextcursor $textcursor
5688 proc findmatches {f} {
5689 global findtype findstring
5690 if {$findtype == [mc "Regexp"]} {
5691 set matches [regexp -indices -all -inline $findstring $f]
5694 if {$findtype == [mc "IgnCase"]} {
5695 set f [string tolower $f]
5696 set fs [string tolower $fs]
5700 set l [string length $fs]
5701 while {[set j [string first $fs $f $i]] >= 0} {
5702 lappend matches [list $j [expr {$j+$l-1}]]
5703 set i [expr {$j + $l}]
5709 proc dofind {{dirn 1} {wrap 1}} {
5710 global findstring findstartline findcurline selectedline numcommits
5711 global gdttype filehighlight fh_serial find_dirn findallowwrap
5713 if {[info exists find_dirn]} {
5714 if {$find_dirn == $dirn} return
5718 if {$findstring eq {} || $numcommits == 0} return
5719 if {$selectedline eq {}} {
5720 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
5722 set findstartline $selectedline
5724 set findcurline $findstartline
5725 nowbusy finding [mc "Searching"]
5726 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
5727 after cancel do_file_hl $fh_serial
5728 do_file_hl $fh_serial
5731 set findallowwrap $wrap
5735 proc stopfinding {} {
5736 global find_dirn findcurline fprogcoord
5738 if {[info exists find_dirn]} {
5748 global commitdata commitinfo numcommits findpattern findloc
5749 global findstartline findcurline findallowwrap
5750 global find_dirn gdttype fhighlights fprogcoord
5751 global curview varcorder vrownum varccommits vrowmod
5753 if {![info exists find_dirn]} {
5756 set fldtypes [list [mc "Headline"] [mc "Author"] [mc "Date"] [mc "Committer"] [mc "CDate"] [mc "Comments"]]
5759 if {$find_dirn > 0} {
5761 if {$l >= $numcommits} {
5764 if {$l <= $findstartline} {
5765 set lim [expr {$findstartline + 1}]
5768 set moretodo $findallowwrap
5775 if {$l >= $findstartline} {
5776 set lim [expr {$findstartline - 1}]
5779 set moretodo $findallowwrap
5782 set n [expr {($lim - $l) * $find_dirn}]
5787 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
5788 update_arcrows $curview
5792 set ai [bsearch $vrownum($curview) $l]
5793 set a [lindex $varcorder($curview) $ai]
5794 set arow [lindex $vrownum($curview) $ai]
5795 set ids [lindex $varccommits($curview,$a)]
5796 set arowend [expr {$arow + [llength $ids]}]
5797 if {$gdttype eq [mc "containing:"]} {
5798 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
5799 if {$l < $arow || $l >= $arowend} {
5801 set a [lindex $varcorder($curview) $ai]
5802 set arow [lindex $vrownum($curview) $ai]
5803 set ids [lindex $varccommits($curview,$a)]
5804 set arowend [expr {$arow + [llength $ids]}]
5806 set id [lindex $ids [expr {$l - $arow}]]
5807 # shouldn't happen unless git log doesn't give all the commits...
5808 if {![info exists commitdata($id)] ||
5809 ![doesmatch $commitdata($id)]} {
5812 if {![info exists commitinfo($id)]} {
5815 set info $commitinfo($id)
5816 foreach f $info ty $fldtypes {
5817 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
5826 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
5827 if {$l < $arow || $l >= $arowend} {
5829 set a [lindex $varcorder($curview) $ai]
5830 set arow [lindex $vrownum($curview) $ai]
5831 set ids [lindex $varccommits($curview,$a)]
5832 set arowend [expr {$arow + [llength $ids]}]
5834 set id [lindex $ids [expr {$l - $arow}]]
5835 if {![info exists fhighlights($id)]} {
5836 # this sets fhighlights($id) to -1
5837 askfilehighlight $l $id
5839 if {$fhighlights($id) > 0} {
5843 if {$fhighlights($id) < 0} {
5846 set findcurline [expr {$l - $find_dirn}]
5851 if {$found || ($domore && !$moretodo)} {
5867 set findcurline [expr {$l - $find_dirn}]
5869 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
5873 set fprogcoord [expr {$n * 1.0 / $numcommits}]
5878 proc findselectline {l} {
5879 global findloc commentend ctext findcurline markingmatches gdttype
5881 set markingmatches 1
5884 if {$findloc == [mc "All fields"] || $findloc == [mc "Comments"]} {
5885 # highlight the matches in the comments
5886 set f [$ctext get 1.0 $commentend]
5887 set matches [findmatches $f]
5888 foreach match $matches {
5889 set start [lindex $match 0]
5890 set end [expr {[lindex $match 1] + 1}]
5891 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
5897 # mark the bits of a headline or author that match a find string
5898 proc markmatches {canv l str tag matches font row} {
5901 set bbox [$canv bbox $tag]
5902 set x0 [lindex $bbox 0]
5903 set y0 [lindex $bbox 1]
5904 set y1 [lindex $bbox 3]
5905 foreach match $matches {
5906 set start [lindex $match 0]
5907 set end [lindex $match 1]
5908 if {$start > $end} continue
5909 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
5910 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
5911 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
5912 [expr {$x0+$xlen+2}] $y1 \
5913 -outline {} -tags [list match$l matches] -fill yellow]
5915 if {$row == $selectedline} {
5916 $canv raise $t secsel
5921 proc unmarkmatches {} {
5922 global markingmatches
5924 allcanvs delete matches
5925 set markingmatches 0
5929 proc selcanvline {w x y} {
5930 global canv canvy0 ctext linespc
5932 set ymax [lindex [$canv cget -scrollregion] 3]
5933 if {$ymax == {}} return
5934 set yfrac [lindex [$canv yview] 0]
5935 set y [expr {$y + $yfrac * $ymax}]
5936 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
5941 set xmax [lindex [$canv cget -scrollregion] 2]
5942 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
5943 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
5949 proc commit_descriptor {p} {
5951 if {![info exists commitinfo($p)]} {
5955 if {[llength $commitinfo($p)] > 1} {
5956 set l [lindex $commitinfo($p) 0]
5961 # append some text to the ctext widget, and make any SHA1 ID
5962 # that we know about be a clickable link.
5963 proc appendwithlinks {text tags} {
5964 global ctext linknum curview
5966 set start [$ctext index "end - 1c"]
5967 $ctext insert end $text $tags
5968 set links [regexp -indices -all -inline {\m[0-9a-f]{6,40}\M} $text]
5972 set linkid [string range $text $s $e]
5974 $ctext tag delete link$linknum
5975 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
5976 setlink $linkid link$linknum
5981 proc setlink {id lk} {
5982 global curview ctext pendinglinks
5985 if {[string length $id] < 40} {
5986 set matches [longid $id]
5987 if {[llength $matches] > 0} {
5988 if {[llength $matches] > 1} return
5990 set id [lindex $matches 0]
5993 set known [commitinview $id $curview]
5996 $ctext tag conf $lk -foreground blue -underline 1
5997 $ctext tag bind $lk <1> [list selbyid $id]
5998 $ctext tag bind $lk <Enter> {linkcursor %W 1}
5999 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6001 lappend pendinglinks($id) $lk
6002 interestedin $id {makelink %P}
6006 proc makelink {id} {
6009 if {![info exists pendinglinks($id)]} return
6010 foreach lk $pendinglinks($id) {
6013 unset pendinglinks($id)
6016 proc linkcursor {w inc} {
6017 global linkentercount curtextcursor
6019 if {[incr linkentercount $inc] > 0} {
6020 $w configure -cursor hand2
6022 $w configure -cursor $curtextcursor
6023 if {$linkentercount < 0} {
6024 set linkentercount 0
6029 proc viewnextline {dir} {
6033 set ymax [lindex [$canv cget -scrollregion] 3]
6034 set wnow [$canv yview]
6035 set wtop [expr {[lindex $wnow 0] * $ymax}]
6036 set newtop [expr {$wtop + $dir * $linespc}]
6039 } elseif {$newtop > $ymax} {
6042 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6045 # add a list of tag or branch names at position pos
6046 # returns the number of names inserted
6047 proc appendrefs {pos ids var} {
6048 global ctext linknum curview $var maxrefs
6050 if {[catch {$ctext index $pos}]} {
6053 $ctext conf -state normal
6054 $ctext delete $pos "$pos lineend"
6057 foreach tag [set $var\($id\)] {
6058 lappend tags [list $tag $id]
6061 if {[llength $tags] > $maxrefs} {
6062 $ctext insert $pos "many ([llength $tags])"
6064 set tags [lsort -index 0 -decreasing $tags]
6067 set id [lindex $ti 1]
6070 $ctext tag delete $lk
6071 $ctext insert $pos $sep
6072 $ctext insert $pos [lindex $ti 0] $lk
6077 $ctext conf -state disabled
6078 return [llength $tags]
6081 # called when we have finished computing the nearby tags
6082 proc dispneartags {delay} {
6083 global selectedline currentid showneartags tagphase
6085 if {$selectedline eq {} || !$showneartags} return
6086 after cancel dispnexttag
6088 after 200 dispnexttag
6091 after idle dispnexttag
6096 proc dispnexttag {} {
6097 global selectedline currentid showneartags tagphase ctext
6099 if {$selectedline eq {} || !$showneartags} return
6100 switch -- $tagphase {
6102 set dtags [desctags $currentid]
6104 appendrefs precedes $dtags idtags
6108 set atags [anctags $currentid]
6110 appendrefs follows $atags idtags
6114 set dheads [descheads $currentid]
6115 if {$dheads ne {}} {
6116 if {[appendrefs branch $dheads idheads] > 1
6117 && [$ctext get "branch -3c"] eq "h"} {
6118 # turn "Branch" into "Branches"
6119 $ctext conf -state normal
6120 $ctext insert "branch -2c" "es"
6121 $ctext conf -state disabled
6126 if {[incr tagphase] <= 2} {
6127 after idle dispnexttag
6131 proc make_secsel {l} {
6132 global linehtag linentag linedtag canv canv2 canv3
6134 if {![info exists linehtag($l)]} return
6136 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
6137 -tags secsel -fill [$canv cget -selectbackground]]
6139 $canv2 delete secsel
6140 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
6141 -tags secsel -fill [$canv2 cget -selectbackground]]
6143 $canv3 delete secsel
6144 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
6145 -tags secsel -fill [$canv3 cget -selectbackground]]
6149 proc selectline {l isnew} {
6150 global canv ctext commitinfo selectedline
6151 global canvy0 linespc parents children curview
6152 global currentid sha1entry
6153 global commentend idtags linknum
6154 global mergemax numcommits pending_select
6155 global cmitmode showneartags allcommits
6156 global targetrow targetid lastscrollrows
6159 catch {unset pending_select}
6164 if {$l < 0 || $l >= $numcommits} return
6165 set id [commitonrow $l]
6170 if {$lastscrollrows < $numcommits} {
6174 set y [expr {$canvy0 + $l * $linespc}]
6175 set ymax [lindex [$canv cget -scrollregion] 3]
6176 set ytop [expr {$y - $linespc - 1}]
6177 set ybot [expr {$y + $linespc + 1}]
6178 set wnow [$canv yview]
6179 set wtop [expr {[lindex $wnow 0] * $ymax}]
6180 set wbot [expr {[lindex $wnow 1] * $ymax}]
6181 set wh [expr {$wbot - $wtop}]
6183 if {$ytop < $wtop} {
6184 if {$ybot < $wtop} {
6185 set newtop [expr {$y - $wh / 2.0}]
6188 if {$newtop > $wtop - $linespc} {
6189 set newtop [expr {$wtop - $linespc}]
6192 } elseif {$ybot > $wbot} {
6193 if {$ytop > $wbot} {
6194 set newtop [expr {$y - $wh / 2.0}]
6196 set newtop [expr {$ybot - $wh}]
6197 if {$newtop < $wtop + $linespc} {
6198 set newtop [expr {$wtop + $linespc}]
6202 if {$newtop != $wtop} {
6206 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6213 addtohistory [list selbyid $id]
6216 $sha1entry delete 0 end
6217 $sha1entry insert 0 $id
6219 $sha1entry selection from 0
6220 $sha1entry selection to end
6224 $ctext conf -state normal
6227 if {![info exists commitinfo($id)]} {
6230 set info $commitinfo($id)
6231 set date [formatdate [lindex $info 2]]
6232 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
6233 set date [formatdate [lindex $info 4]]
6234 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
6235 if {[info exists idtags($id)]} {
6236 $ctext insert end [mc "Tags:"]
6237 foreach tag $idtags($id) {
6238 $ctext insert end " $tag"
6240 $ctext insert end "\n"
6244 set olds $parents($curview,$id)
6245 if {[llength $olds] > 1} {
6248 if {$np >= $mergemax} {
6253 $ctext insert end "[mc "Parent"]: " $tag
6254 appendwithlinks [commit_descriptor $p] {}
6259 append headers "[mc "Parent"]: [commit_descriptor $p]"
6263 foreach c $children($curview,$id) {
6264 append headers "[mc "Child"]: [commit_descriptor $c]"
6267 # make anything that looks like a SHA1 ID be a clickable link
6268 appendwithlinks $headers {}
6269 if {$showneartags} {
6270 if {![info exists allcommits]} {
6273 $ctext insert end "[mc "Branch"]: "
6274 $ctext mark set branch "end -1c"
6275 $ctext mark gravity branch left
6276 $ctext insert end "\n[mc "Follows"]: "
6277 $ctext mark set follows "end -1c"
6278 $ctext mark gravity follows left
6279 $ctext insert end "\n[mc "Precedes"]: "
6280 $ctext mark set precedes "end -1c"
6281 $ctext mark gravity precedes left
6282 $ctext insert end "\n"
6285 $ctext insert end "\n"
6286 set comment [lindex $info 5]
6287 if {[string first "\r" $comment] >= 0} {
6288 set comment [string map {"\r" "\n "} $comment]
6290 appendwithlinks $comment {comment}
6292 $ctext tag remove found 1.0 end
6293 $ctext conf -state disabled
6294 set commentend [$ctext index "end - 1c"]
6296 init_flist [mc "Comments"]
6297 if {$cmitmode eq "tree"} {
6299 } elseif {[llength $olds] <= 1} {
6306 proc selfirstline {} {
6311 proc sellastline {} {
6314 set l [expr {$numcommits - 1}]
6318 proc selnextline {dir} {
6321 if {$selectedline eq {}} return
6322 set l [expr {$selectedline + $dir}]
6327 proc selnextpage {dir} {
6328 global canv linespc selectedline numcommits
6330 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
6334 allcanvs yview scroll [expr {$dir * $lpp}] units
6336 if {$selectedline eq {}} return
6337 set l [expr {$selectedline + $dir * $lpp}]
6340 } elseif {$l >= $numcommits} {
6341 set l [expr $numcommits - 1]
6347 proc unselectline {} {
6348 global selectedline currentid
6351 catch {unset currentid}
6352 allcanvs delete secsel
6356 proc reselectline {} {
6359 if {$selectedline ne {}} {
6360 selectline $selectedline 0
6364 proc addtohistory {cmd} {
6365 global history historyindex curview
6367 set elt [list $curview $cmd]
6368 if {$historyindex > 0
6369 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
6373 if {$historyindex < [llength $history]} {
6374 set history [lreplace $history $historyindex end $elt]
6376 lappend history $elt
6379 if {$historyindex > 1} {
6380 .tf.bar.leftbut conf -state normal
6382 .tf.bar.leftbut conf -state disabled
6384 .tf.bar.rightbut conf -state disabled
6390 set view [lindex $elt 0]
6391 set cmd [lindex $elt 1]
6392 if {$curview != $view} {
6399 global history historyindex
6402 if {$historyindex > 1} {
6403 incr historyindex -1
6404 godo [lindex $history [expr {$historyindex - 1}]]
6405 .tf.bar.rightbut conf -state normal
6407 if {$historyindex <= 1} {
6408 .tf.bar.leftbut conf -state disabled
6413 global history historyindex
6416 if {$historyindex < [llength $history]} {
6417 set cmd [lindex $history $historyindex]
6420 .tf.bar.leftbut conf -state normal
6422 if {$historyindex >= [llength $history]} {
6423 .tf.bar.rightbut conf -state disabled
6428 global treefilelist treeidlist diffids diffmergeid treepending
6429 global nullid nullid2
6432 catch {unset diffmergeid}
6433 if {![info exists treefilelist($id)]} {
6434 if {![info exists treepending]} {
6435 if {$id eq $nullid} {
6436 set cmd [list | git ls-files]
6437 } elseif {$id eq $nullid2} {
6438 set cmd [list | git ls-files --stage -t]
6440 set cmd [list | git ls-tree -r $id]
6442 if {[catch {set gtf [open $cmd r]}]} {
6446 set treefilelist($id) {}
6447 set treeidlist($id) {}
6448 fconfigure $gtf -blocking 0 -encoding binary
6449 filerun $gtf [list gettreeline $gtf $id]
6456 proc gettreeline {gtf id} {
6457 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
6460 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
6461 if {$diffids eq $nullid} {
6464 set i [string first "\t" $line]
6465 if {$i < 0} continue
6466 set fname [string range $line [expr {$i+1}] end]
6467 set line [string range $line 0 [expr {$i-1}]]
6468 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
6469 set sha1 [lindex $line 2]
6470 lappend treeidlist($id) $sha1
6472 if {[string index $fname 0] eq "\""} {
6473 set fname [lindex $fname 0]
6475 set fname [encoding convertfrom $fname]
6476 lappend treefilelist($id) $fname
6479 return [expr {$nl >= 1000? 2: 1}]
6483 if {$cmitmode ne "tree"} {
6484 if {![info exists diffmergeid]} {
6485 gettreediffs $diffids
6487 } elseif {$id ne $diffids} {
6496 global treefilelist treeidlist diffids nullid nullid2
6497 global ctext_file_names ctext_file_lines
6498 global ctext commentend
6500 set i [lsearch -exact $treefilelist($diffids) $f]
6502 puts "oops, $f not in list for id $diffids"
6505 if {$diffids eq $nullid} {
6506 if {[catch {set bf [open $f r]} err]} {
6507 puts "oops, can't read $f: $err"
6511 set blob [lindex $treeidlist($diffids) $i]
6512 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
6513 puts "oops, error reading blob $blob: $err"
6517 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
6518 filerun $bf [list getblobline $bf $diffids]
6519 $ctext config -state normal
6520 clear_ctext $commentend
6521 lappend ctext_file_names $f
6522 lappend ctext_file_lines [lindex [split $commentend "."] 0]
6523 $ctext insert end "\n"
6524 $ctext insert end "$f\n" filesep
6525 $ctext config -state disabled
6526 $ctext yview $commentend
6530 proc getblobline {bf id} {
6531 global diffids cmitmode ctext
6533 if {$id ne $diffids || $cmitmode ne "tree"} {
6537 $ctext config -state normal
6539 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
6540 $ctext insert end "$line\n"
6543 # delete last newline
6544 $ctext delete "end - 2c" "end - 1c"
6548 $ctext config -state disabled
6549 return [expr {$nl >= 1000? 2: 1}]
6552 proc mergediff {id} {
6553 global diffmergeid mdifffd
6554 global diffids treediffs
6558 global limitdiffs vfilelimit curview
6562 set treediffs($id) {}
6563 # this doesn't seem to actually affect anything...
6564 set cmd [concat | git diff-tree --no-commit-id --cc -U$diffcontext $id]
6565 if {$limitdiffs && $vfilelimit($curview) ne {}} {
6566 set cmd [concat $cmd -- $vfilelimit($curview)]
6568 if {[catch {set mdf [open $cmd r]} err]} {
6569 error_popup "[mc "Error getting merge diffs:"] $err"
6572 fconfigure $mdf -blocking 0 -encoding binary
6573 set mdifffd($id) $mdf
6574 set np [llength $parents($curview,$id)]
6575 set diffencoding [get_path_encoding {}]
6577 filerun $mdf [list getmergediffline $mdf $id $np]
6580 proc getmergediffline {mdf id np} {
6581 global diffmergeid ctext cflist mergemax
6582 global difffilestart mdifffd treediffs
6583 global ctext_file_names ctext_file_lines
6586 $ctext conf -state normal
6588 while {[incr nr] <= 1000 && [gets $mdf line] >= 0} {
6589 if {![info exists diffmergeid] || $id != $diffmergeid
6590 || $mdf != $mdifffd($id)} {
6594 if {[regexp {^diff --cc (.*)} $line match fname]} {
6595 # start of a new file
6596 set fname [encoding convertfrom $fname]
6597 $ctext insert end "\n"
6598 set here [$ctext index "end - 1c"]
6599 lappend difffilestart $here
6600 lappend treediffs($id) $fname
6601 add_flist [list $fname]
6602 lappend ctext_file_names $fname
6603 lappend ctext_file_lines [lindex [split $here "."] 0]
6604 set diffencoding [get_path_encoding $fname]
6605 set l [expr {(78 - [string length $fname]) / 2}]
6606 set pad [string range "----------------------------------------" 1 $l]
6607 $ctext insert end "$pad $fname $pad\n" filesep
6608 } elseif {[regexp {^@@} $line]} {
6609 set line [encoding convertfrom $diffencoding $line]
6610 $ctext insert end "$line\n" hunksep
6611 } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
6614 set line [encoding convertfrom $diffencoding $line]
6615 # parse the prefix - one ' ', '-' or '+' for each parent
6620 for {set j 0} {$j < $np} {incr j} {
6621 set c [string range $line $j $j]
6624 } elseif {$c == "-"} {
6626 } elseif {$c == "+"} {
6635 if {!$isbad && $minuses ne {} && $pluses eq {}} {
6636 # line doesn't appear in result, parents in $minuses have the line
6637 set num [lindex $minuses 0]
6638 } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
6639 # line appears in result, parents in $pluses don't have the line
6640 lappend tags mresult
6641 set num [lindex $spaces 0]
6644 if {$num >= $mergemax} {
6649 $ctext insert end "$line\n" $tags
6652 $ctext conf -state disabled
6657 return [expr {$nr >= 1000? 2: 1}]
6660 proc startdiff {ids} {
6661 global treediffs diffids treepending diffmergeid nullid nullid2
6665 catch {unset diffmergeid}
6666 if {![info exists treediffs($ids)] ||
6667 [lsearch -exact $ids $nullid] >= 0 ||
6668 [lsearch -exact $ids $nullid2] >= 0} {
6669 if {![info exists treepending]} {
6677 proc path_filter {filter name} {
6679 set l [string length $p]
6680 if {[string index $p end] eq "/"} {
6681 if {[string compare -length $l $p $name] == 0} {
6685 if {[string compare -length $l $p $name] == 0 &&
6686 ([string length $name] == $l ||
6687 [string index $name $l] eq "/")} {
6695 proc addtocflist {ids} {
6698 add_flist $treediffs($ids)
6702 proc diffcmd {ids flags} {
6703 global nullid nullid2
6705 set i [lsearch -exact $ids $nullid]
6706 set j [lsearch -exact $ids $nullid2]
6708 if {[llength $ids] > 1 && $j < 0} {
6709 # comparing working directory with some specific revision
6710 set cmd [concat | git diff-index $flags]
6712 lappend cmd -R [lindex $ids 1]
6714 lappend cmd [lindex $ids 0]
6717 # comparing working directory with index
6718 set cmd [concat | git diff-files $flags]
6723 } elseif {$j >= 0} {
6724 set cmd [concat | git diff-index --cached $flags]
6725 if {[llength $ids] > 1} {
6726 # comparing index with specific revision
6728 lappend cmd -R [lindex $ids 1]
6730 lappend cmd [lindex $ids 0]
6733 # comparing index with HEAD
6737 set cmd [concat | git diff-tree -r $flags $ids]
6742 proc gettreediffs {ids} {
6743 global treediff treepending
6745 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
6747 set treepending $ids
6749 fconfigure $gdtf -blocking 0 -encoding binary
6750 filerun $gdtf [list gettreediffline $gdtf $ids]
6753 proc gettreediffline {gdtf ids} {
6754 global treediff treediffs treepending diffids diffmergeid
6755 global cmitmode vfilelimit curview limitdiffs perfile_attrs
6760 if {$perfile_attrs} {
6761 # cache_gitattr is slow, and even slower on win32 where we
6762 # have to invoke it for only about 30 paths at a time
6764 if {[tk windowingsystem] == "win32"} {
6768 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
6769 set i [string first "\t" $line]
6771 set file [string range $line [expr {$i+1}] end]
6772 if {[string index $file 0] eq "\""} {
6773 set file [lindex $file 0]
6775 set file [encoding convertfrom $file]
6776 lappend treediff $file
6777 lappend sublist $file
6780 if {$perfile_attrs} {
6781 cache_gitattr encoding $sublist
6784 return [expr {$nr >= $max? 2: 1}]
6787 if {$limitdiffs && $vfilelimit($curview) ne {}} {
6789 foreach f $treediff {
6790 if {[path_filter $vfilelimit($curview) $f]} {
6794 set treediffs($ids) $flist
6796 set treediffs($ids) $treediff
6799 if {$cmitmode eq "tree"} {
6801 } elseif {$ids != $diffids} {
6802 if {![info exists diffmergeid]} {
6803 gettreediffs $diffids
6811 # empty string or positive integer
6812 proc diffcontextvalidate {v} {
6813 return [regexp {^(|[1-9][0-9]*)$} $v]
6816 proc diffcontextchange {n1 n2 op} {
6817 global diffcontextstring diffcontext
6819 if {[string is integer -strict $diffcontextstring]} {
6820 if {$diffcontextstring > 0} {
6821 set diffcontext $diffcontextstring
6827 proc changeignorespace {} {
6831 proc getblobdiffs {ids} {
6832 global blobdifffd diffids env
6833 global diffinhdr treediffs
6836 global limitdiffs vfilelimit curview
6839 set cmd [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"]
6843 if {$limitdiffs && $vfilelimit($curview) ne {}} {
6844 set cmd [concat $cmd -- $vfilelimit($curview)]
6846 if {[catch {set bdf [open $cmd r]} err]} {
6847 puts "error getting diffs: $err"
6851 set diffencoding [get_path_encoding {}]
6852 fconfigure $bdf -blocking 0 -encoding binary
6853 set blobdifffd($ids) $bdf
6854 filerun $bdf [list getblobdiffline $bdf $diffids]
6857 proc setinlist {var i val} {
6860 while {[llength [set $var]] < $i} {
6863 if {[llength [set $var]] == $i} {
6870 proc makediffhdr {fname ids} {
6871 global ctext curdiffstart treediffs
6872 global ctext_file_names
6874 set i [lsearch -exact $treediffs($ids) $fname]
6876 setinlist difffilestart $i $curdiffstart
6878 set ctext_file_names [lreplace $ctext_file_names end end $fname]
6879 set l [expr {(78 - [string length $fname]) / 2}]
6880 set pad [string range "----------------------------------------" 1 $l]
6881 $ctext insert $curdiffstart "$pad $fname $pad" filesep
6884 proc getblobdiffline {bdf ids} {
6885 global diffids blobdifffd ctext curdiffstart
6886 global diffnexthead diffnextnote difffilestart
6887 global ctext_file_names ctext_file_lines
6888 global diffinhdr treediffs
6892 $ctext conf -state normal
6893 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
6894 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
6898 if {![string compare -length 11 "diff --git " $line]} {
6899 # trim off "diff --git "
6900 set line [string range $line 11 end]
6902 # start of a new file
6903 $ctext insert end "\n"
6904 set curdiffstart [$ctext index "end - 1c"]
6905 lappend ctext_file_names ""
6906 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
6907 $ctext insert end "\n" filesep
6908 # If the name hasn't changed the length will be odd,
6909 # the middle char will be a space, and the two bits either
6910 # side will be a/name and b/name, or "a/name" and "b/name".
6911 # If the name has changed we'll get "rename from" and
6912 # "rename to" or "copy from" and "copy to" lines following this,
6913 # and we'll use them to get the filenames.
6914 # This complexity is necessary because spaces in the filename(s)
6915 # don't get escaped.
6916 set l [string length $line]
6917 set i [expr {$l / 2}]
6918 if {!(($l & 1) && [string index $line $i] eq " " &&
6919 [string range $line 2 [expr {$i - 1}]] eq \
6920 [string range $line [expr {$i + 3}] end])} {
6923 # unescape if quoted and chop off the a/ from the front
6924 if {[string index $line 0] eq "\""} {
6925 set fname [string range [lindex $line 0] 2 end]
6927 set fname [string range $line 2 [expr {$i - 1}]]
6929 set fname [encoding convertfrom $fname]
6930 set diffencoding [get_path_encoding $fname]
6931 makediffhdr $fname $ids
6933 } elseif {[regexp {^@@ -([0-9]+)(,[0-9]+)? \+([0-9]+)(,[0-9]+)? @@(.*)} \
6934 $line match f1l f1c f2l f2c rest]} {
6935 set line [encoding convertfrom $diffencoding $line]
6936 $ctext insert end "$line\n" hunksep
6939 } elseif {$diffinhdr} {
6940 if {![string compare -length 12 "rename from " $line]} {
6941 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
6942 if {[string index $fname 0] eq "\""} {
6943 set fname [lindex $fname 0]
6945 set fname [encoding convertfrom $fname]
6946 set i [lsearch -exact $treediffs($ids) $fname]
6948 setinlist difffilestart $i $curdiffstart
6950 } elseif {![string compare -length 10 $line "rename to "] ||
6951 ![string compare -length 8 $line "copy to "]} {
6952 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
6953 if {[string index $fname 0] eq "\""} {
6954 set fname [lindex $fname 0]
6956 set fname [encoding convertfrom $fname]
6957 set diffencoding [get_path_encoding $fname]
6958 makediffhdr $fname $ids
6959 } elseif {[string compare -length 3 $line "---"] == 0} {
6962 } elseif {[string compare -length 3 $line "+++"] == 0} {
6966 $ctext insert end "$line\n" filesep
6969 set line [encoding convertfrom $diffencoding $line]
6970 set x [string range $line 0 0]
6971 if {$x == "-" || $x == "+"} {
6972 set tag [expr {$x == "+"}]
6973 $ctext insert end "$line\n" d$tag
6974 } elseif {$x == " "} {
6975 $ctext insert end "$line\n"
6977 # "\ No newline at end of file",
6978 # or something else we don't recognize
6979 $ctext insert end "$line\n" hunksep
6983 $ctext conf -state disabled
6988 return [expr {$nr >= 1000? 2: 1}]
6991 proc changediffdisp {} {
6992 global ctext diffelide
6994 $ctext tag conf d0 -elide [lindex $diffelide 0]
6995 $ctext tag conf d1 -elide [lindex $diffelide 1]
6998 proc highlightfile {loc cline} {
6999 global ctext cflist cflist_top
7002 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
7003 $cflist tag add highlight $cline.0 "$cline.0 lineend"
7004 $cflist see $cline.0
7005 set cflist_top $cline
7009 global difffilestart ctext cmitmode
7011 if {$cmitmode eq "tree"} return
7014 set here [$ctext index @0,0]
7015 foreach loc $difffilestart {
7016 if {[$ctext compare $loc >= $here]} {
7017 highlightfile $prev $prevline
7023 highlightfile $prev $prevline
7027 global difffilestart ctext cmitmode
7029 if {$cmitmode eq "tree"} return
7030 set here [$ctext index @0,0]
7032 foreach loc $difffilestart {
7034 if {[$ctext compare $loc > $here]} {
7035 highlightfile $loc $line
7041 proc clear_ctext {{first 1.0}} {
7042 global ctext smarktop smarkbot
7043 global ctext_file_names ctext_file_lines
7046 set l [lindex [split $first .] 0]
7047 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
7050 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
7053 $ctext delete $first end
7054 if {$first eq "1.0"} {
7055 catch {unset pendinglinks}
7057 set ctext_file_names {}
7058 set ctext_file_lines {}
7061 proc settabs {{firstab {}}} {
7062 global firsttabstop tabstop ctext have_tk85
7064 if {$firstab ne {} && $have_tk85} {
7065 set firsttabstop $firstab
7067 set w [font measure textfont "0"]
7068 if {$firsttabstop != 0} {
7069 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
7070 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
7071 } elseif {$have_tk85 || $tabstop != 8} {
7072 $ctext conf -tabs [expr {$tabstop * $w}]
7074 $ctext conf -tabs {}
7078 proc incrsearch {name ix op} {
7079 global ctext searchstring searchdirn
7081 $ctext tag remove found 1.0 end
7082 if {[catch {$ctext index anchor}]} {
7083 # no anchor set, use start of selection, or of visible area
7084 set sel [$ctext tag ranges sel]
7086 $ctext mark set anchor [lindex $sel 0]
7087 } elseif {$searchdirn eq "-forwards"} {
7088 $ctext mark set anchor @0,0
7090 $ctext mark set anchor @0,[winfo height $ctext]
7093 if {$searchstring ne {}} {
7094 set here [$ctext search $searchdirn -- $searchstring anchor]
7103 global sstring ctext searchstring searchdirn
7106 $sstring icursor end
7107 set searchdirn -forwards
7108 if {$searchstring ne {}} {
7109 set sel [$ctext tag ranges sel]
7111 set start "[lindex $sel 0] + 1c"
7112 } elseif {[catch {set start [$ctext index anchor]}]} {
7115 set match [$ctext search -count mlen -- $searchstring $start]
7116 $ctext tag remove sel 1.0 end
7122 set mend "$match + $mlen c"
7123 $ctext tag add sel $match $mend
7124 $ctext mark unset anchor
7128 proc dosearchback {} {
7129 global sstring ctext searchstring searchdirn
7132 $sstring icursor end
7133 set searchdirn -backwards
7134 if {$searchstring ne {}} {
7135 set sel [$ctext tag ranges sel]
7137 set start [lindex $sel 0]
7138 } elseif {[catch {set start [$ctext index anchor]}]} {
7139 set start @0,[winfo height $ctext]
7141 set match [$ctext search -backwards -count ml -- $searchstring $start]
7142 $ctext tag remove sel 1.0 end
7148 set mend "$match + $ml c"
7149 $ctext tag add sel $match $mend
7150 $ctext mark unset anchor
7154 proc searchmark {first last} {
7155 global ctext searchstring
7159 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
7160 if {$match eq {}} break
7161 set mend "$match + $mlen c"
7162 $ctext tag add found $match $mend
7166 proc searchmarkvisible {doall} {
7167 global ctext smarktop smarkbot
7169 set topline [lindex [split [$ctext index @0,0] .] 0]
7170 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
7171 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
7172 # no overlap with previous
7173 searchmark $topline $botline
7174 set smarktop $topline
7175 set smarkbot $botline
7177 if {$topline < $smarktop} {
7178 searchmark $topline [expr {$smarktop-1}]
7179 set smarktop $topline
7181 if {$botline > $smarkbot} {
7182 searchmark [expr {$smarkbot+1}] $botline
7183 set smarkbot $botline
7188 proc scrolltext {f0 f1} {
7191 .bleft.bottom.sb set $f0 $f1
7192 if {$searchstring ne {}} {
7198 global linespc charspc canvx0 canvy0
7199 global xspc1 xspc2 lthickness
7201 set linespc [font metrics mainfont -linespace]
7202 set charspc [font measure mainfont "m"]
7203 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
7204 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
7205 set lthickness [expr {int($linespc / 9) + 1}]
7206 set xspc1(0) $linespc
7214 set ymax [lindex [$canv cget -scrollregion] 3]
7215 if {$ymax eq {} || $ymax == 0} return
7216 set span [$canv yview]
7219 allcanvs yview moveto [lindex $span 0]
7221 if {$selectedline ne {}} {
7222 selectline $selectedline 0
7223 allcanvs yview moveto [lindex $span 0]
7227 proc parsefont {f n} {
7230 set fontattr($f,family) [lindex $n 0]
7232 if {$s eq {} || $s == 0} {
7235 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
7237 set fontattr($f,size) $s
7238 set fontattr($f,weight) normal
7239 set fontattr($f,slant) roman
7240 foreach style [lrange $n 2 end] {
7243 "bold" {set fontattr($f,weight) $style}
7245 "italic" {set fontattr($f,slant) $style}
7250 proc fontflags {f {isbold 0}} {
7253 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
7254 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
7255 -slant $fontattr($f,slant)]
7261 set n [list $fontattr($f,family) $fontattr($f,size)]
7262 if {$fontattr($f,weight) eq "bold"} {
7265 if {$fontattr($f,slant) eq "italic"} {
7271 proc incrfont {inc} {
7272 global mainfont textfont ctext canv cflist showrefstop
7273 global stopped entries fontattr
7276 set s $fontattr(mainfont,size)
7281 set fontattr(mainfont,size) $s
7282 font config mainfont -size $s
7283 font config mainfontbold -size $s
7284 set mainfont [fontname mainfont]
7285 set s $fontattr(textfont,size)
7290 set fontattr(textfont,size) $s
7291 font config textfont -size $s
7292 font config textfontbold -size $s
7293 set textfont [fontname textfont]
7300 global sha1entry sha1string
7301 if {[string length $sha1string] == 40} {
7302 $sha1entry delete 0 end
7306 proc sha1change {n1 n2 op} {
7307 global sha1string currentid sha1but
7308 if {$sha1string == {}
7309 || ([info exists currentid] && $sha1string == $currentid)} {
7314 if {[$sha1but cget -state] == $state} return
7315 if {$state == "normal"} {
7316 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
7318 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
7322 proc gotocommit {} {
7323 global sha1string tagids headids curview varcid
7325 if {$sha1string == {}
7326 || ([info exists currentid] && $sha1string == $currentid)} return
7327 if {[info exists tagids($sha1string)]} {
7328 set id $tagids($sha1string)
7329 } elseif {[info exists headids($sha1string)]} {
7330 set id $headids($sha1string)
7332 set id [string tolower $sha1string]
7333 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
7334 set matches [longid $id]
7335 if {$matches ne {}} {
7336 if {[llength $matches] > 1} {
7337 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
7340 set id [lindex $matches 0]
7344 if {[commitinview $id $curview]} {
7345 selectline [rowofcommit $id] 1
7348 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
7349 set msg [mc "SHA1 id %s is not known" $sha1string]
7351 set msg [mc "Tag/Head %s is not known" $sha1string]
7356 proc lineenter {x y id} {
7357 global hoverx hovery hoverid hovertimer
7358 global commitinfo canv
7360 if {![info exists commitinfo($id)] && ![getcommit $id]} return
7364 if {[info exists hovertimer]} {
7365 after cancel $hovertimer
7367 set hovertimer [after 500 linehover]
7371 proc linemotion {x y id} {
7372 global hoverx hovery hoverid hovertimer
7374 if {[info exists hoverid] && $id == $hoverid} {
7377 if {[info exists hovertimer]} {
7378 after cancel $hovertimer
7380 set hovertimer [after 500 linehover]
7384 proc lineleave {id} {
7385 global hoverid hovertimer canv
7387 if {[info exists hoverid] && $id == $hoverid} {
7389 if {[info exists hovertimer]} {
7390 after cancel $hovertimer
7398 global hoverx hovery hoverid hovertimer
7399 global canv linespc lthickness
7402 set text [lindex $commitinfo($hoverid) 0]
7403 set ymax [lindex [$canv cget -scrollregion] 3]
7404 if {$ymax == {}} return
7405 set yfrac [lindex [$canv yview] 0]
7406 set x [expr {$hoverx + 2 * $linespc}]
7407 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
7408 set x0 [expr {$x - 2 * $lthickness}]
7409 set y0 [expr {$y - 2 * $lthickness}]
7410 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
7411 set y1 [expr {$y + $linespc + 2 * $lthickness}]
7412 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
7413 -fill \#ffff80 -outline black -width 1 -tags hover]
7415 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
7420 proc clickisonarrow {id y} {
7423 set ranges [rowranges $id]
7424 set thresh [expr {2 * $lthickness + 6}]
7425 set n [expr {[llength $ranges] - 1}]
7426 for {set i 1} {$i < $n} {incr i} {
7427 set row [lindex $ranges $i]
7428 if {abs([yc $row] - $y) < $thresh} {
7435 proc arrowjump {id n y} {
7438 # 1 <-> 2, 3 <-> 4, etc...
7439 set n [expr {(($n - 1) ^ 1) + 1}]
7440 set row [lindex [rowranges $id] $n]
7442 set ymax [lindex [$canv cget -scrollregion] 3]
7443 if {$ymax eq {} || $ymax <= 0} return
7444 set view [$canv yview]
7445 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
7446 set yfrac [expr {$yt / $ymax - $yspan / 2}]
7450 allcanvs yview moveto $yfrac
7453 proc lineclick {x y id isnew} {
7454 global ctext commitinfo children canv thickerline curview
7456 if {![info exists commitinfo($id)] && ![getcommit $id]} return
7461 # draw this line thicker than normal
7465 set ymax [lindex [$canv cget -scrollregion] 3]
7466 if {$ymax eq {}} return
7467 set yfrac [lindex [$canv yview] 0]
7468 set y [expr {$y + $yfrac * $ymax}]
7470 set dirn [clickisonarrow $id $y]
7472 arrowjump $id $dirn $y
7477 addtohistory [list lineclick $x $y $id 0]
7479 # fill the details pane with info about this line
7480 $ctext conf -state normal
7483 $ctext insert end "[mc "Parent"]:\t"
7484 $ctext insert end $id link0
7486 set info $commitinfo($id)
7487 $ctext insert end "\n\t[lindex $info 0]\n"
7488 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
7489 set date [formatdate [lindex $info 2]]
7490 $ctext insert end "\t[mc "Date"]:\t$date\n"
7491 set kids $children($curview,$id)
7493 $ctext insert end "\n[mc "Children"]:"
7495 foreach child $kids {
7497 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
7498 set info $commitinfo($child)
7499 $ctext insert end "\n\t"
7500 $ctext insert end $child link$i
7501 setlink $child link$i
7502 $ctext insert end "\n\t[lindex $info 0]"
7503 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
7504 set date [formatdate [lindex $info 2]]
7505 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
7508 $ctext conf -state disabled
7512 proc normalline {} {
7514 if {[info exists thickerline]} {
7523 if {[commitinview $id $curview]} {
7524 selectline [rowofcommit $id] 1
7530 if {![info exists startmstime]} {
7531 set startmstime [clock clicks -milliseconds]
7533 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
7536 proc rowmenu {x y id} {
7537 global rowctxmenu selectedline rowmenuid curview
7538 global nullid nullid2 fakerowmenu mainhead
7542 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
7547 if {$id ne $nullid && $id ne $nullid2} {
7548 set menu $rowctxmenu
7549 if {$mainhead ne {}} {
7550 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead]
7552 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
7555 set menu $fakerowmenu
7557 $menu entryconfigure [mca "Diff this -> selected"] -state $state
7558 $menu entryconfigure [mca "Diff selected -> this"] -state $state
7559 $menu entryconfigure [mca "Make patch"] -state $state
7560 tk_popup $menu $x $y
7563 proc diffvssel {dirn} {
7564 global rowmenuid selectedline
7566 if {$selectedline eq {}} return
7568 set oldid [commitonrow $selectedline]
7569 set newid $rowmenuid
7571 set oldid $rowmenuid
7572 set newid [commitonrow $selectedline]
7574 addtohistory [list doseldiff $oldid $newid]
7575 doseldiff $oldid $newid
7578 proc doseldiff {oldid newid} {
7582 $ctext conf -state normal
7584 init_flist [mc "Top"]
7585 $ctext insert end "[mc "From"] "
7586 $ctext insert end $oldid link0
7587 setlink $oldid link0
7588 $ctext insert end "\n "
7589 $ctext insert end [lindex $commitinfo($oldid) 0]
7590 $ctext insert end "\n\n[mc "To"] "
7591 $ctext insert end $newid link1
7592 setlink $newid link1
7593 $ctext insert end "\n "
7594 $ctext insert end [lindex $commitinfo($newid) 0]
7595 $ctext insert end "\n"
7596 $ctext conf -state disabled
7597 $ctext tag remove found 1.0 end
7598 startdiff [list $oldid $newid]
7602 global rowmenuid currentid commitinfo patchtop patchnum
7604 if {![info exists currentid]} return
7605 set oldid $currentid
7606 set oldhead [lindex $commitinfo($oldid) 0]
7607 set newid $rowmenuid
7608 set newhead [lindex $commitinfo($newid) 0]
7611 catch {destroy $top}
7613 label $top.title -text [mc "Generate patch"]
7614 grid $top.title - -pady 10
7615 label $top.from -text [mc "From:"]
7616 entry $top.fromsha1 -width 40 -relief flat
7617 $top.fromsha1 insert 0 $oldid
7618 $top.fromsha1 conf -state readonly
7619 grid $top.from $top.fromsha1 -sticky w
7620 entry $top.fromhead -width 60 -relief flat
7621 $top.fromhead insert 0 $oldhead
7622 $top.fromhead conf -state readonly
7623 grid x $top.fromhead -sticky w
7624 label $top.to -text [mc "To:"]
7625 entry $top.tosha1 -width 40 -relief flat
7626 $top.tosha1 insert 0 $newid
7627 $top.tosha1 conf -state readonly
7628 grid $top.to $top.tosha1 -sticky w
7629 entry $top.tohead -width 60 -relief flat
7630 $top.tohead insert 0 $newhead
7631 $top.tohead conf -state readonly
7632 grid x $top.tohead -sticky w
7633 button $top.rev -text [mc "Reverse"] -command mkpatchrev -padx 5
7634 grid $top.rev x -pady 10
7635 label $top.flab -text [mc "Output file:"]
7636 entry $top.fname -width 60
7637 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
7639 grid $top.flab $top.fname -sticky w
7641 button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
7642 button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
7643 grid $top.buts.gen $top.buts.can
7644 grid columnconfigure $top.buts 0 -weight 1 -uniform a
7645 grid columnconfigure $top.buts 1 -weight 1 -uniform a
7646 grid $top.buts - -pady 10 -sticky ew
7650 proc mkpatchrev {} {
7653 set oldid [$patchtop.fromsha1 get]
7654 set oldhead [$patchtop.fromhead get]
7655 set newid [$patchtop.tosha1 get]
7656 set newhead [$patchtop.tohead get]
7657 foreach e [list fromsha1 fromhead tosha1 tohead] \
7658 v [list $newid $newhead $oldid $oldhead] {
7659 $patchtop.$e conf -state normal
7660 $patchtop.$e delete 0 end
7661 $patchtop.$e insert 0 $v
7662 $patchtop.$e conf -state readonly
7667 global patchtop nullid nullid2
7669 set oldid [$patchtop.fromsha1 get]
7670 set newid [$patchtop.tosha1 get]
7671 set fname [$patchtop.fname get]
7672 set cmd [diffcmd [list $oldid $newid] -p]
7673 # trim off the initial "|"
7674 set cmd [lrange $cmd 1 end]
7675 lappend cmd >$fname &
7676 if {[catch {eval exec $cmd} err]} {
7677 error_popup "[mc "Error creating patch:"] $err"
7679 catch {destroy $patchtop}
7683 proc mkpatchcan {} {
7686 catch {destroy $patchtop}
7691 global rowmenuid mktagtop commitinfo
7695 catch {destroy $top}
7697 label $top.title -text [mc "Create tag"]
7698 grid $top.title - -pady 10
7699 label $top.id -text [mc "ID:"]
7700 entry $top.sha1 -width 40 -relief flat
7701 $top.sha1 insert 0 $rowmenuid
7702 $top.sha1 conf -state readonly
7703 grid $top.id $top.sha1 -sticky w
7704 entry $top.head -width 60 -relief flat
7705 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
7706 $top.head conf -state readonly
7707 grid x $top.head -sticky w
7708 label $top.tlab -text [mc "Tag name:"]
7709 entry $top.tag -width 60
7710 grid $top.tlab $top.tag -sticky w
7712 button $top.buts.gen -text [mc "Create"] -command mktaggo
7713 button $top.buts.can -text [mc "Cancel"] -command mktagcan
7714 grid $top.buts.gen $top.buts.can
7715 grid columnconfigure $top.buts 0 -weight 1 -uniform a
7716 grid columnconfigure $top.buts 1 -weight 1 -uniform a
7717 grid $top.buts - -pady 10 -sticky ew
7722 global mktagtop env tagids idtags
7724 set id [$mktagtop.sha1 get]
7725 set tag [$mktagtop.tag get]
7727 error_popup [mc "No tag name specified"]
7730 if {[info exists tagids($tag)]} {
7731 error_popup [mc "Tag \"%s\" already exists" $tag]
7735 exec git tag $tag $id
7737 error_popup "[mc "Error creating tag:"] $err"
7741 set tagids($tag) $id
7742 lappend idtags($id) $tag
7749 proc redrawtags {id} {
7750 global canv linehtag idpos currentid curview cmitlisted
7751 global canvxmax iddrawn circleitem mainheadid circlecolors
7753 if {![commitinview $id $curview]} return
7754 if {![info exists iddrawn($id)]} return
7755 set row [rowofcommit $id]
7756 if {$id eq $mainheadid} {
7759 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
7761 $canv itemconf $circleitem($row) -fill $ofill
7762 $canv delete tag.$id
7763 set xt [eval drawtags $id $idpos($id)]
7764 $canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
7765 set text [$canv itemcget $linehtag($row) -text]
7766 set font [$canv itemcget $linehtag($row) -font]
7767 set xr [expr {$xt + [font measure $font $text]}]
7768 if {$xr > $canvxmax} {
7772 if {[info exists currentid] && $currentid == $id} {
7780 catch {destroy $mktagtop}
7789 proc writecommit {} {
7790 global rowmenuid wrcomtop commitinfo wrcomcmd
7792 set top .writecommit
7794 catch {destroy $top}
7796 label $top.title -text [mc "Write commit to file"]
7797 grid $top.title - -pady 10
7798 label $top.id -text [mc "ID:"]
7799 entry $top.sha1 -width 40 -relief flat
7800 $top.sha1 insert 0 $rowmenuid
7801 $top.sha1 conf -state readonly
7802 grid $top.id $top.sha1 -sticky w
7803 entry $top.head -width 60 -relief flat
7804 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
7805 $top.head conf -state readonly
7806 grid x $top.head -sticky w
7807 label $top.clab -text [mc "Command:"]
7808 entry $top.cmd -width 60 -textvariable wrcomcmd
7809 grid $top.clab $top.cmd -sticky w -pady 10
7810 label $top.flab -text [mc "Output file:"]
7811 entry $top.fname -width 60
7812 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
7813 grid $top.flab $top.fname -sticky w
7815 button $top.buts.gen -text [mc "Write"] -command wrcomgo
7816 button $top.buts.can -text [mc "Cancel"] -command wrcomcan
7817 grid $top.buts.gen $top.buts.can
7818 grid columnconfigure $top.buts 0 -weight 1 -uniform a
7819 grid columnconfigure $top.buts 1 -weight 1 -uniform a
7820 grid $top.buts - -pady 10 -sticky ew
7827 set id [$wrcomtop.sha1 get]
7828 set cmd "echo $id | [$wrcomtop.cmd get]"
7829 set fname [$wrcomtop.fname get]
7830 if {[catch {exec sh -c $cmd >$fname &} err]} {
7831 error_popup "[mc "Error writing commit:"] $err"
7833 catch {destroy $wrcomtop}
7840 catch {destroy $wrcomtop}
7845 global rowmenuid mkbrtop
7848 catch {destroy $top}
7850 label $top.title -text [mc "Create new branch"]
7851 grid $top.title - -pady 10
7852 label $top.id -text [mc "ID:"]
7853 entry $top.sha1 -width 40 -relief flat
7854 $top.sha1 insert 0 $rowmenuid
7855 $top.sha1 conf -state readonly
7856 grid $top.id $top.sha1 -sticky w
7857 label $top.nlab -text [mc "Name:"]
7858 entry $top.name -width 40
7859 bind $top.name <Key-Return> "[list mkbrgo $top]"
7860 grid $top.nlab $top.name -sticky w
7862 button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
7863 button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
7864 grid $top.buts.go $top.buts.can
7865 grid columnconfigure $top.buts 0 -weight 1 -uniform a
7866 grid columnconfigure $top.buts 1 -weight 1 -uniform a
7867 grid $top.buts - -pady 10 -sticky ew
7872 global headids idheads
7874 set name [$top.name get]
7875 set id [$top.sha1 get]
7879 error_popup [mc "Please specify a name for the new branch"]
7882 if {[info exists headids($name)]} {
7883 if {![confirm_popup [mc \
7884 "Branch '%s' already exists. Overwrite?" $name]]} {
7887 set old_id $headids($name)
7890 catch {destroy $top}
7891 lappend cmdargs $name $id
7895 eval exec git branch $cmdargs
7901 if {$old_id ne {}} {
7907 set headids($name) $id
7908 lappend idheads($id) $name
7917 proc cherrypick {} {
7918 global rowmenuid curview
7919 global mainhead mainheadid
7921 set oldhead [exec git rev-parse HEAD]
7922 set dheads [descheads $rowmenuid]
7923 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
7924 set ok [confirm_popup [mc "Commit %s is already\
7925 included in branch %s -- really re-apply it?" \
7926 [string range $rowmenuid 0 7] $mainhead]]
7929 nowbusy cherrypick [mc "Cherry-picking"]
7931 # Unfortunately git-cherry-pick writes stuff to stderr even when
7932 # no error occurs, and exec takes that as an indication of error...
7933 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
7938 set newhead [exec git rev-parse HEAD]
7939 if {$newhead eq $oldhead} {
7941 error_popup [mc "No changes committed"]
7944 addnewchild $newhead $oldhead
7945 if {[commitinview $oldhead $curview]} {
7946 insertrow $newhead $oldhead $curview
7947 if {$mainhead ne {}} {
7948 movehead $newhead $mainhead
7949 movedhead $newhead $mainhead
7951 set mainheadid $newhead
7960 global mainhead rowmenuid confirm_ok resettype
7963 set w ".confirmreset"
7966 wm title $w [mc "Confirm reset"]
7967 message $w.m -text \
7968 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]] \
7969 -justify center -aspect 1000
7970 pack $w.m -side top -fill x -padx 20 -pady 20
7971 frame $w.f -relief sunken -border 2
7972 message $w.f.rt -text [mc "Reset type:"] -aspect 1000
7973 grid $w.f.rt -sticky w
7975 radiobutton $w.f.soft -value soft -variable resettype -justify left \
7976 -text [mc "Soft: Leave working tree and index untouched"]
7977 grid $w.f.soft -sticky w
7978 radiobutton $w.f.mixed -value mixed -variable resettype -justify left \
7979 -text [mc "Mixed: Leave working tree untouched, reset index"]
7980 grid $w.f.mixed -sticky w
7981 radiobutton $w.f.hard -value hard -variable resettype -justify left \
7982 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
7983 grid $w.f.hard -sticky w
7984 pack $w.f -side top -fill x
7985 button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
7986 pack $w.ok -side left -fill x -padx 20 -pady 20
7987 button $w.cancel -text [mc Cancel] -command "destroy $w"
7988 pack $w.cancel -side right -fill x -padx 20 -pady 20
7989 bind $w <Visibility> "grab $w; focus $w"
7991 if {!$confirm_ok} return
7992 if {[catch {set fd [open \
7993 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
7997 filerun $fd [list readresetstat $fd]
7998 nowbusy reset [mc "Resetting"]
8003 proc readresetstat {fd} {
8004 global mainhead mainheadid showlocalchanges rprogcoord
8006 if {[gets $fd line] >= 0} {
8007 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
8008 set rprogcoord [expr {1.0 * $m / $n}]
8016 if {[catch {close $fd} err]} {
8019 set oldhead $mainheadid
8020 set newhead [exec git rev-parse HEAD]
8021 if {$newhead ne $oldhead} {
8022 movehead $newhead $mainhead
8023 movedhead $newhead $mainhead
8024 set mainheadid $newhead
8028 if {$showlocalchanges} {
8034 # context menu for a head
8035 proc headmenu {x y id head} {
8036 global headmenuid headmenuhead headctxmenu mainhead
8040 set headmenuhead $head
8042 if {$head eq $mainhead} {
8045 $headctxmenu entryconfigure 0 -state $state
8046 $headctxmenu entryconfigure 1 -state $state
8047 tk_popup $headctxmenu $x $y
8051 global headmenuid headmenuhead headids
8052 global showlocalchanges mainheadid
8054 # check the tree is clean first??
8055 nowbusy checkout [mc "Checking out"]
8059 set fd [open [list | git checkout $headmenuhead 2>@1] r]
8063 if {$showlocalchanges} {
8067 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
8071 proc readcheckoutstat {fd newhead newheadid} {
8072 global mainhead mainheadid headids showlocalchanges progresscoords
8074 if {[gets $fd line] >= 0} {
8075 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
8076 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
8081 set progresscoords {0 0}
8084 if {[catch {close $fd} err]} {
8087 set oldmainid $mainheadid
8088 set mainhead $newhead
8089 set mainheadid $newheadid
8090 redrawtags $oldmainid
8091 redrawtags $newheadid
8093 if {$showlocalchanges} {
8099 global headmenuid headmenuhead mainhead
8102 set head $headmenuhead
8104 # this check shouldn't be needed any more...
8105 if {$head eq $mainhead} {
8106 error_popup [mc "Cannot delete the currently checked-out branch"]
8109 set dheads [descheads $id]
8110 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
8111 # the stuff on this branch isn't on any other branch
8112 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
8113 branch.\nReally delete branch %s?" $head $head]]} return
8117 if {[catch {exec git branch -D $head} err]} {
8122 removehead $id $head
8123 removedhead $id $head
8130 # Display a list of tags and heads
8132 global showrefstop bgcolor fgcolor selectbgcolor
8133 global bglist fglist reflistfilter reflist maincursor
8136 set showrefstop $top
8137 if {[winfo exists $top]} {
8143 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
8144 text $top.list -background $bgcolor -foreground $fgcolor \
8145 -selectbackground $selectbgcolor -font mainfont \
8146 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
8147 -width 30 -height 20 -cursor $maincursor \
8148 -spacing1 1 -spacing3 1 -state disabled
8149 $top.list tag configure highlight -background $selectbgcolor
8150 lappend bglist $top.list
8151 lappend fglist $top.list
8152 scrollbar $top.ysb -command "$top.list yview" -orient vertical
8153 scrollbar $top.xsb -command "$top.list xview" -orient horizontal
8154 grid $top.list $top.ysb -sticky nsew
8155 grid $top.xsb x -sticky ew
8157 label $top.f.l -text "[mc "Filter"]: "
8158 entry $top.f.e -width 20 -textvariable reflistfilter
8159 set reflistfilter "*"
8160 trace add variable reflistfilter write reflistfilter_change
8161 pack $top.f.e -side right -fill x -expand 1
8162 pack $top.f.l -side left
8163 grid $top.f - -sticky ew -pady 2
8164 button $top.close -command [list destroy $top] -text [mc "Close"]
8166 grid columnconfigure $top 0 -weight 1
8167 grid rowconfigure $top 0 -weight 1
8168 bind $top.list <1> {break}
8169 bind $top.list <B1-Motion> {break}
8170 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
8175 proc sel_reflist {w x y} {
8176 global showrefstop reflist headids tagids otherrefids
8178 if {![winfo exists $showrefstop]} return
8179 set l [lindex [split [$w index "@$x,$y"] "."] 0]
8180 set ref [lindex $reflist [expr {$l-1}]]
8181 set n [lindex $ref 0]
8182 switch -- [lindex $ref 1] {
8183 "H" {selbyid $headids($n)}
8184 "T" {selbyid $tagids($n)}
8185 "o" {selbyid $otherrefids($n)}
8187 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
8190 proc unsel_reflist {} {
8193 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
8194 $showrefstop.list tag remove highlight 0.0 end
8197 proc reflistfilter_change {n1 n2 op} {
8198 global reflistfilter
8200 after cancel refill_reflist
8201 after 200 refill_reflist
8204 proc refill_reflist {} {
8205 global reflist reflistfilter showrefstop headids tagids otherrefids
8208 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
8210 foreach n [array names headids] {
8211 if {[string match $reflistfilter $n]} {
8212 if {[commitinview $headids($n) $curview]} {
8213 lappend refs [list $n H]
8215 interestedin $headids($n) {run refill_reflist}
8219 foreach n [array names tagids] {
8220 if {[string match $reflistfilter $n]} {
8221 if {[commitinview $tagids($n) $curview]} {
8222 lappend refs [list $n T]
8224 interestedin $tagids($n) {run refill_reflist}
8228 foreach n [array names otherrefids] {
8229 if {[string match $reflistfilter $n]} {
8230 if {[commitinview $otherrefids($n) $curview]} {
8231 lappend refs [list $n o]
8233 interestedin $otherrefids($n) {run refill_reflist}
8237 set refs [lsort -index 0 $refs]
8238 if {$refs eq $reflist} return
8240 # Update the contents of $showrefstop.list according to the
8241 # differences between $reflist (old) and $refs (new)
8242 $showrefstop.list conf -state normal
8243 $showrefstop.list insert end "\n"
8246 while {$i < [llength $reflist] || $j < [llength $refs]} {
8247 if {$i < [llength $reflist]} {
8248 if {$j < [llength $refs]} {
8249 set cmp [string compare [lindex $reflist $i 0] \
8250 [lindex $refs $j 0]]
8252 set cmp [string compare [lindex $reflist $i 1] \
8253 [lindex $refs $j 1]]
8263 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
8271 set l [expr {$j + 1}]
8272 $showrefstop.list image create $l.0 -align baseline \
8273 -image reficon-[lindex $refs $j 1] -padx 2
8274 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
8280 # delete last newline
8281 $showrefstop.list delete end-2c end-1c
8282 $showrefstop.list conf -state disabled
8285 # Stuff for finding nearby tags
8286 proc getallcommits {} {
8287 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
8288 global idheads idtags idotherrefs allparents tagobjid
8290 if {![info exists allcommits]} {
8296 set allccache [file join [gitdir] "gitk.cache"]
8298 set f [open $allccache r]
8307 set cmd [list | git rev-list --parents]
8308 set allcupdate [expr {$seeds ne {}}]
8312 set refs [concat [array names idheads] [array names idtags] \
8313 [array names idotherrefs]]
8316 foreach name [array names tagobjid] {
8317 lappend tagobjs $tagobjid($name)
8319 foreach id [lsort -unique $refs] {
8320 if {![info exists allparents($id)] &&
8321 [lsearch -exact $tagobjs $id] < 0} {
8332 set fd [open [concat $cmd $ids] r]
8333 fconfigure $fd -blocking 0
8336 filerun $fd [list getallclines $fd]
8342 # Since most commits have 1 parent and 1 child, we group strings of
8343 # such commits into "arcs" joining branch/merge points (BMPs), which
8344 # are commits that either don't have 1 parent or don't have 1 child.
8346 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
8347 # arcout(id) - outgoing arcs for BMP
8348 # arcids(a) - list of IDs on arc including end but not start
8349 # arcstart(a) - BMP ID at start of arc
8350 # arcend(a) - BMP ID at end of arc
8351 # growing(a) - arc a is still growing
8352 # arctags(a) - IDs out of arcids (excluding end) that have tags
8353 # archeads(a) - IDs out of arcids (excluding end) that have heads
8354 # The start of an arc is at the descendent end, so "incoming" means
8355 # coming from descendents, and "outgoing" means going towards ancestors.
8357 proc getallclines {fd} {
8358 global allparents allchildren idtags idheads nextarc
8359 global arcnos arcids arctags arcout arcend arcstart archeads growing
8360 global seeds allcommits cachedarcs allcupdate
8363 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
8364 set id [lindex $line 0]
8365 if {[info exists allparents($id)]} {
8370 set olds [lrange $line 1 end]
8371 set allparents($id) $olds
8372 if {![info exists allchildren($id)]} {
8373 set allchildren($id) {}
8378 if {[llength $olds] == 1 && [llength $a] == 1} {
8379 lappend arcids($a) $id
8380 if {[info exists idtags($id)]} {
8381 lappend arctags($a) $id
8383 if {[info exists idheads($id)]} {
8384 lappend archeads($a) $id
8386 if {[info exists allparents($olds)]} {
8387 # seen parent already
8388 if {![info exists arcout($olds)]} {
8391 lappend arcids($a) $olds
8392 set arcend($a) $olds
8395 lappend allchildren($olds) $id
8396 lappend arcnos($olds) $a
8400 foreach a $arcnos($id) {
8401 lappend arcids($a) $id
8408 lappend allchildren($p) $id
8409 set a [incr nextarc]
8410 set arcstart($a) $id
8417 if {[info exists allparents($p)]} {
8418 # seen it already, may need to make a new branch
8419 if {![info exists arcout($p)]} {
8422 lappend arcids($a) $p
8426 lappend arcnos($p) $a
8431 global cached_dheads cached_dtags cached_atags
8432 catch {unset cached_dheads}
8433 catch {unset cached_dtags}
8434 catch {unset cached_atags}
8437 return [expr {$nid >= 1000? 2: 1}]
8441 fconfigure $fd -blocking 1
8444 # got an error reading the list of commits
8445 # if we were updating, try rereading the whole thing again
8451 error_popup "[mc "Error reading commit topology information;\
8452 branch and preceding/following tag information\
8453 will be incomplete."]\n($err)"
8456 if {[incr allcommits -1] == 0} {
8466 proc recalcarc {a} {
8467 global arctags archeads arcids idtags idheads
8471 foreach id [lrange $arcids($a) 0 end-1] {
8472 if {[info exists idtags($id)]} {
8475 if {[info exists idheads($id)]} {
8480 set archeads($a) $ah
8484 global arcnos arcids nextarc arctags archeads idtags idheads
8485 global arcstart arcend arcout allparents growing
8488 if {[llength $a] != 1} {
8489 puts "oops splitarc called but [llength $a] arcs already"
8493 set i [lsearch -exact $arcids($a) $p]
8495 puts "oops splitarc $p not in arc $a"
8498 set na [incr nextarc]
8499 if {[info exists arcend($a)]} {
8500 set arcend($na) $arcend($a)
8502 set l [lindex $allparents([lindex $arcids($a) end]) 0]
8503 set j [lsearch -exact $arcnos($l) $a]
8504 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
8506 set tail [lrange $arcids($a) [expr {$i+1}] end]
8507 set arcids($a) [lrange $arcids($a) 0 $i]
8509 set arcstart($na) $p
8511 set arcids($na) $tail
8512 if {[info exists growing($a)]} {
8518 if {[llength $arcnos($id)] == 1} {
8521 set j [lsearch -exact $arcnos($id) $a]
8522 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
8526 # reconstruct tags and heads lists
8527 if {$arctags($a) ne {} || $archeads($a) ne {}} {
8532 set archeads($na) {}
8536 # Update things for a new commit added that is a child of one
8537 # existing commit. Used when cherry-picking.
8538 proc addnewchild {id p} {
8539 global allparents allchildren idtags nextarc
8540 global arcnos arcids arctags arcout arcend arcstart archeads growing
8541 global seeds allcommits
8543 if {![info exists allcommits] || ![info exists arcnos($p)]} return
8544 set allparents($id) [list $p]
8545 set allchildren($id) {}
8548 lappend allchildren($p) $id
8549 set a [incr nextarc]
8550 set arcstart($a) $id
8553 set arcids($a) [list $p]
8555 if {![info exists arcout($p)]} {
8558 lappend arcnos($p) $a
8559 set arcout($id) [list $a]
8562 # This implements a cache for the topology information.
8563 # The cache saves, for each arc, the start and end of the arc,
8564 # the ids on the arc, and the outgoing arcs from the end.
8565 proc readcache {f} {
8566 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
8567 global idtags idheads allparents cachedarcs possible_seeds seeds growing
8572 if {$lim - $a > 500} {
8573 set lim [expr {$a + 500}]
8577 # finish reading the cache and setting up arctags, etc.
8579 if {$line ne "1"} {error "bad final version"}
8581 foreach id [array names idtags] {
8582 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
8583 [llength $allparents($id)] == 1} {
8584 set a [lindex $arcnos($id) 0]
8585 if {$arctags($a) eq {}} {
8590 foreach id [array names idheads] {
8591 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
8592 [llength $allparents($id)] == 1} {
8593 set a [lindex $arcnos($id) 0]
8594 if {$archeads($a) eq {}} {
8599 foreach id [lsort -unique $possible_seeds] {
8600 if {$arcnos($id) eq {}} {
8606 while {[incr a] <= $lim} {
8608 if {[llength $line] != 3} {error "bad line"}
8609 set s [lindex $line 0]
8611 lappend arcout($s) $a
8612 if {![info exists arcnos($s)]} {
8613 lappend possible_seeds $s
8616 set e [lindex $line 1]
8621 if {![info exists arcout($e)]} {
8625 set arcids($a) [lindex $line 2]
8626 foreach id $arcids($a) {
8627 lappend allparents($s) $id
8629 lappend arcnos($id) $a
8631 if {![info exists allparents($s)]} {
8632 set allparents($s) {}
8637 set nextarc [expr {$a - 1}]
8650 global nextarc cachedarcs possible_seeds
8654 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
8655 # make sure it's an integer
8656 set cachedarcs [expr {int([lindex $line 1])}]
8657 if {$cachedarcs < 0} {error "bad number of arcs"}
8659 set possible_seeds {}
8667 proc dropcache {err} {
8668 global allcwait nextarc cachedarcs seeds
8670 #puts "dropping cache ($err)"
8671 foreach v {arcnos arcout arcids arcstart arcend growing \
8672 arctags archeads allparents allchildren} {
8683 proc writecache {f} {
8684 global cachearc cachedarcs allccache
8685 global arcstart arcend arcnos arcids arcout
8689 if {$lim - $a > 1000} {
8690 set lim [expr {$a + 1000}]
8693 while {[incr a] <= $lim} {
8694 if {[info exists arcend($a)]} {
8695 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
8697 puts $f [list $arcstart($a) {} $arcids($a)]
8702 catch {file delete $allccache}
8703 #puts "writing cache failed ($err)"
8706 set cachearc [expr {$a - 1}]
8707 if {$a > $cachedarcs} {
8716 global nextarc cachedarcs cachearc allccache
8718 if {$nextarc == $cachedarcs} return
8720 set cachedarcs $nextarc
8722 set f [open $allccache w]
8723 puts $f [list 1 $cachedarcs]
8728 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
8729 # or 0 if neither is true.
8730 proc anc_or_desc {a b} {
8731 global arcout arcstart arcend arcnos cached_isanc
8733 if {$arcnos($a) eq $arcnos($b)} {
8734 # Both are on the same arc(s); either both are the same BMP,
8735 # or if one is not a BMP, the other is also not a BMP or is
8736 # the BMP at end of the arc (and it only has 1 incoming arc).
8737 # Or both can be BMPs with no incoming arcs.
8738 if {$a eq $b || $arcnos($a) eq {}} {
8741 # assert {[llength $arcnos($a)] == 1}
8742 set arc [lindex $arcnos($a) 0]
8743 set i [lsearch -exact $arcids($arc) $a]
8744 set j [lsearch -exact $arcids($arc) $b]
8745 if {$i < 0 || $i > $j} {
8752 if {![info exists arcout($a)]} {
8753 set arc [lindex $arcnos($a) 0]
8754 if {[info exists arcend($arc)]} {
8755 set aend $arcend($arc)
8759 set a $arcstart($arc)
8763 if {![info exists arcout($b)]} {
8764 set arc [lindex $arcnos($b) 0]
8765 if {[info exists arcend($arc)]} {
8766 set bend $arcend($arc)
8770 set b $arcstart($arc)
8780 if {[info exists cached_isanc($a,$bend)]} {
8781 if {$cached_isanc($a,$bend)} {
8785 if {[info exists cached_isanc($b,$aend)]} {
8786 if {$cached_isanc($b,$aend)} {
8789 if {[info exists cached_isanc($a,$bend)]} {
8794 set todo [list $a $b]
8797 for {set i 0} {$i < [llength $todo]} {incr i} {
8798 set x [lindex $todo $i]
8799 if {$anc($x) eq {}} {
8802 foreach arc $arcnos($x) {
8803 set xd $arcstart($arc)
8805 set cached_isanc($a,$bend) 1
8806 set cached_isanc($b,$aend) 0
8808 } elseif {$xd eq $aend} {
8809 set cached_isanc($b,$aend) 1
8810 set cached_isanc($a,$bend) 0
8813 if {![info exists anc($xd)]} {
8814 set anc($xd) $anc($x)
8816 } elseif {$anc($xd) ne $anc($x)} {
8821 set cached_isanc($a,$bend) 0
8822 set cached_isanc($b,$aend) 0
8826 # This identifies whether $desc has an ancestor that is
8827 # a growing tip of the graph and which is not an ancestor of $anc
8828 # and returns 0 if so and 1 if not.
8829 # If we subsequently discover a tag on such a growing tip, and that
8830 # turns out to be a descendent of $anc (which it could, since we
8831 # don't necessarily see children before parents), then $desc
8832 # isn't a good choice to display as a descendent tag of
8833 # $anc (since it is the descendent of another tag which is
8834 # a descendent of $anc). Similarly, $anc isn't a good choice to
8835 # display as a ancestor tag of $desc.
8837 proc is_certain {desc anc} {
8838 global arcnos arcout arcstart arcend growing problems
8841 if {[llength $arcnos($anc)] == 1} {
8842 # tags on the same arc are certain
8843 if {$arcnos($desc) eq $arcnos($anc)} {
8846 if {![info exists arcout($anc)]} {
8847 # if $anc is partway along an arc, use the start of the arc instead
8848 set a [lindex $arcnos($anc) 0]
8849 set anc $arcstart($a)
8852 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
8855 set a [lindex $arcnos($desc) 0]
8861 set anclist [list $x]
8865 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
8866 set x [lindex $anclist $i]
8871 foreach a $arcout($x) {
8872 if {[info exists growing($a)]} {
8873 if {![info exists growanc($x)] && $dl($x)} {
8879 if {[info exists dl($y)]} {
8883 if {![info exists done($y)]} {
8886 if {[info exists growanc($x)]} {
8890 for {set k 0} {$k < [llength $xl]} {incr k} {
8891 set z [lindex $xl $k]
8892 foreach c $arcout($z) {
8893 if {[info exists arcend($c)]} {
8895 if {[info exists dl($v)] && $dl($v)} {
8897 if {![info exists done($v)]} {
8900 if {[info exists growanc($v)]} {
8910 } elseif {$y eq $anc || !$dl($x)} {
8921 foreach x [array names growanc] {
8930 proc validate_arctags {a} {
8931 global arctags idtags
8935 foreach id $arctags($a) {
8937 if {![info exists idtags($id)]} {
8938 set na [lreplace $na $i $i]
8945 proc validate_archeads {a} {
8946 global archeads idheads
8949 set na $archeads($a)
8950 foreach id $archeads($a) {
8952 if {![info exists idheads($id)]} {
8953 set na [lreplace $na $i $i]
8957 set archeads($a) $na
8960 # Return the list of IDs that have tags that are descendents of id,
8961 # ignoring IDs that are descendents of IDs already reported.
8962 proc desctags {id} {
8963 global arcnos arcstart arcids arctags idtags allparents
8964 global growing cached_dtags
8966 if {![info exists allparents($id)]} {
8969 set t1 [clock clicks -milliseconds]
8971 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
8972 # part-way along an arc; check that arc first
8973 set a [lindex $arcnos($id) 0]
8974 if {$arctags($a) ne {}} {
8976 set i [lsearch -exact $arcids($a) $id]
8978 foreach t $arctags($a) {
8979 set j [lsearch -exact $arcids($a) $t]
8987 set id $arcstart($a)
8988 if {[info exists idtags($id)]} {
8992 if {[info exists cached_dtags($id)]} {
8993 return $cached_dtags($id)
9000 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
9001 set id [lindex $todo $i]
9003 set ta [info exists hastaggedancestor($id)]
9007 # ignore tags on starting node
9008 if {!$ta && $i > 0} {
9009 if {[info exists idtags($id)]} {
9012 } elseif {[info exists cached_dtags($id)]} {
9013 set tagloc($id) $cached_dtags($id)
9017 foreach a $arcnos($id) {
9019 if {!$ta && $arctags($a) ne {}} {
9021 if {$arctags($a) ne {}} {
9022 lappend tagloc($id) [lindex $arctags($a) end]
9025 if {$ta || $arctags($a) ne {}} {
9026 set tomark [list $d]
9027 for {set j 0} {$j < [llength $tomark]} {incr j} {
9028 set dd [lindex $tomark $j]
9029 if {![info exists hastaggedancestor($dd)]} {
9030 if {[info exists done($dd)]} {
9031 foreach b $arcnos($dd) {
9032 lappend tomark $arcstart($b)
9034 if {[info exists tagloc($dd)]} {
9037 } elseif {[info exists queued($dd)]} {
9040 set hastaggedancestor($dd) 1
9044 if {![info exists queued($d)]} {
9047 if {![info exists hastaggedancestor($d)]} {
9054 foreach id [array names tagloc] {
9055 if {![info exists hastaggedancestor($id)]} {
9056 foreach t $tagloc($id) {
9057 if {[lsearch -exact $tags $t] < 0} {
9063 set t2 [clock clicks -milliseconds]
9066 # remove tags that are descendents of other tags
9067 for {set i 0} {$i < [llength $tags]} {incr i} {
9068 set a [lindex $tags $i]
9069 for {set j 0} {$j < $i} {incr j} {
9070 set b [lindex $tags $j]
9071 set r [anc_or_desc $a $b]
9073 set tags [lreplace $tags $j $j]
9076 } elseif {$r == -1} {
9077 set tags [lreplace $tags $i $i]
9084 if {[array names growing] ne {}} {
9085 # graph isn't finished, need to check if any tag could get
9086 # eclipsed by another tag coming later. Simply ignore any
9087 # tags that could later get eclipsed.
9090 if {[is_certain $t $origid]} {
9094 if {$tags eq $ctags} {
9095 set cached_dtags($origid) $tags
9100 set cached_dtags($origid) $tags
9102 set t3 [clock clicks -milliseconds]
9103 if {0 && $t3 - $t1 >= 100} {
9104 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
9105 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
9111 global arcnos arcids arcout arcend arctags idtags allparents
9112 global growing cached_atags
9114 if {![info exists allparents($id)]} {
9117 set t1 [clock clicks -milliseconds]
9119 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
9120 # part-way along an arc; check that arc first
9121 set a [lindex $arcnos($id) 0]
9122 if {$arctags($a) ne {}} {
9124 set i [lsearch -exact $arcids($a) $id]
9125 foreach t $arctags($a) {
9126 set j [lsearch -exact $arcids($a) $t]
9132 if {![info exists arcend($a)]} {
9136 if {[info exists idtags($id)]} {
9140 if {[info exists cached_atags($id)]} {
9141 return $cached_atags($id)
9149 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
9150 set id [lindex $todo $i]
9152 set td [info exists hastaggeddescendent($id)]
9156 # ignore tags on starting node
9157 if {!$td && $i > 0} {
9158 if {[info exists idtags($id)]} {
9161 } elseif {[info exists cached_atags($id)]} {
9162 set tagloc($id) $cached_atags($id)
9166 foreach a $arcout($id) {
9167 if {!$td && $arctags($a) ne {}} {
9169 if {$arctags($a) ne {}} {
9170 lappend tagloc($id) [lindex $arctags($a) 0]
9173 if {![info exists arcend($a)]} continue
9175 if {$td || $arctags($a) ne {}} {
9176 set tomark [list $d]
9177 for {set j 0} {$j < [llength $tomark]} {incr j} {
9178 set dd [lindex $tomark $j]
9179 if {![info exists hastaggeddescendent($dd)]} {
9180 if {[info exists done($dd)]} {
9181 foreach b $arcout($dd) {
9182 if {[info exists arcend($b)]} {
9183 lappend tomark $arcend($b)
9186 if {[info exists tagloc($dd)]} {
9189 } elseif {[info exists queued($dd)]} {
9192 set hastaggeddescendent($dd) 1
9196 if {![info exists queued($d)]} {
9199 if {![info exists hastaggeddescendent($d)]} {
9205 set t2 [clock clicks -milliseconds]
9208 foreach id [array names tagloc] {
9209 if {![info exists hastaggeddescendent($id)]} {
9210 foreach t $tagloc($id) {
9211 if {[lsearch -exact $tags $t] < 0} {
9218 # remove tags that are ancestors of other tags
9219 for {set i 0} {$i < [llength $tags]} {incr i} {
9220 set a [lindex $tags $i]
9221 for {set j 0} {$j < $i} {incr j} {
9222 set b [lindex $tags $j]
9223 set r [anc_or_desc $a $b]
9225 set tags [lreplace $tags $j $j]
9228 } elseif {$r == 1} {
9229 set tags [lreplace $tags $i $i]
9236 if {[array names growing] ne {}} {
9237 # graph isn't finished, need to check if any tag could get
9238 # eclipsed by another tag coming later. Simply ignore any
9239 # tags that could later get eclipsed.
9242 if {[is_certain $origid $t]} {
9246 if {$tags eq $ctags} {
9247 set cached_atags($origid) $tags
9252 set cached_atags($origid) $tags
9254 set t3 [clock clicks -milliseconds]
9255 if {0 && $t3 - $t1 >= 100} {
9256 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
9257 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
9262 # Return the list of IDs that have heads that are descendents of id,
9263 # including id itself if it has a head.
9264 proc descheads {id} {
9265 global arcnos arcstart arcids archeads idheads cached_dheads
9268 if {![info exists allparents($id)]} {
9272 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
9273 # part-way along an arc; check it first
9274 set a [lindex $arcnos($id) 0]
9275 if {$archeads($a) ne {}} {
9276 validate_archeads $a
9277 set i [lsearch -exact $arcids($a) $id]
9278 foreach t $archeads($a) {
9279 set j [lsearch -exact $arcids($a) $t]
9284 set id $arcstart($a)
9290 for {set i 0} {$i < [llength $todo]} {incr i} {
9291 set id [lindex $todo $i]
9292 if {[info exists cached_dheads($id)]} {
9293 set ret [concat $ret $cached_dheads($id)]
9295 if {[info exists idheads($id)]} {
9298 foreach a $arcnos($id) {
9299 if {$archeads($a) ne {}} {
9300 validate_archeads $a
9301 if {$archeads($a) ne {}} {
9302 set ret [concat $ret $archeads($a)]
9306 if {![info exists seen($d)]} {
9313 set ret [lsort -unique $ret]
9314 set cached_dheads($origid) $ret
9315 return [concat $ret $aret]
9318 proc addedtag {id} {
9319 global arcnos arcout cached_dtags cached_atags
9321 if {![info exists arcnos($id)]} return
9322 if {![info exists arcout($id)]} {
9323 recalcarc [lindex $arcnos($id) 0]
9325 catch {unset cached_dtags}
9326 catch {unset cached_atags}
9329 proc addedhead {hid head} {
9330 global arcnos arcout cached_dheads
9332 if {![info exists arcnos($hid)]} return
9333 if {![info exists arcout($hid)]} {
9334 recalcarc [lindex $arcnos($hid) 0]
9336 catch {unset cached_dheads}
9339 proc removedhead {hid head} {
9340 global cached_dheads
9342 catch {unset cached_dheads}
9345 proc movedhead {hid head} {
9346 global arcnos arcout cached_dheads
9348 if {![info exists arcnos($hid)]} return
9349 if {![info exists arcout($hid)]} {
9350 recalcarc [lindex $arcnos($hid) 0]
9352 catch {unset cached_dheads}
9355 proc changedrefs {} {
9356 global cached_dheads cached_dtags cached_atags
9357 global arctags archeads arcnos arcout idheads idtags
9359 foreach id [concat [array names idheads] [array names idtags]] {
9360 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
9361 set a [lindex $arcnos($id) 0]
9362 if {![info exists donearc($a)]} {
9368 catch {unset cached_dtags}
9369 catch {unset cached_atags}
9370 catch {unset cached_dheads}
9373 proc rereadrefs {} {
9374 global idtags idheads idotherrefs mainheadid
9376 set refids [concat [array names idtags] \
9377 [array names idheads] [array names idotherrefs]]
9378 foreach id $refids {
9379 if {![info exists ref($id)]} {
9380 set ref($id) [listrefs $id]
9383 set oldmainhead $mainheadid
9386 set refids [lsort -unique [concat $refids [array names idtags] \
9387 [array names idheads] [array names idotherrefs]]]
9388 foreach id $refids {
9389 set v [listrefs $id]
9390 if {![info exists ref($id)] || $ref($id) != $v} {
9394 if {$oldmainhead ne $mainheadid} {
9395 redrawtags $oldmainhead
9396 redrawtags $mainheadid
9401 proc listrefs {id} {
9402 global idtags idheads idotherrefs
9405 if {[info exists idtags($id)]} {
9409 if {[info exists idheads($id)]} {
9413 if {[info exists idotherrefs($id)]} {
9414 set z $idotherrefs($id)
9416 return [list $x $y $z]
9419 proc showtag {tag isnew} {
9420 global ctext tagcontents tagids linknum tagobjid
9423 addtohistory [list showtag $tag 0]
9425 $ctext conf -state normal
9429 if {![info exists tagcontents($tag)]} {
9431 set tagcontents($tag) [exec git cat-file tag $tagobjid($tag)]
9434 if {[info exists tagcontents($tag)]} {
9435 set text $tagcontents($tag)
9437 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
9439 appendwithlinks $text {}
9440 $ctext conf -state disabled
9452 if {[info exists gitktmpdir]} {
9453 catch {file delete -force $gitktmpdir}
9457 proc mkfontdisp {font top which} {
9458 global fontattr fontpref $font
9460 set fontpref($font) [set $font]
9461 button $top.${font}but -text $which -font optionfont \
9462 -command [list choosefont $font $which]
9463 label $top.$font -relief flat -font $font \
9464 -text $fontattr($font,family) -justify left
9465 grid x $top.${font}but $top.$font -sticky w
9468 proc choosefont {font which} {
9469 global fontparam fontlist fonttop fontattr
9471 set fontparam(which) $which
9472 set fontparam(font) $font
9473 set fontparam(family) [font actual $font -family]
9474 set fontparam(size) $fontattr($font,size)
9475 set fontparam(weight) $fontattr($font,weight)
9476 set fontparam(slant) $fontattr($font,slant)
9479 if {![winfo exists $top]} {
9481 eval font config sample [font actual $font]
9483 wm title $top [mc "Gitk font chooser"]
9484 label $top.l -textvariable fontparam(which)
9485 pack $top.l -side top
9486 set fontlist [lsort [font families]]
9488 listbox $top.f.fam -listvariable fontlist \
9489 -yscrollcommand [list $top.f.sb set]
9490 bind $top.f.fam <<ListboxSelect>> selfontfam
9491 scrollbar $top.f.sb -command [list $top.f.fam yview]
9492 pack $top.f.sb -side right -fill y
9493 pack $top.f.fam -side left -fill both -expand 1
9494 pack $top.f -side top -fill both -expand 1
9496 spinbox $top.g.size -from 4 -to 40 -width 4 \
9497 -textvariable fontparam(size) \
9498 -validatecommand {string is integer -strict %s}
9499 checkbutton $top.g.bold -padx 5 \
9500 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
9501 -variable fontparam(weight) -onvalue bold -offvalue normal
9502 checkbutton $top.g.ital -padx 5 \
9503 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
9504 -variable fontparam(slant) -onvalue italic -offvalue roman
9505 pack $top.g.size $top.g.bold $top.g.ital -side left
9506 pack $top.g -side top
9507 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
9509 $top.c create text 100 25 -anchor center -text $which -font sample \
9510 -fill black -tags text
9511 bind $top.c <Configure> [list centertext $top.c]
9512 pack $top.c -side top -fill x
9514 button $top.buts.ok -text [mc "OK"] -command fontok -default active
9515 button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
9516 grid $top.buts.ok $top.buts.can
9517 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9518 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9519 pack $top.buts -side bottom -fill x
9520 trace add variable fontparam write chg_fontparam
9523 $top.c itemconf text -text $which
9525 set i [lsearch -exact $fontlist $fontparam(family)]
9527 $top.f.fam selection set $i
9532 proc centertext {w} {
9533 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
9537 global fontparam fontpref prefstop
9539 set f $fontparam(font)
9540 set fontpref($f) [list $fontparam(family) $fontparam(size)]
9541 if {$fontparam(weight) eq "bold"} {
9542 lappend fontpref($f) "bold"
9544 if {$fontparam(slant) eq "italic"} {
9545 lappend fontpref($f) "italic"
9548 $w conf -text $fontparam(family) -font $fontpref($f)
9554 global fonttop fontparam
9556 if {[info exists fonttop]} {
9557 catch {destroy $fonttop}
9558 catch {font delete sample}
9564 proc selfontfam {} {
9565 global fonttop fontparam
9567 set i [$fonttop.f.fam curselection]
9569 set fontparam(family) [$fonttop.f.fam get $i]
9573 proc chg_fontparam {v sub op} {
9576 font config sample -$sub $fontparam($sub)
9580 global maxwidth maxgraphpct
9581 global oldprefs prefstop showneartags showlocalchanges
9582 global bgcolor fgcolor ctext diffcolors selectbgcolor
9583 global tabstop limitdiffs autoselect extdifftool perfile_attrs
9587 if {[winfo exists $top]} {
9591 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
9592 limitdiffs tabstop perfile_attrs} {
9593 set oldprefs($v) [set $v]
9596 wm title $top [mc "Gitk preferences"]
9597 label $top.ldisp -text [mc "Commit list display options"]
9598 grid $top.ldisp - -sticky w -pady 10
9599 label $top.spacer -text " "
9600 label $top.maxwidthl -text [mc "Maximum graph width (lines)"] \
9602 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
9603 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
9604 label $top.maxpctl -text [mc "Maximum graph width (% of pane)"] \
9606 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
9607 grid x $top.maxpctl $top.maxpct -sticky w
9608 frame $top.showlocal
9609 label $top.showlocal.l -text [mc "Show local changes"] -font optionfont
9610 checkbutton $top.showlocal.b -variable showlocalchanges
9611 pack $top.showlocal.b $top.showlocal.l -side left
9612 grid x $top.showlocal -sticky w
9613 frame $top.autoselect
9614 label $top.autoselect.l -text [mc "Auto-select SHA1"] -font optionfont
9615 checkbutton $top.autoselect.b -variable autoselect
9616 pack $top.autoselect.b $top.autoselect.l -side left
9617 grid x $top.autoselect -sticky w
9619 label $top.ddisp -text [mc "Diff display options"]
9620 grid $top.ddisp - -sticky w -pady 10
9621 label $top.tabstopl -text [mc "Tab spacing"] -font optionfont
9622 spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
9623 grid x $top.tabstopl $top.tabstop -sticky w
9625 label $top.ntag.l -text [mc "Display nearby tags"] -font optionfont
9626 checkbutton $top.ntag.b -variable showneartags
9627 pack $top.ntag.b $top.ntag.l -side left
9628 grid x $top.ntag -sticky w
9630 label $top.ldiff.l -text [mc "Limit diffs to listed paths"] -font optionfont
9631 checkbutton $top.ldiff.b -variable limitdiffs
9632 pack $top.ldiff.b $top.ldiff.l -side left
9633 grid x $top.ldiff -sticky w
9635 label $top.lattr.l -text [mc "Support per-file encodings"] -font optionfont
9636 checkbutton $top.lattr.b -variable perfile_attrs
9637 pack $top.lattr.b $top.lattr.l -side left
9638 grid x $top.lattr -sticky w
9640 entry $top.extdifft -textvariable extdifftool
9642 label $top.extdifff.l -text [mc "External diff tool" ] -font optionfont \
9644 button $top.extdifff.b -text [mc "Choose..."] -font optionfont \
9645 -command choose_extdiff
9646 pack $top.extdifff.l $top.extdifff.b -side left
9647 grid x $top.extdifff $top.extdifft -sticky w
9649 label $top.cdisp -text [mc "Colors: press to choose"]
9650 grid $top.cdisp - -sticky w -pady 10
9651 label $top.bg -padx 40 -relief sunk -background $bgcolor
9652 button $top.bgbut -text [mc "Background"] -font optionfont \
9653 -command [list choosecolor bgcolor {} $top.bg background setbg]
9654 grid x $top.bgbut $top.bg -sticky w
9655 label $top.fg -padx 40 -relief sunk -background $fgcolor
9656 button $top.fgbut -text [mc "Foreground"] -font optionfont \
9657 -command [list choosecolor fgcolor {} $top.fg foreground setfg]
9658 grid x $top.fgbut $top.fg -sticky w
9659 label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
9660 button $top.diffoldbut -text [mc "Diff: old lines"] -font optionfont \
9661 -command [list choosecolor diffcolors 0 $top.diffold "diff old lines" \
9662 [list $ctext tag conf d0 -foreground]]
9663 grid x $top.diffoldbut $top.diffold -sticky w
9664 label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
9665 button $top.diffnewbut -text [mc "Diff: new lines"] -font optionfont \
9666 -command [list choosecolor diffcolors 1 $top.diffnew "diff new lines" \
9667 [list $ctext tag conf d1 -foreground]]
9668 grid x $top.diffnewbut $top.diffnew -sticky w
9669 label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
9670 button $top.hunksepbut -text [mc "Diff: hunk header"] -font optionfont \
9671 -command [list choosecolor diffcolors 2 $top.hunksep \
9672 "diff hunk header" \
9673 [list $ctext tag conf hunksep -foreground]]
9674 grid x $top.hunksepbut $top.hunksep -sticky w
9675 label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor
9676 button $top.selbgbut -text [mc "Select bg"] -font optionfont \
9677 -command [list choosecolor selectbgcolor {} $top.selbgsep background setselbg]
9678 grid x $top.selbgbut $top.selbgsep -sticky w
9680 label $top.cfont -text [mc "Fonts: press to choose"]
9681 grid $top.cfont - -sticky w -pady 10
9682 mkfontdisp mainfont $top [mc "Main font"]
9683 mkfontdisp textfont $top [mc "Diff display font"]
9684 mkfontdisp uifont $top [mc "User interface font"]
9687 button $top.buts.ok -text [mc "OK"] -command prefsok -default active
9688 button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
9689 grid $top.buts.ok $top.buts.can
9690 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9691 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9692 grid $top.buts - - -pady 10 -sticky ew
9693 bind $top <Visibility> "focus $top.buts.ok"
9696 proc choose_extdiff {} {
9699 set prog [tk_getOpenFile -title "External diff tool" -multiple false]
9701 set extdifftool $prog
9705 proc choosecolor {v vi w x cmd} {
9708 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
9709 -title [mc "Gitk: choose color for %s" $x]]
9710 if {$c eq {}} return
9711 $w conf -background $c
9717 global bglist cflist
9719 $w configure -selectbackground $c
9721 $cflist tag configure highlight \
9722 -background [$cflist cget -selectbackground]
9723 allcanvs itemconf secsel -fill $c
9730 $w conf -background $c
9738 $w conf -foreground $c
9740 allcanvs itemconf text -fill $c
9741 $canv itemconf circle -outline $c
9745 global oldprefs prefstop
9747 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
9748 limitdiffs tabstop perfile_attrs} {
9750 set $v $oldprefs($v)
9752 catch {destroy $prefstop}
9758 global maxwidth maxgraphpct
9759 global oldprefs prefstop showneartags showlocalchanges
9760 global fontpref mainfont textfont uifont
9761 global limitdiffs treediffs perfile_attrs
9763 catch {destroy $prefstop}
9767 if {$mainfont ne $fontpref(mainfont)} {
9768 set mainfont $fontpref(mainfont)
9769 parsefont mainfont $mainfont
9770 eval font configure mainfont [fontflags mainfont]
9771 eval font configure mainfontbold [fontflags mainfont 1]
9775 if {$textfont ne $fontpref(textfont)} {
9776 set textfont $fontpref(textfont)
9777 parsefont textfont $textfont
9778 eval font configure textfont [fontflags textfont]
9779 eval font configure textfontbold [fontflags textfont 1]
9781 if {$uifont ne $fontpref(uifont)} {
9782 set uifont $fontpref(uifont)
9783 parsefont uifont $uifont
9784 eval font configure uifont [fontflags uifont]
9787 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
9788 if {$showlocalchanges} {
9794 if {$limitdiffs != $oldprefs(limitdiffs) ||
9795 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
9796 # treediffs elements are limited by path;
9797 # won't have encodings cached if perfile_attrs was just turned on
9798 catch {unset treediffs}
9800 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
9801 || $maxgraphpct != $oldprefs(maxgraphpct)} {
9803 } elseif {$showneartags != $oldprefs(showneartags) ||
9804 $limitdiffs != $oldprefs(limitdiffs)} {
9809 proc formatdate {d} {
9810 global datetimeformat
9812 set d [clock format $d -format $datetimeformat]
9817 # This list of encoding names and aliases is distilled from
9818 # http://www.iana.org/assignments/character-sets.
9819 # Not all of them are supported by Tcl.
9820 set encoding_aliases {
9821 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
9822 ISO646-US US-ASCII us IBM367 cp367 csASCII }
9823 { ISO-10646-UTF-1 csISO10646UTF1 }
9824 { ISO_646.basic:1983 ref csISO646basic1983 }
9825 { INVARIANT csINVARIANT }
9826 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
9827 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
9828 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
9829 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
9830 { NATS-DANO iso-ir-9-1 csNATSDANO }
9831 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
9832 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
9833 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
9834 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
9835 { ISO-2022-KR csISO2022KR }
9837 { ISO-2022-JP csISO2022JP }
9838 { ISO-2022-JP-2 csISO2022JP2 }
9839 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
9841 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
9842 { IT iso-ir-15 ISO646-IT csISO15Italian }
9843 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
9844 { ES iso-ir-17 ISO646-ES csISO17Spanish }
9845 { greek7-old iso-ir-18 csISO18Greek7Old }
9846 { latin-greek iso-ir-19 csISO19LatinGreek }
9847 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
9848 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
9849 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
9850 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
9851 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
9852 { BS_viewdata iso-ir-47 csISO47BSViewdata }
9853 { INIS iso-ir-49 csISO49INIS }
9854 { INIS-8 iso-ir-50 csISO50INIS8 }
9855 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
9856 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
9857 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
9858 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
9859 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
9860 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
9862 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
9863 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
9864 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
9865 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
9866 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
9867 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
9868 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
9869 { greek7 iso-ir-88 csISO88Greek7 }
9870 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
9871 { iso-ir-90 csISO90 }
9872 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
9873 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
9874 csISO92JISC62991984b }
9875 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
9876 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
9877 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
9878 csISO95JIS62291984handadd }
9879 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
9880 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
9881 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
9882 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
9884 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
9885 { T.61-7bit iso-ir-102 csISO102T617bit }
9886 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
9887 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
9888 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
9889 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
9890 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
9891 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
9892 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
9893 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
9894 arabic csISOLatinArabic }
9895 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
9896 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
9897 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
9898 greek greek8 csISOLatinGreek }
9899 { T.101-G2 iso-ir-128 csISO128T101G2 }
9900 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
9902 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
9903 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
9904 { CSN_369103 iso-ir-139 csISO139CSN369103 }
9905 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
9906 { ISO_6937-2-add iso-ir-142 csISOTextComm }
9907 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
9908 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
9909 csISOLatinCyrillic }
9910 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
9911 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
9912 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
9913 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
9914 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
9915 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
9916 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
9917 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
9918 { ISO_10367-box iso-ir-155 csISO10367Box }
9919 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
9920 { latin-lap lap iso-ir-158 csISO158Lap }
9921 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
9922 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
9925 { JIS_X0201 X0201 csHalfWidthKatakana }
9926 { KSC5636 ISO646-KR csKSC5636 }
9927 { ISO-10646-UCS-2 csUnicode }
9928 { ISO-10646-UCS-4 csUCS4 }
9929 { DEC-MCS dec csDECMCS }
9930 { hp-roman8 roman8 r8 csHPRoman8 }
9931 { macintosh mac csMacintosh }
9932 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
9934 { IBM038 EBCDIC-INT cp038 csIBM038 }
9935 { IBM273 CP273 csIBM273 }
9936 { IBM274 EBCDIC-BE CP274 csIBM274 }
9937 { IBM275 EBCDIC-BR cp275 csIBM275 }
9938 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
9939 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
9940 { IBM280 CP280 ebcdic-cp-it csIBM280 }
9941 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
9942 { IBM284 CP284 ebcdic-cp-es csIBM284 }
9943 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
9944 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
9945 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
9946 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
9947 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
9948 { IBM424 cp424 ebcdic-cp-he csIBM424 }
9949 { IBM437 cp437 437 csPC8CodePage437 }
9950 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
9951 { IBM775 cp775 csPC775Baltic }
9952 { IBM850 cp850 850 csPC850Multilingual }
9953 { IBM851 cp851 851 csIBM851 }
9954 { IBM852 cp852 852 csPCp852 }
9955 { IBM855 cp855 855 csIBM855 }
9956 { IBM857 cp857 857 csIBM857 }
9957 { IBM860 cp860 860 csIBM860 }
9958 { IBM861 cp861 861 cp-is csIBM861 }
9959 { IBM862 cp862 862 csPC862LatinHebrew }
9960 { IBM863 cp863 863 csIBM863 }
9961 { IBM864 cp864 csIBM864 }
9962 { IBM865 cp865 865 csIBM865 }
9963 { IBM866 cp866 866 csIBM866 }
9964 { IBM868 CP868 cp-ar csIBM868 }
9965 { IBM869 cp869 869 cp-gr csIBM869 }
9966 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
9967 { IBM871 CP871 ebcdic-cp-is csIBM871 }
9968 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
9969 { IBM891 cp891 csIBM891 }
9970 { IBM903 cp903 csIBM903 }
9971 { IBM904 cp904 904 csIBBM904 }
9972 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
9973 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
9974 { IBM1026 CP1026 csIBM1026 }
9975 { EBCDIC-AT-DE csIBMEBCDICATDE }
9976 { EBCDIC-AT-DE-A csEBCDICATDEA }
9977 { EBCDIC-CA-FR csEBCDICCAFR }
9978 { EBCDIC-DK-NO csEBCDICDKNO }
9979 { EBCDIC-DK-NO-A csEBCDICDKNOA }
9980 { EBCDIC-FI-SE csEBCDICFISE }
9981 { EBCDIC-FI-SE-A csEBCDICFISEA }
9982 { EBCDIC-FR csEBCDICFR }
9983 { EBCDIC-IT csEBCDICIT }
9984 { EBCDIC-PT csEBCDICPT }
9985 { EBCDIC-ES csEBCDICES }
9986 { EBCDIC-ES-A csEBCDICESA }
9987 { EBCDIC-ES-S csEBCDICESS }
9988 { EBCDIC-UK csEBCDICUK }
9989 { EBCDIC-US csEBCDICUS }
9990 { UNKNOWN-8BIT csUnknown8BiT }
9991 { MNEMONIC csMnemonic }
9996 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
9997 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
9998 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
9999 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
10000 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
10001 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
10002 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
10003 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
10004 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
10005 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
10006 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
10007 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
10008 { IBM1047 IBM-1047 }
10009 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
10010 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
10011 { UNICODE-1-1 csUnicode11 }
10012 { CESU-8 csCESU-8 }
10013 { BOCU-1 csBOCU-1 }
10014 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
10015 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
10017 { ISO-8859-15 ISO_8859-15 Latin-9 }
10018 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
10019 { GBK CP936 MS936 windows-936 }
10020 { JIS_Encoding csJISEncoding }
10021 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
10022 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
10024 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
10025 { ISO-10646-UCS-Basic csUnicodeASCII }
10026 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
10027 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
10028 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
10029 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
10030 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
10031 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
10032 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
10033 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
10034 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
10035 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
10036 { Adobe-Standard-Encoding csAdobeStandardEncoding }
10037 { Ventura-US csVenturaUS }
10038 { Ventura-International csVenturaInternational }
10039 { PC8-Danish-Norwegian csPC8DanishNorwegian }
10040 { PC8-Turkish csPC8Turkish }
10041 { IBM-Symbols csIBMSymbols }
10042 { IBM-Thai csIBMThai }
10043 { HP-Legal csHPLegal }
10044 { HP-Pi-font csHPPiFont }
10045 { HP-Math8 csHPMath8 }
10046 { Adobe-Symbol-Encoding csHPPSMath }
10047 { HP-DeskTop csHPDesktop }
10048 { Ventura-Math csVenturaMath }
10049 { Microsoft-Publishing csMicrosoftPublishing }
10050 { Windows-31J csWindows31J }
10051 { GB2312 csGB2312 }
10055 proc tcl_encoding {enc} {
10056 global encoding_aliases tcl_encoding_cache
10057 if {[info exists tcl_encoding_cache($enc)]} {
10058 return $tcl_encoding_cache($enc)
10060 set names [encoding names]
10061 set lcnames [string tolower $names]
10062 set enc [string tolower $enc]
10063 set i [lsearch -exact $lcnames $enc]
10065 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
10066 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
10067 set i [lsearch -exact $lcnames $encx]
10071 foreach l $encoding_aliases {
10072 set ll [string tolower $l]
10073 if {[lsearch -exact $ll $enc] < 0} continue
10074 # look through the aliases for one that tcl knows about
10076 set i [lsearch -exact $lcnames $e]
10078 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
10079 set i [lsearch -exact $lcnames $ex]
10089 set tclenc [lindex $names $i]
10091 set tcl_encoding_cache($enc) $tclenc
10095 proc gitattr {path attr default} {
10096 global path_attr_cache
10097 if {[info exists path_attr_cache($attr,$path)]} {
10098 set r $path_attr_cache($attr,$path)
10100 set r "unspecified"
10101 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
10102 regexp "(.*): encoding: (.*)" $line m f r
10104 set path_attr_cache($attr,$path) $r
10106 if {$r eq "unspecified"} {
10112 proc cache_gitattr {attr pathlist} {
10113 global path_attr_cache
10115 foreach path $pathlist {
10116 if {![info exists path_attr_cache($attr,$path)]} {
10117 lappend newlist $path
10121 if {[tk windowingsystem] == "win32"} {
10122 # windows has a 32k limit on the arguments to a command...
10125 while {$newlist ne {}} {
10126 set head [lrange $newlist 0 [expr {$lim - 1}]]
10127 set newlist [lrange $newlist $lim end]
10128 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
10129 foreach row [split $rlist "\n"] {
10130 if {[regexp "(.*): encoding: (.*)" $row m path value]} {
10131 if {[string index $path 0] eq "\""} {
10132 set path [encoding convertfrom [lindex $path 0]]
10134 set path_attr_cache($attr,$path) $value
10141 proc get_path_encoding {path} {
10142 global gui_encoding perfile_attrs
10143 set tcl_enc $gui_encoding
10144 if {$path ne {} && $perfile_attrs} {
10145 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
10153 # First check that Tcl/Tk is recent enough
10154 if {[catch {package require Tk 8.4} err]} {
10155 show_error {} . [mc "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
10156 Gitk requires at least Tcl/Tk 8.4."]
10161 set wrcomcmd "git diff-tree --stdin -p --pretty"
10165 set gitencoding [exec git config --get i18n.commitencoding]
10167 if {$gitencoding == ""} {
10168 set gitencoding "utf-8"
10170 set tclencoding [tcl_encoding $gitencoding]
10171 if {$tclencoding == {}} {
10172 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
10175 set gui_encoding [encoding system]
10177 set enc [exec git config --get gui.encoding]
10179 set tclenc [tcl_encoding $enc]
10180 if {$tclenc ne {}} {
10181 set gui_encoding $tclenc
10183 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
10188 set mainfont {Helvetica 9}
10189 set textfont {Courier 9}
10190 set uifont {Helvetica 9 bold}
10192 set findmergefiles 0
10200 set cmitmode "patch"
10201 set wrapcomment "none"
10205 set showlocalchanges 1
10207 set datetimeformat "%Y-%m-%d %H:%M:%S"
10209 set perfile_attrs 0
10211 set extdifftool "meld"
10213 set colors {green red blue magenta darkgrey brown orange}
10216 set diffcolors {red "#00a000" blue}
10219 set selectbgcolor gray85
10221 set circlecolors {white blue gray blue blue}
10223 # button for popping up context menus
10224 if {[tk windowingsystem] eq "aqua"} {
10225 set ctxbut <Button-2>
10227 set ctxbut <Button-3>
10230 ## For msgcat loading, first locate the installation location.
10231 if { [info exists ::env(GITK_MSGSDIR)] } {
10232 ## Msgsdir was manually set in the environment.
10233 set gitk_msgsdir $::env(GITK_MSGSDIR)
10235 ## Let's guess the prefix from argv0.
10236 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
10237 set gitk_libdir [file join $gitk_prefix share gitk lib]
10238 set gitk_msgsdir [file join $gitk_libdir msgs]
10242 ## Internationalization (i18n) through msgcat and gettext. See
10243 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
10244 package require msgcat
10245 namespace import ::msgcat::mc
10246 ## And eventually load the actual message catalog
10247 ::msgcat::mcload $gitk_msgsdir
10249 catch {source ~/.gitk}
10251 font create optionfont -family sans-serif -size -12
10253 parsefont mainfont $mainfont
10254 eval font create mainfont [fontflags mainfont]
10255 eval font create mainfontbold [fontflags mainfont 1]
10257 parsefont textfont $textfont
10258 eval font create textfont [fontflags textfont]
10259 eval font create textfontbold [fontflags textfont 1]
10261 parsefont uifont $uifont
10262 eval font create uifont [fontflags uifont]
10266 # check that we can find a .git directory somewhere...
10267 if {[catch {set gitdir [gitdir]}]} {
10268 show_error {} . [mc "Cannot find a git repository here."]
10271 if {![file isdirectory $gitdir]} {
10272 show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir]
10277 set selectheadid {}
10280 set cmdline_files {}
10282 set revtreeargscmd {}
10283 foreach arg $argv {
10284 switch -glob -- $arg {
10287 set cmdline_files [lrange $argv [expr {$i + 1}] end]
10290 "--select-commit=*" {
10291 set selecthead [string range $arg 16 end]
10294 set revtreeargscmd [string range $arg 10 end]
10297 lappend revtreeargs $arg
10303 if {$selecthead eq "HEAD"} {
10307 if {$i >= [llength $argv] && $revtreeargs ne {}} {
10308 # no -- on command line, but some arguments (other than --argscmd)
10310 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
10311 set cmdline_files [split $f "\n"]
10312 set n [llength $cmdline_files]
10313 set revtreeargs [lrange $revtreeargs 0 end-$n]
10314 # Unfortunately git rev-parse doesn't produce an error when
10315 # something is both a revision and a filename. To be consistent
10316 # with git log and git rev-list, check revtreeargs for filenames.
10317 foreach arg $revtreeargs {
10318 if {[file exists $arg]} {
10319 show_error {} . [mc "Ambiguous argument '%s': both revision\
10320 and filename" $arg]
10325 # unfortunately we get both stdout and stderr in $err,
10326 # so look for "fatal:".
10327 set i [string first "fatal:" $err]
10329 set err [string range $err [expr {$i + 6}] end]
10331 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
10336 set nullid "0000000000000000000000000000000000000000"
10337 set nullid2 "0000000000000000000000000000000000000001"
10338 set nullfile "/dev/null"
10340 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
10347 set highlight_paths {}
10349 set searchdirn -forwards
10351 set boldnamerows {}
10352 set diffelide {0 0}
10353 set markingmatches 0
10354 set linkentercount 0
10355 set need_redisplay 0
10362 set selectedhlview [mc "None"]
10363 set highlight_related [mc "None"]
10364 set highlight_files {}
10365 set viewfiles(0) {}
10368 set viewargscmd(0) {}
10370 set selectedline {}
10378 set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
10381 # wait for the window to become visible
10382 tkwait visibility .
10383 wm title . "[file tail $argv0]: [file tail [pwd]]"
10386 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
10387 # create a view for the files/dirs specified on the command line
10391 set viewname(1) [mc "Command line"]
10392 set viewfiles(1) $cmdline_files
10393 set viewargs(1) $revtreeargs
10394 set viewargscmd(1) $revtreeargscmd
10398 .bar.view entryconf [mca "Edit view..."] -state normal
10399 .bar.view entryconf [mca "Delete view"] -state normal
10402 if {[info exists permviews]} {
10403 foreach v $permviews {
10406 set viewname($n) [lindex $v 0]
10407 set viewfiles($n) [lindex $v 1]
10408 set viewargs($n) [lindex $v 2]
10409 set viewargscmd($n) [lindex $v 3]